From 5cdde68c8be9fb6c4a4f18d922708b81f148a523 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Tue, 4 Mar 2014 16:50:49 +0100 Subject: [PATCH] action #1784 Unselect do not need a Project parameter, only the Package --- osc-staging.py | 20 +++++++++++++------- osclib/request_finder.py | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/osc-staging.py b/osc-staging.py index 563d0ab7..c7c540b0 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -187,8 +187,10 @@ def do_staging(self, subcmd, opts, *args): min_args, max_args = 1, 1 elif cmd == 'check': min_args, max_args = 0, 2 - elif cmd in ('select', 'unselect'): + elif cmd == 'select': min_args, max_args = 2, None + elif cmd == 'unselect': + min_args, max_args = 1, None elif cmd in ('list', 'cleanup_rings'): min_args, max_args = 0, 0 else: @@ -258,13 +260,17 @@ def do_staging(self, subcmd, opts, *args): elif cmd == 'accept': return AcceptCommand(api).perform(api. prj_from_letter(args[1]), opts.commit) elif cmd == 'unselect': - tprj = api.prj_from_letter(args[1]) # see issue 1784 - for rq, rq_prj in RequestFinder.find_sr(args[2:], opts.apiurl).items(): - api.rm_from_prj(tprj, request_id=rq) - api.add_review(rq, by_group='factory-staging', - msg='Please recheck') + for rq_or_pkg in args[1:]: + rq, rq_prj = RequestFinder.find_single_sr(rq_or_pkg, opts.apiurl) + if 'staging' in rq_prj: + print('Unselecting "{}" from "{}"'.format(rq_or_pkg, rq_prj['staging'])) + api.rm_from_prj(rq_prj['staging'], request_id=rq) + api.add_review(rq, by_group='factory-staging', + msg='Please recheck') + else: + print('Can\'t unselect "{}" because is not in any staging project'.format(rq_or_pkg)) elif cmd == 'select': - tprj = api. prj_from_letter(args[1]) + tprj = api.prj_from_letter(args[1]) return SelectCommand(api).perform(tprj, args[2:], opts.move, opts.from_) elif cmd == 'cleanup_rings': return CleanupRings(opts.apiurl).perform() diff --git a/osclib/request_finder.py b/osclib/request_finder.py index 4288e5de..281fe98b 100644 --- a/osclib/request_finder.py +++ b/osclib/request_finder.py @@ -121,10 +121,12 @@ class RequestFinder: return ret - def find(self, pkgs): + def find(self, pkgs, include_project=True): """ Search for all various mutations and return list of SR#s :param pkgs: mesh of argumets to search for + :param include_project: if True, include the search or request + inside a project This function is only called for its side effect. """ @@ -147,3 +149,15 @@ class RequestFinder: finder = cls(apiurl) finder.find(pkgs) return finder.srs + + @classmethod + def find_single_sr(cls, pkg, apiurl): + """ + Search for all various mutations and return a single SR#s. + :param pkg: a single SR|package to search + :param apiurl: OBS url + """ + finder = cls(apiurl) + finder.find([pkg], include_project=False) + assert len(finder.srs) <= 1, 'Found more that one submit request' + return finder.srs.items()[0]