0

I have a list of repositories (their URLs in String form) and I would like to clone each of them to the folder. I would like to ZIP this folder with repositories afterwards too. Any suggestions please?

3 Answers3

1

Firstly you need to implement module named os to use your commands and then modul shutil responsible for ZIPing your file.

then you need to use specify folder path where you want to clone repositories. After that you have to use command git clone and clone that repository there. Eventually you need to use modul shutil to make a ZIP archive and specify a path where this archive should appear.

here is the code:

import os, shutil

def main():
    listOfUrls = ["https://github.com/UserName/RepositoryName", "https://github.com/UserName/RepositoryName"] 

for singleRepositoryUrl in listOfUrls:
    path  = "specify your full path to the folder here (in String form)"
    clone = "git clone " + singleRepositoryUrl
    os.chdir(path) # changes the current working directory to the given path
    os.system(clone) # actual cloning
    shutil.make_archive(path, "zip", path) # zipping the file

if __name__ == '__main__':
  main()
Michal Moravik
  • 1,213
  • 1
  • 12
  • 23
0

First of all clone all the repos in a directory like below:

import git
for url in urls:
    git.Git("your_directory").clone("git://gitorious.org/git-python/mainline.git")



Then zip your directory like so

import shutil
shutil.make_archive(output_filename, 'zip', dir_name_cloned)

Omar Faroque Anik
  • 2,531
  • 1
  • 29
  • 42
0

For the ZIPing via Python I don't know, but for the git part, this should do it.

import subprocess
import os

for singleCloneUrl in urlsList:
    os.chdir('your full path here') 
    subprocess.run(['git', 'clone', singleCloneUrl], shell=True)
Highyard
  • 1
  • 1