diff options
author | Ed Bartosh <eduard.bartosh@intel.com> | 2013-08-17 12:06:10 +0300 |
---|---|---|
committer | Ed Bartosh <eduard.bartosh@intel.com> | 2013-08-17 12:10:37 +0300 |
commit | 63de51252946c0db6d0e2d86bc07d19ee7ef8b23 (patch) | |
tree | fa5896cb559849b1ef16fcdf15518b27e649c2b3 | |
parent | 2a976434fcaec9ebd3e06bab3cbaf9ddb481fa27 (diff) | |
download | repa-63de51252946c0db6d0e2d86bc07d19ee7ef8b23.tar.gz repa-63de51252946c0db6d0e2d86bc07d19ee7ef8b23.tar.bz2 repa-63de51252946c0db6d0e2d86bc07d19ee7ef8b23.zip |
Draft implementation of repa accept
Acceptance is done by creating SRs for all packages and immediately
changing their state to 'accepted'.
This change also introduces common APIs, which will be used for further
implementation of repa reject command.
Change-Id: I35660dd266941531dd8421b7c141c904eb350b9b
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
-rw-r--r-- | repa/accept.py | 42 | ||||
-rw-r--r-- | repa/common.py | 60 | ||||
-rw-r--r-- | setup.py | 3 |
3 files changed, 104 insertions, 1 deletions
diff --git a/repa/accept.py b/repa/accept.py new file mode 100644 index 0000000..178b3c1 --- /dev/null +++ b/repa/accept.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +""" +REPA: Release Engineering Process Assistant. + +Copyright (C) Intel Corporation 2013 +Licence: GPL version 2 +Author: Ed Bartosh <eduard.bartosh@intel.com> + +Accept module. +Accept submissions. +""" + +import sys + +from repa.obs import OBS +from repa.main import sub_main +from repa.common import accept_or_reject + + +class Accept(object): + """Subcommand: accept submissions.""" + + name = 'accept' + description = 'Accept submission or group' + help = description + + @staticmethod + def add_arguments(parser, _config): + """Adds arguments to the parser. Called from [sub_]main.""" + parser.add_argument('submission', help='submission or group') + parser.add_argument('-comment', help='comment', default='') + + @staticmethod + def run(argv): + """Command line entry point. Called from [sub_]main.""" + obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd) + return accept_or_reject(obs, argv.submission, 'accepted', + argv.comment) + +if __name__ == '__main__': + sys.exit(sub_main(sys.argv[1:], Accept())) diff --git a/repa/common.py b/repa/common.py index 2fd61d5..9384839 100644 --- a/repa/common.py +++ b/repa/common.py @@ -11,7 +11,67 @@ Common module. Common functions, classes, exceptions. """ +import json + +from repa.obs import OBS_PREFIX + class RepaException(Exception): """Custom repa exception. All repa modules should use it.""" pass +def get_project_by_name(obs, name): + """Lookup for a project in OBS by submission or group name.""" + if name.startswith("submitgroup"): + mask = '^%s%s$' + else: + mask = '^%s.*:%s$' + + projects = list(obs.get_projects(mask % (OBS_PREFIX, + name.replace('/', ':')))) + if not projects: + raise RepaException('OBS project not found for %s' % name) + if len(projects) > 1: + raise RepaException('%s resolves into multiple projects' % name) + + return projects[0][0], json.loads(projects[0][1]) + + + +def _resolve_submissions(obs, name): + """Get list of submissions with meta. Resolves submitgroups.""" + project, meta = get_project_by_name(obs, name) + if name.startswith('submitgroup'): + for subm in meta['submissions']: + sprj, smeta = get_project_by_name(obs, subm) + yield subm, sprj, smeta + else: + yield name, project, meta + + +def delete_project(obs, name): + """Delete OBS project related to submission or submit group.""" + project = get_project_by_name(obs, name)[0] + obs.delete_project(project) + + +def accept_or_reject(obs, submission, state, comment=''): + """Create SRs and set their state for one submission or for a group.""" + for name, project, meta in _resolve_submissions(obs, submission): + # osc submitreq [OPTIONS] SOURCEPRJ SOURCEPKG DESTPRJ [DESTPKG] + # osc request accept [-m TEXT] ID + message = "submission %s" % str(name) + print message + if comment: + message += ' comment: %s' % comment + for pkg in obs.get_source_packages(project): + # Create SR + reqid = obs.create_sr(project, pkg, str(meta['obs_target_prj']), + message=message) + print 'package %s: created SR %s' % (pkg, reqid) + # and immediately set its state + obs.set_sr_state(reqid, state=state, message=message, force=True) + print 'set SR state to', state + # delete submit group + if submission.startswith('submitgroup'): + delete_project(obs, submission) + @@ -24,6 +24,7 @@ setup(name = "repa", entry_points = { 'console_scripts': ['repa = repa.main:main'], 'repa_commands': ['list = repa.list:List', - 'group = repa.group:Group'] + 'group = repa.group:Group', + 'accept = repa.accept:Accept'] } ) |