git程式碼遷移到新的gitlab伺服器
阿新 • • 發佈:2019-01-04
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()