1、將.repo/manifests/default.xml文件拷貝到部署代碼時從ATC下載下來的代碼目錄中,如下
zhaojiawei@zjr-7040:~/ATC_AndoridOGO_8827L-to-flaydio$ cp .repo/manifests/default.xml
2、創建python腳本將當前的代碼的所有git子庫中的遠程如下設置
autochips ssh://[email protected]:29418/atc/android/o/$REPO_PROJECT
origin [email protected]:/home/git/atc/android/o/$REPO_PROJECT
如下:
zhaojiawei@zjr-7040:~/ATC_AndoridOGO_8827L-to-flaydio/art$ git remote -v
autochips ssh://[email protected]:29418/atc/android/o/platform/art (fetch)
autochips ssh://[email protected]:29418/atc/android/o/platform/art (push)
origin [email protected]:/home/git/atc/android/o/platform/art (fetch)
origin [email protected]:/home/git/atc/android/o/platform/art (push)
取名稱爲getnames_and_medfiy_remote.py ,腳本文件下載路徑:
https://download.csdn.net/download/jinron10/10698032
腳本代碼如下:
#!/usr/bin/python3
import os
import sys
######remote = '[email protected]:rk3229'
#####[email protected]/home/git/Project/8227L_project
#####remote = '[email protected]:atc/android/o'
######remote = 'ssh://[email protected]:29418'
flyaudio_remote = '[email protected]:/home/git'
atc_remote = 'ssh://[email protected]:29418'
if len(sys.argv) == 1:
print('錯誤!請傳入 xml 文件')
elif len(sys.argv) > 2:
print('錯誤!傳入參數太多')
else:
print('傳入的文件是 %s' % sys.argv[1])
with open(sys.argv[1], 'r') as fin:
while True:
linestr = fin.readline()
if linestr == '': #表示文件結束
break
#####for project-list.txt
#else:
#print(linestr)
#localpath = sys.path[0] + '/' + linestr # git工程的本地絕對路徑
#remotepath = remote + '/' + linestr # git工程遠程相對路徑
#cmd = 'cd %s && git remote set-url autochips %s &&git push -u autochips android-trunk-o1.ac8227L && cd %s' % (localpath, remotepath, sys.path[0])
#print(cmd)
#os.system(cmd)
#end for project-list.txt
print(linestr)
#下面開始對本行內容分析
if (('name=' in linestr) or ('name =' in linestr)) and (('project' in linestr) or ('path' in linestr)): #本行內容含有name信息
#print(linestr)
#先無條件提取name路徑
charistr1 = 'name="'
charistr2 = '"'
namestr = linestr[linestr.index(charistr1)+len(charistr1) : linestr.index(charistr1)+len(charistr1)+ linestr[linestr.index(charistr1)+len(charistr1):].index(charistr2)]
if 'path=' in linestr: #如果path存在則用path的路徑作爲本地路徑
charistr1 = 'path="'
charistr2 = '"'
pathstr = linestr[linestr.index(charistr1)+len(charistr1) : linestr.index(charistr1)+len(charistr1)+ linestr[linestr.index(charistr1)+len(charistr1):].index(charistr2)]
else: #如果path不存在,則認爲path路徑(本地路徑)就是name路徑
pathstr = namestr
print('name="%s", path="%s"' % (namestr, pathstr))
path_m = pathstr
if path_m == 'autochips': #路徑等於origin,那麼不創建
print(path_m)
else:
#下面開始初始化並提交git工程
localpath = sys.path[0] + '/' + pathstr # git工程的本地絕對路徑
atc_remotepath = atc_remote + '/' + namestr # ATC git工程遠程相對路徑
flyaudio_remotepath = flyaudio_remote + '/' + namestr # flyaduio_git工程遠程相對路徑
#判斷本地目錄是否爲空,爲空的話則新建一個文件,空目錄會導致git提交失敗
if os.path.exists(localpath): #目錄存在上傳文件
#print(localpath)
#if not os.listdir(localpath): # 本地目錄爲空
# cmd = 'touch %s/.gitignore' % (localpath)
# print(localpath)
# os.system(cmd)
###cmd = 'cd %s && git remote add set-url autochips %s && git add . && git commit -m "init base 8827L project" &&git push -u autochips android-trunk-o1.ac8227L && cd %s' % (localpath, remotepath, sys.path[0])
####cmd = 'cd %s && git remote set-url autochips %s &&git push -u autochips android-trunk-o1.ac8227L && cd %s' % (localpath, remotepath, sys.path[0])
#print(remotepath)
print('localpath="%s"' %localpath)
print('atc_remotepath="%s"' %atc_remotepath)
print('flyaudio_remotepath="%s"' %flyaudio_remotepath)
### 所有字庫將原來上傳代碼時修改成的flyaudio的地址修改還OEM廠家ATC的gerrite的服務器地址
cmd = 'cd %s && git remote set-url autochips %s && cd %s' % (localpath, atc_remotepath, sys.path[0])
print(cmd)
os.system(cmd)
### 所有字庫添加客戶端flyaudio的遠程服務器地址
cmd = 'cd %s && git remote add origin %s && cd %s' % (localpath, flyaudio_remotepath, sys.path[0])
print(cmd)
os.system(cmd)
##Upload each git sub library to the remote server.
#cmd = 'cd %s &&git push -u autochips android-trunk-o1.ac8227L && cd %s' % (localpath, sys.path[0])
#print(cmd)
#os.system(cmd)
else: #目錄不存在不上傳
print(localpath)
#cmd = 'cd %s && rm -rf .git && git init && git remote add origin %s && git add . -f && git commit -m "init " &&git push -u origin master && cd %s' % (localpath, remotepath, sys.path[0])
#print(cmd)
#os.system(cmd)
3、運行腳本,修改每次git子庫的remote地址,形成所有的單個git子庫同時指向兩個不同的遠程路徑,方便代碼鏡像同步使用。如下:
zhaojiawei@zjr-7040:~/ATC_AndoridOGO_8827L-to-flaydio$ ./getnames_and_medfiy_remote.py default.xml
運行完成後,進入~/ATC_AndoridOGO_8827L-to-flaydio/art目錄查看是否成本
zhaojiawei@zjr-7040:~/ATC_AndoridOGO_8827L-to-flaydio/art$ git remote -v
autochips ssh://[email protected]:29418/atc/android/o/platform/art (fetch)
autochips ssh://[email protected]:29418/atc/android/o/platform/art (push)
origin [email protected]:/home/git/atc/android/o/platform/art (fetch)
origin [email protected]:/home/git/atc/android/o/platform/art (push)
表示成功