Add list-srs command
This command parses the log output of running osc-batch-submit's output script and allows to track the status of the SRs
This commit is contained in:
93
osc_batch_submit/list_srs.py
Normal file
93
osc_batch_submit/list_srs.py
Normal file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/python3
|
||||
import re
|
||||
import sys
|
||||
from osc_batch_submit.osc import OSC
|
||||
from osc_batch_submit.main import __version__
|
||||
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||
|
||||
|
||||
def is_ibs(project):
|
||||
if 'openSUSE.org:' in project:
|
||||
return True
|
||||
elif 'Backports' in project or 'Leap' in project:
|
||||
return False
|
||||
elif 'SUSE:' in project:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def process_log(filename, show_packagelist=False, show_state=False,
|
||||
show_comments=None, verbose=0):
|
||||
contents = open(filename, 'r').read()
|
||||
|
||||
if not verbose and not show_packagelist and not show_state:
|
||||
srs = re.findall(r'created request id ([0-9]*)', contents)
|
||||
print(' '.join(srs))
|
||||
sys.exit(0)
|
||||
|
||||
url = ''
|
||||
packages = []
|
||||
errors = []
|
||||
sections = contents.split('#-# ')
|
||||
osc = None
|
||||
for x, y in [x.split('\n', 1) for x in sections if x]:
|
||||
sr_id = re.search(r'created request id ([0-9]*)', y)
|
||||
srcPrj, package, tgtPrj = x.split(' ')
|
||||
if show_packagelist:
|
||||
packages.append(package)
|
||||
if verbose > 1:
|
||||
if is_ibs(tgtPrj):
|
||||
url = 'https://build.suse.de/request/show/'
|
||||
else:
|
||||
url = 'https://build.opensuse.org/request/show/'
|
||||
|
||||
state_text = ''
|
||||
comments_text = ''
|
||||
if show_state and sr_id:
|
||||
if not osc:
|
||||
osc = OSC(False, ibs=is_ibs(tgtPrj))
|
||||
|
||||
state, state_msg = osc.get_request_state(sr_id.group(1))
|
||||
state_text = f' {state} : {state_msg}'
|
||||
if show_comments:
|
||||
only_last = (show_comments == 'last')
|
||||
comments = osc.get_request_comments(sr_id.group(1),
|
||||
only_last=only_last)
|
||||
if comments and isinstance(comments, list):
|
||||
comments = '\n' + '\n'.join(comments)
|
||||
if comments:
|
||||
comments_text = f' . {comments}'
|
||||
|
||||
if sr_id:
|
||||
print(f'{url}{sr_id.group(1)}{state_text} '
|
||||
f'{package}{comments_text}')
|
||||
else:
|
||||
errors.append(f'?? {package}')
|
||||
|
||||
if show_packagelist:
|
||||
print('{' + ', '.join(packages) + '}')
|
||||
|
||||
if errors:
|
||||
print('\n'.join(errors))
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(description='Manage your music collection',
|
||||
formatter_class=RawTextHelpFormatter)
|
||||
parser.add_argument('--version', action='version',
|
||||
version='list-srs ' + __version__)
|
||||
parser.add_argument('log_file')
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
parser.add_argument('--show-state', '-s', action='store_true')
|
||||
parser.add_argument('--show-comments', '-c', choices=[None, 'all', 'last'],
|
||||
default=None)
|
||||
parser.add_argument('--packagelist', action='store_true')
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
process_log(options.log_file, options.packagelist, options.show_state,
|
||||
options.show_comments, options.verbose)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@@ -23,3 +23,4 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project.scripts]
|
||||
osc-batch-submit = "osc_batch_submit.main:main"
|
||||
list-srs = "osc_batch_submit.list_srs:main"
|
||||
|
Reference in New Issue
Block a user