2017-04-26 21:10:52 -05:00
|
|
|
from colorama import Fore
|
|
|
|
|
2017-04-19 17:11:46 -05:00
|
|
|
|
|
|
|
class SupersedeCommand(object):
|
2017-04-26 22:27:18 -05:00
|
|
|
CODE_MAP = {
|
2017-04-26 21:10:52 -05:00
|
|
|
None: Fore.MAGENTA + 'superseded' + Fore.RESET,
|
|
|
|
True: Fore.RED + 'declined' + Fore.RESET,
|
|
|
|
False: Fore.WHITE + 'ignored' + Fore.RESET,
|
2017-04-26 22:27:18 -05:00
|
|
|
}
|
|
|
|
|
2017-04-19 17:11:46 -05:00
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
|
|
|
|
2017-04-19 17:18:25 -05:00
|
|
|
def perform(self, requests=None):
|
2017-04-26 22:27:18 -05:00
|
|
|
for stage_info, code, request in self.api.dispatch_open_requests(requests):
|
2017-04-19 17:37:03 -05:00
|
|
|
action = request.find('action')
|
|
|
|
target_package = action.find('target').get('package')
|
2017-05-31 10:10:22 +02:00
|
|
|
if code == 'unstage':
|
|
|
|
# Technically, the new request has not been staged, but superseded the old one.
|
|
|
|
code = None
|
2017-04-26 22:27:18 -05:00
|
|
|
verbage = self.CODE_MAP[code]
|
|
|
|
if code is not None:
|
|
|
|
verbage += ' in favor of'
|
|
|
|
print('request {} for {} {} {} in {}'.format(
|
2017-04-26 21:10:52 -05:00
|
|
|
request.get('id'),
|
|
|
|
Fore.CYAN + target_package + Fore.RESET,
|
|
|
|
verbage,
|
|
|
|
stage_info['rq_id'],
|
|
|
|
Fore.YELLOW + stage_info['prj']))
|