Refactory list command using the api so we can use it in other commands too.
This commit is contained in:
parent
d6286b6fde
commit
24bf0341be
@ -12,47 +12,27 @@ class ListCommand:
|
||||
"""
|
||||
Perform the list command
|
||||
"""
|
||||
self.packages_staged = dict()
|
||||
for prj in self.api.get_staging_projects():
|
||||
meta = self.api.get_prj_pseudometa(prj)
|
||||
for req in meta['requests']:
|
||||
self.packages_staged[req['package']] = {'prj': prj, 'rq_id': req['id'] }
|
||||
|
||||
where = "@by_group='factory-staging'+and+@state='new'"
|
||||
# First dispatch all possible requests
|
||||
self.api.dispatch_open_requests()
|
||||
|
||||
url = makeurl(self.api.apiurl, ['search','request'], "match=state/@name='review'+and+review["+where+"]")
|
||||
f = http_GET(url)
|
||||
root = ET.parse(f).getroot()
|
||||
for rq in root.findall('request'):
|
||||
self.one_request(rq)
|
||||
# Print out the left overs
|
||||
requests = self.api.get_open_requests()
|
||||
|
||||
def one_request(self, request):
|
||||
"""
|
||||
Process one request potentially to be listed
|
||||
:param request: request to process
|
||||
"""
|
||||
rq_id = int(request.get('id'))
|
||||
actions = request.findall('action')
|
||||
act = actions[0]
|
||||
for request in requests:
|
||||
# Consolidate all data from request
|
||||
request_id = int(request.get('id'))
|
||||
action = request.findall('action')
|
||||
if not action:
|
||||
msg = 'Request {} has no action'.format(request_id)
|
||||
raise oscerr.WrongArgs(msg)
|
||||
# we care only about first action
|
||||
action = action[0]
|
||||
|
||||
tpkg = act.find('target').get('package')
|
||||
# Where are we targeting the package
|
||||
target_package = action.find('target').get('package')
|
||||
|
||||
# Replace superseded
|
||||
stage_info = self.packages_staged.get(tpkg, {'prj': '', 'rq_id': 0})
|
||||
if stage_info['rq_id'] != 0 and int(stage_info['rq_id']) != rq_id:
|
||||
# Remove the old request
|
||||
self.api.rm_from_prj(stage_info['prj'], request_id=stage_info['rq_id'],
|
||||
review='declined', msg='Replaced by newer request')
|
||||
# Add the new one that should be replacing it
|
||||
self.api.rq_to_prj(rq_id, stage_info['prj'])
|
||||
# Update local data structure
|
||||
self.packages_staged[tpkg]['rq_id'] = rq_id
|
||||
return
|
||||
|
||||
ring = self.api.ring_packages.get(tpkg)
|
||||
if ring:
|
||||
print("Request(%d): %s -> %s" % (rq_id, tpkg, ring))
|
||||
return
|
||||
|
||||
# no ring, no group -> ok
|
||||
self.api.change_review_state(rq_id, 'accepted', by_group='factory-staging', message='ok')
|
||||
ring = self.api.ring_packages.get(target_package)
|
||||
# This condition is quite moot as we dispatched stuff above anyway
|
||||
if ring:
|
||||
print('Request({}): {} -> {}'.format(request_id, target_package, ring))
|
||||
|
@ -38,6 +38,7 @@ class StagingAPI(object):
|
||||
self.rings = ['openSUSE:Factory:Rings:0-Bootstrap',
|
||||
'openSUSE:Factory:Rings:1-MinimalX']
|
||||
self.ring_packages = self._generate_ring_packages()
|
||||
self.packages_staged = self._get_staged_requests()
|
||||
|
||||
def makeurl(self, l, query=None):
|
||||
"""
|
||||
@ -62,6 +63,20 @@ class StagingAPI(object):
|
||||
ret[entry.attrib['name']] = prj
|
||||
return ret
|
||||
|
||||
def _get_staged_requests(self):
|
||||
"""
|
||||
Get all requests that are already staged
|
||||
:return dict of staged requests with their project and srid
|
||||
"""
|
||||
|
||||
packages_staged = dict()
|
||||
for prj in self.get_staging_projects():
|
||||
meta = self.get_prj_pseudometa(prj)
|
||||
for req in meta['requests']:
|
||||
packages_staged[req['package']] = {'prj': prj, 'rq_id': req['id'] }
|
||||
|
||||
return packages_staged
|
||||
|
||||
def get_package_information(self, project, pkgname):
|
||||
"""
|
||||
Get the revision packagename and source project to copy from
|
||||
@ -184,10 +199,45 @@ class StagingAPI(object):
|
||||
ring = self.ring_packages.get(target_package, None)
|
||||
if not ring:
|
||||
# accept the request here
|
||||
message = 'No need for staging, not in tested ring project.'
|
||||
message = 'No need for staging, not in tested ring projects.'
|
||||
self.change_review_state(request_id, 'accepted', message=message,
|
||||
by_group='factory-staging')
|
||||
|
||||
def update_superseded_request(self, request):
|
||||
"""
|
||||
Replace superseded requests that are already in some
|
||||
staging prj
|
||||
:param request: request we are checking if it is fine
|
||||
"""
|
||||
|
||||
# Consolidate all data from request
|
||||
request_id = int(request.get('id'))
|
||||
action = request.findall('action')
|
||||
if not action:
|
||||
msg = 'Request {} has no action'.format(request_id)
|
||||
raise oscerr.WrongArgs(msg)
|
||||
# we care only about first action
|
||||
action = action[0]
|
||||
|
||||
# Where are we targeting the package
|
||||
target_project = action.find('target').get('project')
|
||||
target_package = action.find('target').get('package')
|
||||
|
||||
# If the values are empty it is no error
|
||||
if not target_project or not target_package:
|
||||
msg = 'no target/package in request {}, action {}; '
|
||||
msg = msg.format(request_id, action)
|
||||
logging.info(msg)
|
||||
|
||||
# If the package is currently tracked then we do the replacement
|
||||
stage_info = self.packages_staged.get(target_package, {'prj': '', 'rq_id': 0})
|
||||
if stage_info['rq_id'] != 0 and int(stage_info['rq_id']) != request_id:
|
||||
# Remove the old request
|
||||
self.api.rm_from_prj(stage_info['prj'], request_id=stage_info['rq_id'],
|
||||
review='declined', msg='Replaced by newer request')
|
||||
# Add the new one that should be replacing it
|
||||
self.api.rq_to_prj(request_id, stage_info['prj'])
|
||||
|
||||
def get_open_requests(self):
|
||||
"""
|
||||
Get all requests with open review for staging project
|
||||
@ -221,6 +271,7 @@ class StagingAPI(object):
|
||||
# check if we can reduce it down by accepting some
|
||||
for rq in requests:
|
||||
self.accept_non_ring_request(rq)
|
||||
self.update_superseded_request(rq)
|
||||
|
||||
def get_prj_pseudometa(self, project):
|
||||
"""
|
||||
@ -294,7 +345,7 @@ class StagingAPI(object):
|
||||
def get_request_id_for_package(self, project, package):
|
||||
"""
|
||||
Query the request id from meta
|
||||
:param project: project to remove from
|
||||
:param project: project the package is in
|
||||
:param package: package we want to query for
|
||||
"""
|
||||
data = self.get_prj_pseudometa(project)
|
||||
@ -306,7 +357,7 @@ class StagingAPI(object):
|
||||
def get_package_for_request_id(self, project, request_id):
|
||||
"""
|
||||
Query the request id from meta
|
||||
:param project: project to remove from
|
||||
:param project: project the package is in
|
||||
:param package: package we want to query for
|
||||
"""
|
||||
data = self.get_prj_pseudometa(project)
|
||||
|
Loading…
x
Reference in New Issue
Block a user