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)
表示成功