From 33dcce48cee11f0f40cbf3871d4cd2fcfd7ae379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Mon, 2 Nov 2009 08:32:15 +0000 Subject: [PATCH] implement "mbranch" call as documented on http://en.opensuse.org/Build_Service/Concepts/Maintenance --- NEWS | 3 ++- osc/commandline.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ osc/conf.py | 4 +++ osc/core.py | 33 +++++++++++++++++++++++-- 4 files changed, 98 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 27a5c104..4d35df05 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,3 @@ - - partial fix for bnc#551147 0.124 - added 'osc bugowner' as a more intelligent version of 'osc maintainer -B' @@ -15,11 +14,13 @@ * This is meant as a proof of concept. I intend to generalize this usage of '.' for all osc commands. Feedback welcome. - support http proxies when using python 2.6 or newer (#551004) + - partial fix for checkout problems (bnc#551147) # # Features which require OBS 1.7 # - search: allow to limit results via existing attibutes - added "osc meta attribute" for basic attribute creation, deletion, showing and value setting + - implement "osc mbranch" call to create projects with multiple source package (instances) 0.123 - IMPORTANT: ssl certificate checks are actually performed now to diff --git a/osc/commandline.py b/osc/commandline.py index 3d0e77fc..3774dae7 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1294,6 +1294,67 @@ Please submit there instead, or use --nodevelproject to force direct submission. print r + @cmdln.option('-c', '--checkout', action='store_true', + help='Checkout branched package afterwards ' \ + '(\'osc bco\' is a shorthand for this option)' ) + @cmdln.option('-a', '--attribute', metavar='ATTRIBUTE', + help='Use this attribute to find affected packages (default is OBS:Maintained)') + @cmdln.option('-u', '--update-project-attribute', metavar='UPDATE_ATTRIBUTE', + help='Use this attribute to find update projects (default is OBS:UpdateProject) ') + def do_mbranch(self, subcmd, opts, *args): + """${cmd_name}: Multiple branch of a package + + [See http://en.opensuse.org/Build_Service/Concepts/Maintenance for information + on this topic.] + + This command is used for creating multiple links of defined version of a package + in one project. This is esp. used for maintenance updates. + + The branched package will live in + home:USERNAME:branches:ATTRIBUTE:PACKAGE + if nothing else specified. + + usage: + osc mbranch [ SOURCEPACKAGE [ TARGETPROJECT ] ] + ${cmd_option_list} + """ + args = slash_split(args) + tproject = None + + maintained_attribute = conf.config['maintained_attribute'] + maintained_update_project_attribute = conf.config['maintained_update_project_attribute'] + + if not (len(args) >= 1 and len(args) <= 2): + raise oscerr.WrongArgs('Wrong number of arguments.') + if len(args) >= 1: + package = args[0] + if len(args) >= 2: + tproject = args[1] + + r = attribute_branch_pkg(conf.config['apiurl'], maintained_attribute, maintained_update_project_attribute, \ + package, tproject) + + if r is None: + print >>sys.stderr, 'ERROR: Attribute branch call came not back with a project.' + sys.exit(1) + + print "Project " + r + " created." + + if opts.checkout: + init_project_dir(conf.config['apiurl'], r, r) + print statfrmt('A', r) + + # all packages + for package in meta_get_packagelist(conf.config['apiurl'], r): + try: + checkout_package(conf.config['apiurl'], r, package, expand_link = True, prj_dir = r) + except: + print >>sys.stderr, 'Error while checkout package:\n', package + + if conf.config['verbose']: + print 'Note: You can use "osc delete" or "osc submitpac" when done.\n' + + @cmdln.alias('branchco') @cmdln.alias('bco') @cmdln.alias('getpac') diff --git a/osc/conf.py b/osc/conf.py index 45396480..699fb666 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -106,6 +106,10 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org', 'check_filelist': '1', # check for pending requests after executing an action (e.g. checkout, update, commit) 'check_for_request_on_action': '0', + + # Maintenance defaults to OBS instance defaults + 'maintained_attribute': 'OBS:Maintained', + 'maintained_update_project_attribute': 'OBS:UpdateProject', } # being global to this module, this dict can be accessed from outside diff --git a/osc/core.py b/osc/core.py index b3352f8d..bc7decbc 100755 --- a/osc/core.py +++ b/osc/core.py @@ -1783,8 +1783,6 @@ def makeurl(baseurl, l, query=[]): function. In case of a list not -- this is to be backwards compatible. """ - print 'makeurl:', baseurl, l, query - if type(query) == type(list()): query = '&'.join(query) elif type(query) == type(dict()): @@ -3063,6 +3061,37 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map = http_PUT(u, data=aggregate_template) print 'Done.' + +def attribute_branch_pkg(apiurl, attribute, maintained_update_project_attribute, package, targetproject): + """ + Branch packages defined via attributes (via API call) + """ + query = { 'cmd': 'branch' } + query['attribute'] = attribute + if targetproject: + query['target_project'] = targetproject + if package: + query['package'] = package + if maintained_update_project_attribute: + query['update_project_attribute'] = maintained_update_project_attribute + + u = makeurl(apiurl, ['source'], query=query) + try: + f = http_POST(u) + except urllib2.HTTPError, e: + if not return_existing: + raise + msg = ''.join(e.readlines()) + msg = msg.split('')[1] + msg = msg.split('')[0] + m = re.match(r"branch target package already exists: (\S+)/", msg) + + r = f.read() + r = r.split('targetproject">')[1] + r = r.split('')[0] + return r + + def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None, target_project=None, target_package=None, return_existing=False): """ Branch a package (via API call)