zoukankan      html  css  js  c++  java
  • git代码迁移到新的gitlab服务器批量python脚本

    git代码迁移到新的gitlab服务器

    由于gitlab上的代码要迁移至北京gitlab服务器统一用组的方式管理,需要把旧的代码迁移至新的gitlab服务器

    文件内容:

     gitwa

    cephfs-http-service.git
    cloudadmin.git

    批量迁移脚本

    from subprocess import PIPE,Popen
    import os
    import sys
    OLD = "http://1.1.1.1/"
    NEW = "http://2.2.2.2/"
    GROUP = "cloudzone"
    addr = "/root/git"
    
    def clone():
        print("clone代码")
        with open('gitwa','r')as f:
            for line in f:
                proc = Popen('git clone {0}{1}/{2}'.format(OLD,GROUP,line),shell=True,stdout=PIPE,stdin=PIPE)
                txt = proc.stdout.read()
                res = proc.wait()
                print(txt,res)
    
    def modify():
        print("修改代码地址")
        with open('gitwa','r') as f:
            for line in f:
                strs = line.split('.')[0]
                print(strs)
                os.chdir("{0}/{1}".format(addr,strs))
                print(os.getcwd())
                proc = Popen('git remote set-url origin {0}{1}/{2}'.format(NEW,GROUP,line),shell=True,stdout=PIPE,stdin=PIPE)
                if proc.wait() == 0:
                    print(proc.stdout.read())
                else:
                    print("error")
                    sys.exit(1)
    
    def push():
        print("推送代码到远程仓库")
        with open('gitwa','r') as f:
            for line in f.readlines():
                strs = line.split('.')[0]
                os.chdir("{0}/{1}".format(addr,strs))
           os.system("git add *")
    os.system("git remote add origin {0}{1}/{2}".format(NEW,GROUP,strs)) os.system('git commit -m "Initial commit"') os.system('git push -u origin master') if __name__ == '__main__': clone() modify() push()
  • 相关阅读:
    阿里云esc 安装 mysql8.0
    阿里云esc 登录时的相关提示
    C# web项目 log4net 使用
    MVC 全局异常捕获
    datetimepicker 基础使用/select2 基础使用
    C# 从登陆开始 MVC4+BOOTSTRAP
    Android如何导入语言资源
    Android自带邮件含中文的附件用HTML打开乱码问题的解决
    android 解决输入法遮挡输入框的问题
    repo代码简单解读
  • 原文地址:https://www.cnblogs.com/zhangzihong/p/10221454.html
Copyright © 2011-2022 走看看