2014-08-07 12:39:41 +02:00
|
|
|
from osc import oscerr
|
2014-02-28 11:45:06 +01:00
|
|
|
|
2014-02-18 14:05:57 +01:00
|
|
|
|
|
|
|
class ListCommand:
|
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
|
|
|
|
2015-10-01 19:09:15 +08:00
|
|
|
def perform(self, packages=None, supersede=False):
|
2014-03-05 13:01:55 +01:00
|
|
|
"""
|
|
|
|
Perform the list command
|
|
|
|
"""
|
2014-02-18 14:05:57 +01:00
|
|
|
|
2015-10-01 19:09:15 +08:00
|
|
|
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()
|
2014-03-06 11:43:21 +01:00
|
|
|
|
|
|
|
# Print out the left overs
|
|
|
|
requests = self.api.get_open_requests()
|
|
|
|
|
2015-07-16 12:21:15 +02:00
|
|
|
non_ring_packages = []
|
2015-09-09 15:11:47 +08:00
|
|
|
change_devel_requests = {}
|
2015-07-16 12:21:15 +02:00
|
|
|
|
2016-06-02 16:44:29 +02:00
|
|
|
result = {}
|
2014-03-06 11:43:21 +01:00
|
|
|
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')
|
|
|
|
|
2016-08-23 16:58:44 +08:00
|
|
|
# ignore add_role requests
|
|
|
|
if action.get('type') == 'add_role':
|
|
|
|
continue
|
|
|
|
|
2015-09-09 15:11:47 +08:00
|
|
|
# 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:
|
2016-06-13 16:54:01 +08:00
|
|
|
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
|
2014-03-06 11:43:21 +01:00
|
|
|
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'
|
2016-06-26 13:15:05 +02: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)
|
2015-07-16 12:21:15 +02:00
|
|
|
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
|
|
|
|
|
2015-07-16 12:21:15 +02:00
|
|
|
if len(non_ring_packages):
|
|
|
|
print "Not in a ring:", ' '.join(sorted(non_ring_packages))
|
2015-09-09 15:11:47 +08:00
|
|
|
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)))
|