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))
    

      

  • 相关阅读:
    Python学习4
    Python学习3
    Python学习2
    表空间
    sqlplus常用设置
    HashMap和LinkedHashMap
    堆栈源码
    观察者模式
    策略模式
    java线性表
  • 原文地址:https://www.cnblogs.com/yako/p/13897480.html
Copyright © 2011-2022 走看看