Files
prep-source-repos/bin/prep_source_repos
Adam Gandelman 885d3caba5 INIT
2014-05-28 16:46:22 -07:00

52 lines
1.6 KiB
Python
Executable File

#!/usr/bin/python
import yaml
from subprocess import check_call, check_output
import os
SRC_ROOT = os.getenv('TRIPLEO_ROOT', 'tripleo')
CONF = 'repo_refs.yaml'
CONF = yaml.load(open(CONF).read())
GIT_SERVER = 'http://review.openstack.org'
if not os.path.isdir(SRC_ROOT):
os.mkdir(SRC_ROOT)
for repo in CONF['repos']:
rd = os.path.join(SRC_ROOT, repo)
if repo in ['tripleo-ci']:
org = 'openstack-infra'
else:
org = 'openstack'
remote = GIT_SERVER + '/%s/%s' % (org, repo)
if os.path.isdir(os.path.join(rd)):
check_call(['git', 'checkout', 'master'], cwd=rd)
check_call(['git', 'pull'], cwd=rd)
else:
check_call(['git', 'clone', remote, rd])
if repo not in CONF['gerrit_refs']:
print 'no refs for %s' % repo
continue
refs = CONF['gerrit_refs'][repo]
branch_name = 'rollup_' + \
'_'.join([r[1] for r in [ref.split('/') for ref in refs]])
branches = check_output(['git', 'branch', '-a'], cwd=rd)
if branch_name in branches:
print 'Deleting existing branch %s...' % branch_name
check_call(['git', 'branch', '-D', branch_name], cwd=rd)
check_call(['git', 'checkout', '-b', branch_name], cwd=rd)
check_call(['git', 'branch', '--set-upstream-to=origin/master'], cwd=rd)
for ref in CONF['gerrit_refs'][repo]:
_, rev, p = ref.split('/')
print 'pulling %s' % (GIT_SERVER + '/#/c/' + rev)
print ' '.join(['git', 'pull', remote, ref])
check_call(['git', 'pull', '--no-edit', remote, 'refs/changes/' + ref],
cwd=rd)