Merge pull request #91 from aplanas/master
action #1784 Unselect do not need a Project parameter, only the Package
This commit is contained in:
commit
7939060ad4
@ -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,13 @@ 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)
|
||||
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])
|
||||
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()
|
||||
|
@ -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):
|
||||
@ -137,13 +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_staged_sr(cls, pkgs, apiurl, stagingapi):
|
||||
"""
|
||||
Search for all various mutations and return a single SR#s.
|
||||
:param pkgs: mesh of argumets to search for (SR#|package name)
|
||||
:param apiurl: OBS url
|
||||
:param stagingapi: StagingAPI instance
|
||||
"""
|
||||
finder = cls(apiurl, stagingapi)
|
||||
finder.find_via_stagingapi(pkgs)
|
||||
return finder.srs
|
||||
|
@ -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']
|
||||
|
Loading…
x
Reference in New Issue
Block a user