赞
踩
下载python
python官网下载
安装(记住保存位置,我是保存在【D:\software\python37】)
配置环境变量
from urllib.request import urlopen import json import shlex import subprocess import os import requests def getProjects(group_id=None,full_path=None): url = f"http://8.129.23.111:5720/api/v4/groups/{group_id}/projects?private_token=123456&per_page=100000" allProjectsDict = requests.get(url=url).json() for thisProject in allProjectsDict: try: thisProjectURL = thisProject['http_url_to_repo'] target_path = full_path + '//' + thisProject['path'] print(('git clone %s %s' % (thisProjectURL,target_path))) command = shlex.split('git clone %s %s' % (thisProjectURL,target_path)) resultCode = subprocess.Popen(command) resultCode.wait() # 等待子进程执行完毕 except Exception as e: print("Error on {}: {}".format(thisProjectURL, str(e))) def get_mark(group_dict=None): for i in group_dict: group_id = i['id'] full_path = i['full_path'] full_path = './' + full_path if not os.path.exists(full_path): os.makedirs(full_path) print("文件夹创建成功!") else: print("文件夹已存在!") getProjects(group_id=group_id,full_path=full_path) subgroup_url = f"http://8.129.23.111:5720/api/v4/groups/{group_id}/subgroups?private_token=123456&per_page=100000" subgroup_info = urlopen(subgroup_url) subgroups = json.loads(subgroup_info.read().decode()) if subgroups: get_mark(group_dict=subgroups) else: pass # 获取最外层分组的分组id url = "http://8.129.23.111:5720/api/v4/groups?private_token=123456&search=target-group" group_url = url group_info = urlopen(group_url) group_dict = json.loads(group_info.read().decode()) get_mark(group_dict=group_dict)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。