Python 将git存储库从列表克隆到文件夹
我有一个存储库列表(它们的URL是字符串形式的),我想将它们克隆到文件夹中。我想以后也用存储库压缩这个文件夹。有什么建议吗?首先,您需要实现名为os的模块来使用您的命令,然后由modul shutil负责对您的文件进行压缩 然后,您需要使用指定文件夹路径来克隆存储库。之后,您必须使用gitclone命令,并在那里克隆该存储库。最后,您需要使用modul shutil创建一个ZIP归档文件,并指定该归档文件应该出现的路径 代码如下:Python 将git存储库从列表克隆到文件夹,python,python-3.x,Python,Python 3.x,我有一个存储库列表(它们的URL是字符串形式的),我想将它们克隆到文件夹中。我想以后也用存储库压缩这个文件夹。有什么建议吗?首先,您需要实现名为os的模块来使用您的命令,然后由modul shutil负责对您的文件进行压缩 然后,您需要使用指定文件夹路径来克隆存储库。之后,您必须使用gitclone命令,并在那里克隆该存储库。最后,您需要使用modul shutil创建一个ZIP归档文件,并指定该归档文件应该出现的路径 代码如下: import os, shutil def main():
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()
首先,在如下目录中克隆所有repo:
import git
for url in urls:
git.Git("your_directory").clone("git://gitorious.org/git-python/mainline.git")
然后像这样压缩你的目录
import shutil
shutil.make_archive(output_filename, 'zip', dir_name_cloned)
对于通过Python实现的ZIPing,我不知道,但是对于git部分,这应该可以做到
import subprocess
import os
for singleCloneUrl in urlsList:
os.chdir('your full path here')
subprocess.run(['git', 'clone', singleCloneUrl], shell=True)
你需要python做什么?去普通的成批脚本可能重复的非常感谢。它工作得很好!