From 5cdde68c8be9fb6c4a4f18d922708b81f148a523 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Tue, 4 Mar 2014 16:50:49 +0100 Subject: [PATCH 1/3] 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] From 6ece494c0afbf4f6a21ace2e74c76eb42dd3d28b Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Tue, 4 Mar 2014 18:21:59 +0100 Subject: [PATCH 2/3] Make sure that the request_id is an integer --- osclib/stagingapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 150efca9..31c05259 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -310,6 +310,7 @@ class StagingAPI(object): :param package: package we want to query for """ data = self.get_prj_pseudometa(project) + request_id = int(request_id) for x in data['requests']: if x['id'] == request_id: return x['package'] From eb4aee3a19a9a3646587e02f97f3679192c84893 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Tue, 4 Mar 2014 18:22:37 +0100 Subject: [PATCH 3/3] A better approach for action #1784 --- osc-staging.py | 14 ++++------- osclib/request_finder.py | 51 ++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/osc-staging.py b/osc-staging.py index c7c540b0..98e9db3b 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -260,15 +260,11 @@ 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': - 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)) + for rq, rq_prj in RequestFinder.find_staged_sr(args[1:], opts.apiurl, api).items(): + print('Unselecting "{}" from "{}"'.format(rq, rq_prj['staging'])) + api.rm_from_prj(rq_prj['staging'], request_id=rq) + api.add_review(rq, by_group='factory-staging', + msg='Please recheck') elif cmd == 'select': tprj = api.prj_from_letter(args[1]) return SelectCommand(api).perform(tprj, args[2:], opts.move, opts.from_) diff --git a/osclib/request_finder.py b/osclib/request_finder.py index 281fe98b..d87459dd 100644 --- a/osclib/request_finder.py +++ b/osclib/request_finder.py @@ -12,7 +12,7 @@ STG_PREFIX = 'openSUSE:Factory:Staging:' class RequestFinder: - def __init__(self, apiurl): + def __init__(self, apiurl, stagingapi): # Store the list of submit request together with the source project # # Example: @@ -29,6 +29,7 @@ class RequestFinder: # } # self.apiurl = apiurl + self.stagingapi = stagingapi self.srs = {} def find_request_id(self, request): @@ -121,12 +122,10 @@ class RequestFinder: return ret - def find(self, pkgs, include_project=True): + def find(self, pkgs): """ 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. """ @@ -139,25 +138,53 @@ class RequestFinder: continue raise oscerr.WrongArgs('No SR# found for: {}'.format(p)) + def find_via_stagingapi(self, pkgs): + """ + Search for all various mutations and return list of SR#s. Use + and instance of StagingAPI to direct the search, this makes + sure that the SR# are inside a staging project. + :param pkgs: mesh of argumets to search for + + This function is only called for its side effect. + """ + def _is_int(x): + return isinstance(x, int) or x.isdigit() + + for p in pkgs: + found = False + for staging in self.stagingapi.get_staging_projects(): + if _is_int(p) and self.stagingapi.get_package_for_request_id(staging, p): + self.srs[int(p)] = {'staging': staging} + found = True + continue + else: + rq = self.stagingapi.get_request_id_for_package(staging, p) + if rq: + self.srs[rq] = {'staging': staging} + found = True + continue + if not found: + raise oscerr.WrongArgs('No SR# found for: {}'.format(p)) + @classmethod - def find_sr(cls, pkgs, apiurl): + def find_sr(cls, pkgs, apiurl, stagingapi=None): """ Search for all various mutations and return list of SR#s :param pkgs: mesh of argumets to search for :param apiurl: OBS url """ - finder = cls(apiurl) + finder = cls(apiurl, stagingapi) finder.find(pkgs) return finder.srs @classmethod - def find_single_sr(cls, pkg, apiurl): + def find_staged_sr(cls, pkgs, apiurl, stagingapi): """ Search for all various mutations and return a single SR#s. - :param pkg: a single SR|package to search + :param pkgs: mesh of argumets to search for (SR#|package name) :param apiurl: OBS url + :param stagingapi: StagingAPI instance """ - 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] + finder = cls(apiurl, stagingapi) + finder.find_via_stagingapi(pkgs) + return finder.srs