在一次行动中克隆来自Gitolite的回购

时间:2017-01-18 10:56:53

标签: python git ssh gitolite

这是我尝试简化准备工作环境的过程。假设您的团队有许多Gitolite托管存储库,您希望:

  • 获取完整的清单;
  • 将其中一些克隆得尽可能简单快捷。

此脚本允许它。所以,上述问题的答案是:

显示gitolite repos:

ssh git@server_ip

以下代码用于克隆:

#!/usr/bin/python

import subprocess
import sys
import os
import re

FILTER = None

# check shell arguments
if len(sys.argv) == 2:
    FILTER = sys.argv[1]

GIT_PATH = "git@server_ip"

# run system command and retrieve result
p = subprocess.Popen("ssh " + GIT_PATH, stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()

output = re.sub(r'^[\S\s]*?(?=web/)', '', output)
output = re.sub(r'R|W', '', output)

output = output.split()


# filter function
def f(line):
    if line.find(FILTER) != -1:
         return True

    return False


if FILTER:
    output = filter(f, output)

yes = 'yes'
no = 'no'

for line in output:
    print(line)
    choice = input("Do you want to clone this repo (yes/no): ")

    if choice == yes:
        os.system("git clone " + GIT_PATH + ':/' + line.strip())
        print('Done!')

print('All work is done! Congrats!')

语法: python clone.py [filter] 指定过滤器时,只允许获取包含过滤字符串作为子字符串的repos。

欢迎提出改进建议!感谢。

0 个答案:

没有答案