osc-staging: implement colorization using colorama for adi and list.
This commit is contained in:
parent
b4d00a4134
commit
fb25b7a044
@ -23,7 +23,10 @@ import tempfile
|
|||||||
import warnings
|
import warnings
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
from osc import cmdln
|
from osc import cmdln
|
||||||
|
from osc import conf
|
||||||
from osc import oscerr
|
from osc import oscerr
|
||||||
|
|
||||||
# Expand sys.path to search modules inside the pluging directory
|
# Expand sys.path to search modules inside the pluging directory
|
||||||
@ -112,6 +115,7 @@ def _full_project_name(self, project):
|
|||||||
@cmdln.option('--merge', action='store_true', help='propose merge where applicable and store details to allow future merges')
|
@cmdln.option('--merge', action='store_true', help='propose merge where applicable and store details to allow future merges')
|
||||||
@cmdln.option('--try-strategies', action='store_true', default=False, help='apply strategies and keep any with desireable outcome')
|
@cmdln.option('--try-strategies', action='store_true', default=False, help='apply strategies and keep any with desireable outcome')
|
||||||
@cmdln.option('--strategy', help='apply a specific strategy')
|
@cmdln.option('--strategy', help='apply a specific strategy')
|
||||||
|
@cmdln.option('--no-color', action='store_true', help='strip colors from output (or add staging.color = 0 to the .oscrc general section')
|
||||||
def do_staging(self, subcmd, opts, *args):
|
def do_staging(self, subcmd, opts, *args):
|
||||||
"""${cmd_name}: Commands to work with staging projects
|
"""${cmd_name}: Commands to work with staging projects
|
||||||
|
|
||||||
@ -314,6 +318,8 @@ def do_staging(self, subcmd, opts, *args):
|
|||||||
opts.apiurl = self.get_api_url()
|
opts.apiurl = self.get_api_url()
|
||||||
opts.verbose = False
|
opts.verbose = False
|
||||||
Config(opts.project)
|
Config(opts.project)
|
||||||
|
colorama.init(autoreset=True,
|
||||||
|
strip=(opts.no_color or not bool(int(conf.config.get('staging.color', True)))))
|
||||||
|
|
||||||
if opts.wipe_cache:
|
if opts.wipe_cache:
|
||||||
Cache.delete_all()
|
Cache.delete_all()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
from colorama import Fore
|
||||||
|
|
||||||
from osc import oscerr
|
from osc import oscerr
|
||||||
from osc.core import delete_project
|
from osc.core import delete_project
|
||||||
from osc.core import show_package_meta
|
from osc.core import show_package_meta
|
||||||
@ -17,31 +19,38 @@ class AdiCommand:
|
|||||||
query_project = self.api.extract_staging_short(project)
|
query_project = self.api.extract_staging_short(project)
|
||||||
info = self.api.project_status(project, True)
|
info = self.api.project_status(project, True)
|
||||||
if len(info['building_repositories']):
|
if len(info['building_repositories']):
|
||||||
print query_project, "still building"
|
print query_project, Fore.MAGENTA + 'building'
|
||||||
return
|
return
|
||||||
if len(info['untracked_requests']):
|
if len(info['untracked_requests']):
|
||||||
print query_project, "untracked:", ', '.join(['%s[%s]'%(req['package'], req['number']) for req in info['untracked_requests']])
|
print query_project, Fore.YELLOW + 'untracked:', ', '.join(['{}[{}]'.format(
|
||||||
|
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['untracked_requests']])
|
||||||
return
|
return
|
||||||
if len(info['obsolete_requests']):
|
if len(info['obsolete_requests']):
|
||||||
print query_project, "obsolete:", ', '.join(['%s[%s]'%(req['package'], req['number']) for req in info['obsolete_requests']])
|
print query_project, Fore.YELLOW + 'obsolete:', ', '.join(['{}[{}]'.format(
|
||||||
|
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['obsolete_requests']])
|
||||||
return
|
return
|
||||||
if len(info['broken_packages']):
|
if len(info['broken_packages']):
|
||||||
print query_project, "broken:", ', '.join([p['package'] for p in info['broken_packages']])
|
print query_project, Fore.RED + 'broken:', ', '.join([
|
||||||
|
Fore.CYAN + p['package'] + Fore.RESET for p in info['broken_packages']])
|
||||||
return
|
return
|
||||||
for review in info['missing_reviews']:
|
for review in info['missing_reviews']:
|
||||||
print query_project, "missing review by {} for {}[{}]".format(review['by'], review['package'], review['request'])
|
print query_project, Fore.WHITE + 'review:', '{} for {}[{}]'.format(
|
||||||
|
Fore.YELLOW + review['by'] + Fore.RESET,
|
||||||
|
Fore.CYAN + review['package'] + Fore.RESET,
|
||||||
|
review['request'])
|
||||||
return
|
return
|
||||||
if self.api.is_user_member_of(self.api.user, 'factory-staging'):
|
if self.api.is_user_member_of(self.api.user, 'factory-staging'):
|
||||||
print query_project, "is ready"
|
print query_project, Fore.GREEN + 'ready'
|
||||||
packages = []
|
packages = []
|
||||||
for req in info['selected_requests']:
|
for req in info['selected_requests']:
|
||||||
print " - %s [%s]"%(req['package'], req['number'])
|
print ' - {} [{}]'.format(Fore.CYAN + req['package'] + Fore.RESET, req['number'])
|
||||||
self.api.rm_from_prj(project, request_id=req['number'], msg='ready to accept')
|
self.api.rm_from_prj(project, request_id=req['number'], msg='ready to accept')
|
||||||
packages.append(req['package'])
|
packages.append(req['package'])
|
||||||
self.api.accept_status_comment(project, packages)
|
self.api.accept_status_comment(project, packages)
|
||||||
delete_project(self.api.apiurl, project)
|
delete_project(self.api.apiurl, project)
|
||||||
else:
|
else:
|
||||||
print query_project, "ready:", ', '.join(['%s[%s]'%(req['package'], req['number']) for req in info['selected_requests']])
|
print query_project, Fore.GREEN + 'ready:', ', '.join(['{}[{}]'.format(
|
||||||
|
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['selected_requests']])
|
||||||
|
|
||||||
def check_adi_projects(self):
|
def check_adi_projects(self):
|
||||||
for p in self.api.get_adi_projects():
|
for p in self.api.get_adi_projects():
|
||||||
@ -64,21 +73,21 @@ class AdiCommand:
|
|||||||
splitter.split()
|
splitter.split()
|
||||||
|
|
||||||
for group in sorted(splitter.grouped.keys()):
|
for group in sorted(splitter.grouped.keys()):
|
||||||
print(group if group != '' else 'wanted')
|
print(Fore.YELLOW + (group if group != '' else 'wanted') + Fore.RESET)
|
||||||
|
|
||||||
name = None
|
name = None
|
||||||
for request in splitter.grouped[group]['requests']:
|
for request in splitter.grouped[group]['requests']:
|
||||||
request_id = int(request.get('id'))
|
request_id = int(request.get('id'))
|
||||||
target_package = request.find('./action/target').get('package')
|
target_package = request.find('./action/target').get('package')
|
||||||
line = '- sr#{}: {:<30}'.format(request_id, target_package)
|
line = '- sr#{}: {}{:<30}{}'.format(request_id, Fore.CYAN, target_package, Fore.RESET)
|
||||||
|
|
||||||
if request_id in self.requests_ignored:
|
if request_id in self.requests_ignored:
|
||||||
print(line + '\n ignored: ' + str(self.requests_ignored[request_id]))
|
print(line + Fore.WHITE + '\n ignored: ' + str(self.requests_ignored[request_id]) + Fore.RESET)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Auto-superseding request in adi command
|
# Auto-superseding request in adi command
|
||||||
if self.api.update_superseded_request(request):
|
if self.api.update_superseded_request(request):
|
||||||
print(line + ' (superseded)')
|
print(line + Fore.MAGENTA + ' (superseded)' + Fore.RESET)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Only create staging projec the first time a non superseded
|
# Only create staging projec the first time a non superseded
|
||||||
@ -89,7 +98,7 @@ class AdiCommand:
|
|||||||
if not self.api.rq_to_prj(request_id, name):
|
if not self.api.rq_to_prj(request_id, name):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print(line + ' (staged in {})'.format(name))
|
print(line + Fore.GREEN + ' (staged in {})'.format(name) + Fore.RESET)
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
# Notify everybody about the changes.
|
# Notify everybody about the changes.
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from colorama import Fore
|
||||||
from osc import oscerr
|
from osc import oscerr
|
||||||
from osclib.request_splitter import RequestSplitter
|
from osclib.request_splitter import RequestSplitter
|
||||||
from osclib.supersede_command import SupersedeCommand
|
from osclib.supersede_command import SupersedeCommand
|
||||||
@ -37,17 +38,19 @@ class ListCommand:
|
|||||||
|
|
||||||
is_factory = self.api.project != 'openSUSE:Factory'
|
is_factory = self.api.project != 'openSUSE:Factory'
|
||||||
for group in sorted(splitter.grouped.keys()):
|
for group in sorted(splitter.grouped.keys()):
|
||||||
print group
|
print Fore.YELLOW + group
|
||||||
|
|
||||||
for request in splitter.grouped[group]['requests']:
|
for request in splitter.grouped[group]['requests']:
|
||||||
request_id = int(request.get('id'))
|
request_id = int(request.get('id'))
|
||||||
action = request.find('action')
|
action = request.find('action')
|
||||||
target_package = action.find('target').get('package')
|
target_package = action.find('target').get('package')
|
||||||
ring = action.find('target').get('ring')
|
ring = action.find('target').get('ring')
|
||||||
|
if ring.startswith('0'):
|
||||||
|
ring = Fore.MAGENTA + ring + Fore.RESET
|
||||||
if action.get('type') == 'delete':
|
if action.get('type') == 'delete':
|
||||||
ring += ' (delete request)'
|
ring += Fore.RED + ' (delete request)'
|
||||||
|
|
||||||
line = 'sr#{}: {:<30} -> {:<12}'.format(request_id, target_package, ring)
|
line = 'sr#{}: {}{:<30}{} -> {:<12}'.format(request_id, Fore.CYAN, target_package, Fore.RESET, ring)
|
||||||
|
|
||||||
if is_factory and action.find('source') != None:
|
if is_factory and action.find('source') != None:
|
||||||
source_project = action.find('source').get('project')
|
source_project = action.find('source').get('project')
|
||||||
@ -55,7 +58,7 @@ class ListCommand:
|
|||||||
line += ' ({})'.format(source_project)
|
line += ' ({})'.format(source_project)
|
||||||
|
|
||||||
if request_id in requests_ignored:
|
if request_id in requests_ignored:
|
||||||
line += '\n ignored: ' + str(requests_ignored[request_id])
|
line += Fore.WHITE + '\n ignored: ' + str(requests_ignored[request_id]) + Fore.RESET
|
||||||
|
|
||||||
print ' ', line
|
print ' ', line
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
colorama
|
||||||
lxml
|
lxml
|
||||||
PyYAML
|
PyYAML
|
||||||
pycurl
|
pycurl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user