2017-04-21 17:09:17 -05:00
|
|
|
from colorama import Fore
|
2014-08-07 12:39:41 +02:00
|
|
|
from osc import oscerr
|
2017-01-13 01:16:05 -06:00
|
|
|
from osclib.request_splitter import RequestSplitter
|
2017-04-19 17:11:46 -05:00
|
|
|
from osclib.supersede_command import SupersedeCommand
|
2014-02-28 11:45:06 +01:00
|
|
|
|
2014-02-18 14:05:57 +01:00
|
|
|
|
|
|
|
class ListCommand:
|
2017-01-13 01:16:05 -06:00
|
|
|
SOURCE_PROJECT_STRIP = [
|
|
|
|
'SUSE:SLE-12:',
|
|
|
|
'SUSE:SLE-12-',
|
|
|
|
'openSUSE:Leap:'
|
|
|
|
'openSUSE:',
|
|
|
|
'home:',
|
|
|
|
]
|
|
|
|
|
2014-02-18 14:05:57 +01:00
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
|
|
|
|
2017-04-19 17:11:46 -05:00
|
|
|
def perform(self, 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 supersede:
|
2017-04-19 17:11:46 -05:00
|
|
|
SupersedeCommand(self.api).perform()
|
2014-03-06 11:43:21 +01:00
|
|
|
|
|
|
|
requests = self.api.get_open_requests()
|
2017-04-26 21:00:26 -05:00
|
|
|
if not len(requests): return
|
2014-03-06 11:43:21 +01:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
splitter = RequestSplitter(self.api, requests, in_ring=True)
|
|
|
|
splitter.filter_add('./action[@type="change_devel"]')
|
|
|
|
change_devel_requests = splitter.filter_only()
|
|
|
|
splitter.reset()
|
|
|
|
|
|
|
|
splitter.filter_add('./action[not(@type="add_role" or @type="change_devel")]')
|
2017-01-31 18:36:54 -06:00
|
|
|
splitter.group_by('./action/target/@devel_project')
|
2017-01-13 01:16:05 -06:00
|
|
|
splitter.split()
|
|
|
|
|
2017-08-31 15:48:14 -05:00
|
|
|
hide_source = self.api.project == 'openSUSE:Factory'
|
2017-01-13 01:16:05 -06:00
|
|
|
for group in sorted(splitter.grouped.keys()):
|
2017-04-21 17:09:17 -05:00
|
|
|
print Fore.YELLOW + group
|
2017-01-13 01:16:05 -06:00
|
|
|
|
|
|
|
for request in splitter.grouped[group]['requests']:
|
|
|
|
request_id = int(request.get('id'))
|
|
|
|
action = request.find('action')
|
|
|
|
target_package = action.find('target').get('package')
|
|
|
|
ring = action.find('target').get('ring')
|
2017-05-10 15:56:57 -05:00
|
|
|
ring_color = Fore.MAGENTA if ring.startswith('0') else ''
|
2017-01-13 01:16:05 -06:00
|
|
|
|
2017-05-10 15:56:57 -05:00
|
|
|
line = '{} {}{:<30}{} -> {}{:<12}{}'.format(
|
|
|
|
request_id, Fore.CYAN, target_package, Fore.RESET,
|
|
|
|
ring_color, ring, Fore.RESET)
|
2017-01-13 01:16:05 -06:00
|
|
|
|
2017-06-15 15:52:42 -05:00
|
|
|
if not hide_source and action.find('source') != None:
|
2017-01-13 01:16:05 -06:00
|
|
|
source_project = action.find('source').get('project')
|
|
|
|
source_project = self.project_strip(source_project)
|
2017-04-28 10:18:39 -05:00
|
|
|
line += ' ({})'.format(Fore.YELLOW + source_project + Fore.RESET)
|
2017-04-26 10:27:10 -05:00
|
|
|
if action.get('type') == 'delete':
|
2017-06-14 22:07:04 -05:00
|
|
|
line += ' (' + Fore.RED + 'delete request' + Fore.RESET + ')'
|
2017-01-13 01:16:05 -06:00
|
|
|
|
2017-04-28 10:18:14 -05:00
|
|
|
message = self.api.ignore_format(request_id)
|
|
|
|
if message:
|
|
|
|
line += '\n' + Fore.WHITE + message + Fore.RESET
|
2017-01-13 01:16:05 -06:00
|
|
|
|
|
|
|
print ' ', line
|
2015-07-16 12:21:15 +02:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
if len(splitter.other):
|
|
|
|
non_ring_packages = []
|
|
|
|
for request in splitter.other:
|
|
|
|
non_ring_packages.append(request.find('./action/target').get('package'))
|
|
|
|
print 'Not in a ring:', ' '.join(sorted(non_ring_packages))
|
2016-06-02 16:44:29 +02:00
|
|
|
|
2015-09-09 15:11:47 +08:00
|
|
|
if len(change_devel_requests):
|
2017-01-13 01:16:05 -06:00
|
|
|
print '\nChange devel requests:'
|
|
|
|
for request in change_devel_requests:
|
|
|
|
target_package = request.find('./action/target').get('package')
|
|
|
|
url = self.api.makeurl(['request', 'show', request.get('id')])
|
|
|
|
print('- request({}): {}'.format(target_package, url))
|
|
|
|
|
|
|
|
def project_strip(self, source_project):
|
|
|
|
home = source_project.startswith('home:')
|
|
|
|
|
|
|
|
for prefix in self.SOURCE_PROJECT_STRIP:
|
|
|
|
if source_project.startswith(prefix):
|
|
|
|
source_project = source_project[len(prefix):]
|
|
|
|
|
|
|
|
if home:
|
|
|
|
source_project = '~' + source_project
|
|
|
|
|
|
|
|
return source_project
|