From acbbbacabd9d0bdd9332bebf2ffbdb85fb8371bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Mon, 2 May 2011 13:21:28 +0200 Subject: [PATCH] - add "createincident" command --- NEWS | 4 ++++ osc/commandline.py | 55 +++++++++++++++++++++++++++++++++++++++++++--- osc/conf.py | 1 + 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index aa1d31ba..66427b86 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ 0.132 - +# +# Features which requires OBS 2.3 +# + - new command "createincident" to create maintenance incidents without a request 0.131 - new command 'develproject' to print the devel project from the package meta. diff --git a/osc/commandline.py b/osc/commandline.py index 33891a8b..5e261454 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2441,6 +2441,55 @@ Please submit there instead, or use --nodevelproject to force direct submission. + @cmdln.option('-a', '--attribute', metavar='ATTRIBUTE', + help='Use this attribute to find default maintenance project (default is OBS:MaintenanceProject)') + @cmdln.option('-m', '--message', metavar='TEXT', + help='specify message TEXT') + def do_createincident(self, subcmd, opts, *args): + """${cmd_name}: Create a maintenance incident + + [See http://doc.opensuse.org/products/draft/OBS/obs-reference-guide/cha.obs.maintenance_setup.html + for information on this topic.] + + This command is asking to open an empty maintence incident. This can usually only be done by a responsible + maintenance team. + Please see the "mbranch" command on how to full such a project content and + the "patchinfo" command how add the required maintenance update informations. + + usage: + osc createincident [ MAINTENANCEPROJECT ] + ${cmd_option_list} + """ + + args = slash_split(args) + apiurl = self.get_api_url() + maintenance_attribute = conf.config['maintenance_attribute'] + if opts.attribute: + maintenance_attribute = opts.attribute + + source_project = target_project = None + + if len(args) > 1: + raise oscerr.WrongArgs('Too many arguments.') + + if len(args) == 1: + target_project = args[1] + else: + xpath = 'attribute/@name = \'%s\'' % 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.') + target_project = project.get('name') + print 'Using target project \'%s\'' % target_project + + query = { 'cmd': 'createmaintenanceincident' } + url = makeurl(apiurl, ['source', target_project], query=query) + r = http_POST(url, data=opts.message) + print ET.parse(r).getroot().get('code') + + @cmdln.option('-a', '--attribute', metavar='ATTRIBUTE', help='Use this attribute to find default maintenance project (default is OBS:MaintenanceProject)') @cmdln.option('-m', '--message', metavar='TEXT', @@ -2462,9 +2511,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. args = slash_split(args) apiurl = self.get_api_url() - attribute = "OBS:MaintenanceProject" # default attribute as defined in api code. + maintenance_attribute = conf.config['maintenance_attribute'] if opts.attribute: - attribute = opts.attribute + maintenance_attribute = opts.attribute source_project = target_project = None @@ -2481,7 +2530,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. if len(args) > 1: target_project = args[1] else: - xpath = 'attribute/@name = \'%s\'' % attribute + xpath = 'attribute/@name = \'%s\'' % maintenance_attribute res = search(apiurl, project_id=xpath) root = res['project_id'] project = root.find('project') diff --git a/osc/conf.py b/osc/conf.py index 3131fd61..fb6bbf76 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -139,6 +139,7 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org', # Maintenance defaults to OBS instance defaults 'maintained_attribute': 'OBS:Maintained', + 'maintenance_attribute': 'OBS:MaintenanceProject', 'maintained_update_project_attribute': 'OBS:UpdateProject', 'show_download_progress': '0', }