From cb7823034783303135b2c09042d1d7e4ba9af8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Mon, 23 Jan 2012 14:12:17 +0100 Subject: [PATCH] - ask user to create maintenance incident when submit request fails at release project --- NEWS | 1 + osc/core.py | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index e66286e9..53dff1c8 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ - support dryrun of branching to preview the expected result. "osc sm" is doing this now by default. - maintenance requests accept package lists as source and target incidents to be merged in - add "setincident" command to "request" to re-direct a maintenance request + - ask user to create "maintenance incident" request when submit request is failing at release project 0.133 - add --meta option also to "list", "cat" and "less" commands diff --git a/osc/core.py b/osc/core.py index aceaeccb..beb5faa0 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3433,12 +3433,15 @@ def create_maintenance_request(apiurl, src_project, src_packages, tgt_project, o # This creates an old style submit request for server api 1.0 def create_submit_request(apiurl, - src_project, src_package, + src_project, src_package=None, dst_project=None, dst_package=None, message="", orev=None, src_update=None): import cgi options_block="" + package="" + if src_update: + package="""package="%s" """ % (src_package) if src_update: options_block="""%s """ % (src_update) @@ -3453,7 +3456,7 @@ def create_submit_request(apiurl, xml = """\ - + %s %s @@ -3461,7 +3464,7 @@ def create_submit_request(apiurl, %s """ % (src_project, - src_package, + package, orev or show_upstream_rev(apiurl, src_project, src_package), targetxml, options_block, @@ -3473,10 +3476,26 @@ def create_submit_request(apiurl, # I guess, my original workaround was not that bad. u = makeurl(apiurl, ['request'], query='cmd=create') - f = http_POST(u, data=xml) + try: + f = http_POST(u, data=xml) + root = ET.parse(f).getroot() + r = root.get('id') + except urllib2.HTTPError, e: + if e.headers.get('X-Opensuse-Errorcode') == "submit_request_rejected": + print "This project is just for releasign maintenance updates. Do you want to create a maintenance incident request instead ? [y/n]" + if sys.stdin.read(1) == "y": + xpath = 'attribute/@name = \'%s\'' % conf.config['maintenance_attribute'] + res = search(apiurl, project_id=xpath) + root = res['project_id'] + project = root.find('project') + if project is None: + sys.exit('Unable to find defined OBS:MaintenanceProject project on server.') + tproject = project.get('name') + r = create_maintenance_request(apiurl, src_project, [src_package], tproject, src_update, message) + else: + raise - root = ET.parse(f).getroot() - return root.get('id') + return r def get_request(apiurl, reqid):