推送新项目到gerrit

最好在linux环境下
python push_new_project.py $projext_hone $preproject

projext_hone为项目根目录
preproject是创建gerrit项目时为所有项目添加的前缀

然后手动创建manifest.xml文件

创建manifest项目
ssh -p 29418 [email protected] gerrit create-project xxx-manifest
git init
git add .
git commit -m "first commit"

git push ssh://[email protected]:29418/xxx-manifest *:*


push_new_project.py:

#导入新项目(非git项目)到gerrit,不包含manifest(default.xml)
#各子目录另成一个项目
#!/usr/bin/python
# -*- coding:utf-8 -*-

import os
import time

def run_shell(cmd):
    os.system('echo "++++---- {0}"'.format(cmd))
    r = os.system(cmd)
    if r != 0:
        exit(1)
        
try:
    rootdir = sys.argv[1]
except:
    print 'sys.argv[1] must set project dir'
    exit(1)
try:
    project = sys.argv[2]
except:
    print 'sys.argv[2] must set the projectpre'
    exit(1)


for filename in os.listdir(rootdir):
    pathname = os.path.join(rootdir, filename)
    if (os.path.isdir(pathname)):
        os.chdir(pathname)
        time.sleep(2)
        run_shell("ssh -p 29418 [email protected] gerrit create-project {0}-{1}".format(project,filename))
        run_shell("git init")
        run_shell("git add .")
        run_shell('git commit -m "first commit"')
        run_shell("git push ssh://[email protected]:29418/{0}-{1} *:*".format(project,filename))
        os.chdir(rootdir)
        time.sleep(2)

os.chdir(rootdir)
run_shell("ssh -p 29418 [email protected] gerrit create-project {0}-build-makefile".format(project))
run_shell("git init")
for filename in os.listdir(rootdir):
    if (os.path.isfile(filename)):
        run_shell("git add {0}".format(filename))
run_shell("git commit -m 'first commit'")
run_shell("git push ssh://[email protected]:29418/{0}-build-makefile *:*".format(project))

猜你喜欢

转载自blog.csdn.net/appke846/article/details/79426077
今日推荐