openSUSE-release-tools/osclib/list_command.py

103 lines
3.8 KiB
Python
Raw Normal View History

from osc import oscerr
2014-02-28 11:45:06 +01:00
class ListCommand:
def __init__(self, api):
self.api = api
def perform(self, packages=None, supersede=False):
2014-03-05 13:01:55 +01:00
"""
Perform the list command
"""
if not packages:
packages = []
if supersede:
if packages:
self.api.dispatch_open_requests(packages)
else:
# First dispatch all possible requests
self.api.dispatch_open_requests()
# Print out the left overs
requests = self.api.get_open_requests()
non_ring_packages = []
change_devel_requests = {}
2016-06-02 16:44:29 +02:00
result = {}
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]
# Where are we targeting the package
target_package = action.find('target').get('package')
# ignore add_role requests
if action.get('type') == 'add_role':
continue
# handle change_devel requests
if action.get('type') == 'change_devel':
change_devel_requests[target_package] = request_id
continue
2015-03-24 14:46:36 +01:00
# If the system have rings, we ask for the ring of the
# package
if self.api.crings:
ring = self.api.ring_packages_for_links.get(target_package)
2016-06-02 16:44:29 +02:00
if ring:
# cut off *:Rings: prefix
ring = ring[len(self.api.crings)+1:]
2015-03-24 14:46:36 +01:00
else:
ring = self.api.project
2015-09-09 16:18:20 +08:00
# list all deletereq as in-ring
if action.get('type') == 'delete':
if ring:
ring = ring + " (delete request)"
else:
2016-06-02 16:44:29 +02:00
ring = '(delete request)'
2015-09-09 16:18:20 +08:00
2015-03-24 14:46:36 +01:00
# This condition is quite moot as we dispatched stuff
# above anyway
if ring:
2016-06-02 16:44:29 +02:00
devel = self.api.get_devel_project("openSUSE:Factory", target_package)
if devel is None:
devel = '00'
result.setdefault(devel, []).append('sr#{}: {:<30} -> {:<12}'.format(request_id, target_package, ring))
# show origin of request
if self.api.project != "openSUSE:Factory" and action.find('source') != None:
source_prj = action.find('source').get('project')
if source_prj.startswith('SUSE:SLE-12:') \
or source_prj.startswith('SUSE:SLE-12-'):
source_prj = source_prj[len('SUSE:SLE-12:'):]
elif source_prj.startswith('openSUSE:'):
source_prj = source_prj[len('openSUSE:'):]
if source_prj.startswith('Leap:'):
source_prj = source_prj[len('Leap:'):]
elif source_prj.startswith('home:'):
source_prj = '~' + source_prj[len('home:'):]
result[devel][-1] += ' ({})'.format(source_prj)
else:
non_ring_packages.append(target_package)
2016-06-02 16:44:29 +02:00
for prj in sorted(result.keys()):
print prj
for line in result[prj]:
print ' ', line
if len(non_ring_packages):
print "Not in a ring:", ' '.join(sorted(non_ring_packages))
if len(change_devel_requests):
print "\nChange devel requests:"
for package, requestid in change_devel_requests.items():
print('Request({}): {}'.format(package, 'https://build.opensuse.org/request/show/'+str(requestid)))