action #1784 Unselect do not need a Project parameter, only the Package

This commit is contained in:
Alberto Planas 2014-03-04 16:50:49 +01:00
parent f84a67316e
commit 5cdde68c8b
2 changed files with 28 additions and 8 deletions

View File

@ -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()

View File

@ -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]