summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2017-05-12 12:37:33 -0400
committerFeng Pan <fpan@redhat.com>2017-05-30 16:36:11 -0400
commit8f2cffd3681baffd44ab6fb1e9d91d899053753b (patch)
tree03d9969f04a355af246fee6f1cca49d006859100 /lib
parenta622216b83fd46d3ad1fd763a367cc26323a8864 (diff)
Moving to forks on gerrit.opnfv.org
Migrating off of github onto opnfv.org to host our forked projects that are side loaded into our builds apex-tripleo-heat-templates: Ic65cfeee4a55e993629f831c8c9d9addf6f3dff4 apex-puppet-tripleo: If498c41d706c8f14a5b0bbee64cb4d26cd78c2d0 apex-os-net-config: I5281a57640f388e984b061702362f9c82d08da78 Change-Id: Ieb5cf293ad06d90fce7a9467e32ac0f2d8731a0a Signed-off-by: Dan Radez <dradez@redhat.com> Signed-off-by: Feng Pan <fpan@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/playbooks/build_dependencies.yml8
-rw-r--r--lib/python/build_utils.py108
2 files changed, 115 insertions, 1 deletions
diff --git a/lib/ansible/playbooks/build_dependencies.yml b/lib/ansible/playbooks/build_dependencies.yml
index dcf2ed94..620b1b3f 100644
--- a/lib/ansible/playbooks/build_dependencies.yml
+++ b/lib/ansible/playbooks/build_dependencies.yml
@@ -10,7 +10,7 @@
python34-markupsafe, python2-virtualbmc,
libguestfs-tools,bsdtar,libvirt,
python2-oslo-config,python2-debtcollector,
- make, python-pip, python-virtualenv
+ make, python-pip, python-virtualenv, python34-pip
- name: Install Virtualization group
yum:
name: "@Virtualization Host"
@@ -19,3 +19,9 @@
name: 'http://artifacts.opnfv.org/apex/dependencies/python3-ipmi-0.3.0-1.noarch.rpm'
- pip:
name: tox
+ - pip:
+ name: gitpython
+ executable: pip3.4
+ - pip:
+ name: pygerrit2
+ executable: pip3.4
diff --git a/lib/python/build_utils.py b/lib/python/build_utils.py
new file mode 100644
index 00000000..14327a90
--- /dev/null
+++ b/lib/python/build_utils.py
@@ -0,0 +1,108 @@
+##############################################################################
+# Copyright (c) 2017 Feng Pan (fpan@redhat.com) and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import argparse
+import git
+import logging
+import os
+from pygerrit2.rest import GerritRestAPI
+import re
+import shutil
+import sys
+
+
+def clone_fork(args):
+ ref = None
+ logging.info("Cloning {}".format(args.repo))
+
+ try:
+ cm = git.Repo(search_parent_directories=True).commit().message
+ except git.exc.InvalidGitRepositoryError:
+ logging.debug('Current Apex directory is not a git repo: {}'
+ .format(os.getcwd()))
+ cm = ''
+
+ logging.info("Current commit message: {}".format(cm))
+ m = re.search('{}:\s*(\S+)'.format(args.repo), cm)
+
+ if m:
+ change_id = m.group(1)
+ logging.info("Using change ID {} from {}".format(change_id, args.repo))
+ rest = GerritRestAPI(url=args.url)
+ change_str = "changes/{}?o=CURRENT_REVISION".format(change_id)
+ change = rest.get(change_str)
+ try:
+ assert change['status'] not in 'ABANDONED' 'CLOSED',\
+ 'Change {} is in {} state'.format(change_id, change['status'])
+ if change['status'] == 'MERGED':
+ logging.info('Change {} is merged, ignoring...'
+ .format(change_id))
+ else:
+ current_revision = change['current_revision']
+ ref = change['revisions'][current_revision]['ref']
+ logging.info('setting ref to {}'.format(ref))
+ except KeyError:
+ logging.error('Failed to get valid change data structure from url '
+ '{}/{}, data returned: \n{}'
+ .format(change_id, change_str, change))
+ raise
+
+ # remove existing file or directory named repo
+ if os.path.exists(args.repo):
+ if os.path.isdir(args.repo):
+ shutil.rmtree(args.repo)
+ else:
+ os.remove(args.repo)
+
+ ws = git.Repo.clone_from("{}/{}".format(args.url, args.repo),
+ args.repo, b=args.branch)
+ if ref:
+ git_cmd = ws.git
+ git_cmd.fetch("{}/{}".format(args.url, args.repo), ref)
+ git_cmd.checkout('FETCH_HEAD')
+ logging.info('Checked out commit:\n{}'.format(ws.head.commit.message))
+
+
+def get_parser():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--debug', action='store_true', default=False,
+ help="Turn on debug messages")
+ subparsers = parser.add_subparsers()
+ fork = subparsers.add_parser('clone-fork',
+ help='Clone fork of dependent repo')
+ fork.add_argument('-r', '--repo', required=True, help='Name of repository')
+ fork.add_argument('-u', '--url',
+ default='https://gerrit.opnfv.org/gerrit',
+ help='Gerrit URL of repository')
+ fork.add_argument('-b', '--branch',
+ default='master',
+ help='Branch to checkout')
+ fork.set_defaults(func=clone_fork)
+ return parser
+
+
+def main():
+ parser = get_parser()
+ args = parser.parse_args(sys.argv[1:])
+ if args.debug:
+ logging_level = logging.DEBUG
+ else:
+ logging_level = logging.INFO
+
+ logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
+ datefmt='%m/%d/%Y %I:%M:%S %p',
+ level=logging_level)
+ if hasattr(args, 'func'):
+ args.func(args)
+ else:
+ parser.print_help()
+ exit(1)
+
+if __name__ == "__main__":
+ main()