2018-11-05 15:46:50 +01:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-04-21 17:09:17 -05:00
|
|
|
from colorama import Fore
|
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
|
|
|
|
2022-02-18 17:15:48 +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:',
|
2017-08-31 16:13:02 -05:00
|
|
|
'openSUSE.org:',
|
2017-01-13 01:16:05 -06:00
|
|
|
'home:',
|
|
|
|
]
|
|
|
|
|
2014-02-18 14:05:57 +01:00
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
|
|
|
|
2024-10-31 14:21:23 +01:00
|
|
|
def print_request(self, request):
|
|
|
|
hide_source = self.api.project == 'openSUSE:Factory'
|
|
|
|
request_id = int(request.get('id'))
|
|
|
|
action = request.find('action')
|
|
|
|
target_package = action.find('target').get('package')
|
|
|
|
ring = action.find('target').get('ring', None)
|
|
|
|
|
|
|
|
line = f"{request_id} {Fore.CYAN}{target_package:<30}{Fore.RESET}"
|
|
|
|
if ring:
|
|
|
|
ring_color = Fore.MAGENTA if ring.startswith('0') else ''
|
|
|
|
line += f" -> {ring_color}{ring:<12}{Fore.RESET}"
|
|
|
|
|
|
|
|
if not hide_source and action.find('source') is not None:
|
|
|
|
source_project = action.find('source').get('project')
|
|
|
|
source_project = self.project_strip(source_project)
|
|
|
|
line += f' ({Fore.YELLOW + source_project + Fore.RESET})'
|
|
|
|
if action.get('type') == 'delete':
|
|
|
|
line += ' (' + Fore.RED + 'delete request' + Fore.RESET + ')'
|
|
|
|
|
|
|
|
message = self.api.ignore_format(request_id)
|
|
|
|
if message:
|
|
|
|
line += '\n' + Fore.WHITE + message + Fore.RESET
|
|
|
|
|
|
|
|
print(' ', line)
|
|
|
|
|
2024-10-31 16:23:29 +01:00
|
|
|
def perform(self, adi_details=False, match_filter=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 supersede:
|
2017-04-19 17:11:46 -05:00
|
|
|
SupersedeCommand(self.api).perform()
|
2014-03-06 11:43:21 +01:00
|
|
|
|
2024-10-31 16:23:29 +01:00
|
|
|
requests = self.api.get_open_requests(match_filter=match_filter)
|
2022-02-18 13:42:57 +01: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)
|
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()
|
|
|
|
|
|
|
|
for group in sorted(splitter.grouped.keys()):
|
2018-11-05 15:46:50 +01:00
|
|
|
print(Fore.YELLOW + group)
|
2017-01-13 01:16:05 -06:00
|
|
|
|
|
|
|
for request in splitter.grouped[group]['requests']:
|
2024-10-31 14:21:23 +01:00
|
|
|
self.print_request(request)
|
2015-07-16 12:21:15 +02:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
if len(splitter.other):
|
2024-10-31 14:21:23 +01:00
|
|
|
non_ring_requests = splitter.other
|
|
|
|
if adi_details:
|
|
|
|
print('Not in a ring: ')
|
|
|
|
for request in non_ring_requests:
|
|
|
|
self.print_request(request)
|
|
|
|
else:
|
|
|
|
non_ring_packages = sorted(
|
|
|
|
request.find('./action/target').get('package')
|
|
|
|
for request in non_ring_requests)
|
|
|
|
print('Not in a ring: ' + ' '.join(non_ring_packages))
|
2016-06-02 16:44:29 +02:00
|
|
|
|
2017-08-31 16:18:40 -05:00
|
|
|
# Print requests not handled by staging process to highlight them.
|
2018-10-31 16:24:16 -05:00
|
|
|
splitter.stageable = False
|
2017-08-31 16:18:40 -05:00
|
|
|
for request_type in ('change_devel', 'set_bugowner'):
|
|
|
|
splitter.reset()
|
2024-05-07 17:55:17 +02:00
|
|
|
splitter.filter_add(f'./action[@type="{request_type}"]')
|
2017-08-31 16:18:40 -05:00
|
|
|
requests = splitter.filter_only()
|
|
|
|
if len(requests):
|
2024-05-07 17:55:17 +02:00
|
|
|
print(f'\n{request_type} request(s)')
|
2017-08-31 16:18:40 -05:00
|
|
|
for request in sorted(requests, key=lambda s: s.get('id')):
|
|
|
|
print(' {} {}'.format(
|
|
|
|
self.api.makeurl(['request', 'show', request.get('id')]),
|
|
|
|
request.find('./action/target').get('package')))
|
2017-01-13 01:16:05 -06:00
|
|
|
|
|
|
|
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
|