--- /dev/null
+#!/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()))
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)
+