首页 > 编程语言 >python api gitlab迁移所有项目

python api gitlab迁移所有项目

时间:2022-09-26 10:47:43浏览次数:52  
标签:git python gitlab cd api thisProjectPath import com

1、 gitlab生成token (略)

帐号后台生成toekn

2、python拉取所有的gitlab项目

** 代码如下: vim get_git_all.py **

import os,sys
if sys.version_info < (3, 0):
    import urllib
else:
    from urllib.request import urlopen
 
import json
import subprocess, shlex
import time
import os
 
gitlabAddr  = 'gitlab.xxx.com'
gitlabToken = 'xxx'
 
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)
    
    if sys.version_info < (3, 0):
        allProjects     = urllib.urlopen(url)
    else:
        allProjects     = urlopen(url)
        
    allProjectsDict = json.loads(allProjects.read().decode(encoding='UTF-8'))
    if len(allProjectsDict) == 0:
        break
    for thisProject in allProjectsDict: 
        try:
            thisProjectURL  = thisProject['http_url_to_repo']
            thisProjectPath = thisProject['path_with_namespace']
            print(thisProjectURL + ' ' + thisProjectPath)
            
            if os.path.exists(thisProjectPath):
#                command     = shlex.split('cd "%s" && git pull' % (thisProjectPath))
                os.system('cd %s && git pull' % thisProjectPath)

            else:
                command     = shlex.split('git clone --mirror  %s %s' % (thisProjectURL, thisProjectPath))
                resultCode  = subprocess.Popen(command)
            
            time.sleep(3)
        except Exception as e:
            print("Error on %s: %s" % (thisProjectURL, e.strerror))

3 、修改git地址脚本&&上传到新的gitlab (得保证目标仓库没有同路径的仓库)

for tmp in  `ls -r |sort  -n`;do


if [ -d $tmp ];then

cd $tmp

  for xx in `ls -r`;do

  if [ -d $xx ];then
    echo $tmp/$xx
    cd $xx
    sed -i 's#gitlab.xxx.com#gitlab.newxxx.com/lbx#g' config
    git push --mirror 

    cd ..
  fi

  done

cd ..
fi

done


提示: 运维git迁移命令:

git clone --mirror xxxxx.git

cd xxxxx

sed -i 's#gitlab.xxx.com#gitlab.xxxnew.com/lbx#g' config
 
git push --mirror


标签:git,python,gitlab,cd,api,thisProjectPath,import,com
From: https://www.cnblogs.com/Qing-840/p/16730042.html

相关文章

  • Centos7安装Python虚拟环境之virtualenv
    一、安装自己需要的python版本步骤略二、安装virtualenv模块并创建虚拟环境[root@localhost~]#/usr/local/python3.6.8/bin/pip3installvirtualenv[root@localh......
  • python的内置函数vars,locals
    vars包含参数时,用于返回实例化对象的内部属性值,(因此,其最常用于读取parse的参数数值,以便于写入文件中记录)用于非实例化对象时,可用于查看对象的方法名等作用。在没有参数......
  • 1688API接口,获取商品详情,按关键词搜索,拍立淘,商品评论商品类目,店铺接口等
    接口所示item_get获得1688商品详情item_search按关键字搜索商品item_search_img按图搜索1688商品(拍立淘)item_search_shop获得店铺的所有商品item_get_app获取1688app......
  • python中::-1代表什么?
    在Python中::-1表示将字符或数字倒序输出。举个栗子,当line="abcde"时,使用语句line[::-1],最后的运行结果为:'edcba'。下面请看详细解释。一、反转::-1涉及到将数字或字符倒......
  • 本地文件上传到OSS python版本
    #-*-coding:utf-8-*-importoss2importos#官方参考:https://help.aliyun.com/document_detail/88426.html#阿里云账号AccessKey拥有所有API的访问权限,风险很高。强......
  • 百度地图api
    今天需要在公司官网展示公司坐标,也学习一下百度地图的其他apiHTML<divid="mapContainer"style="height:500px"></div>jsconstmap=newBMapGL.Map("mapContain......
  • 进入python的世界_第一周总结
    一、认识了计算机的组成部分,核心硬件五大组成部分控制器、运算器、存储器、输入设备、输出设备三大核心硬件CPU、内存、硬盘(外存)CPU不直接与硬盘交互,内存是CPU与......
  • Python中class内置方法__init__与__new__作用与区别探究
    背景最近尝试了解Django中ORM实现的原理,发现其用到了metaclass(元类)这一技术,进一步又涉及到Pythonclass中有两个特殊内置方法__init__与__new__,决定先尝试探究一番两者......
  • python语法之注释
    引言注释的最大作用是提高程序的可读性,在开发过程中非常有必要加上注释。Python支持两种类型的注释,分别是单行注释和多行注释。1单行注释Python使用井号#作为单行注......
  • python GUI编程实例(executeMML_tools)
    #!/usr/bin#_*_coding:UTF-8_*_#Copyright(c)2022GengYaZhao.Allrightsreserved#@CreateByGengYaZhao#@Create_time:2022/9/25#@FileName:myGui#打包命......