zoukankan      html  css  js  c++  java
  • GitLab 导出项目

    # 在Python3.0测试通过
    # 需要在gitlab里面新建一个AccessToken
    # 需要在本地机器设置一个环境变量,保证git clone 可以执行
     
    from urllib.request import urlopen
    import json
    import subprocess, shlex
    import time
    import os
     
    gitlabAddr  = '{0}'
    gitlabToken = '{0}'
     
    for index in range(10):
        url     = "http://%s/api/v4/projects?private_token=%s&per_page=100&page=%d&order_by=name" % (gitlabAddr, gitlabToken, index)
        print(url)
        allProjects     = urlopen(url)
        allProjectsDict = json.loads(allProjects.read().decode())
        if len(allProjectsDict) == 0:
            breaka
        for thisProject in allProjectsDict: 
            try:
                thisProjectURL  = thisProject['ssh_url_to_repo']
                thisProjectPath = thisProject['path_with_namespace']
                print(thisProjectURL + ' ' + thisProjectPath)
                
                if os.path.exists(thisProjectPath):
                    command     = shlex.split('git -C "%s" pull' % (thisProjectPath))
                else:
                    command     = shlex.split('git clone %s %s' % (thisProjectURL, thisProjectPath))
                
                resultCode  = subprocess.Popen(command)
                time.sleep(1)
            except Exception as e:
                print("Error on %s: %s" % (thisProjectURL, e.strerror))
    

      

  • 相关阅读:
    AtCoder Regular Contest 093
    AtCoder Regular Contest 094
    G. Gangsters in Central City
    HGOI 20190711 题解
    HGOI20190710 题解
    HGOI 20190709 题解
    HGOI 20190708 题解
    HGOI20190707 题解
    HGOI20190706 题解
    HGOI 20190705 题解
  • 原文地址:https://www.cnblogs.com/yako/p/13897480.html
Copyright © 2011-2022 走看看