Move CLI argument parsing to argparse and run black on the sources
Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
parent
7d07df40ce
commit
7ba8489b72
1 changed files with 23 additions and 13 deletions
|
@ -1,13 +1,10 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import datetime
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import pygit2
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -34,19 +31,32 @@ def run_command(command, cwd=None):
|
|||
return output
|
||||
|
||||
|
||||
def get_cli_arguments(self):
|
||||
""" Set the CLI argument parser and return the argument parsed.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Script to determine the next NVR of a build"
|
||||
)
|
||||
parser.add_argument("package", help="The name of the package of interest")
|
||||
parser.add_argument("dist", help="The dist-tag of interest")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main(args):
|
||||
""" Main method. """
|
||||
package = args[0]
|
||||
dist = args[1]
|
||||
args = get_cli_arguments(args)
|
||||
|
||||
cmd = f"koji list-builds --package={package} --state=COMPLETE -r --quiet"
|
||||
cmd = f"koji list-builds --package={args.package} --state=COMPLETE -r --quiet"
|
||||
rows = run_command(cmd.split()).decode("utf-8")
|
||||
builds = [row.strip().split()[0] for row in rows.split("\n") if row.strip()]
|
||||
builds = [
|
||||
row.strip().split()[0] for row in rows.split("\n") if row.strip()
|
||||
]
|
||||
n_builds = 1
|
||||
last_build = None
|
||||
nv = None
|
||||
for build in builds:
|
||||
if dist in build:
|
||||
if args.dist in build:
|
||||
if n_builds == 1:
|
||||
last_build = build
|
||||
nv = last_build.rsplit("-", 1)[0]
|
||||
|
@ -54,15 +64,15 @@ def main(args):
|
|||
n_builds += 1
|
||||
|
||||
print(f"Last build: {last_build}")
|
||||
last_build = last_build.rsplit(f".{dist}", 1)[0]
|
||||
last_build = last_build.rsplit(f".{args.dist}", 1)[0]
|
||||
rel = last_build.rsplit("-", 1)[-1]
|
||||
try:
|
||||
rel = int(rel)
|
||||
n_builds = max([rel+1, n_builds])
|
||||
n_builds = max([rel + 1, n_builds])
|
||||
except Exception:
|
||||
pass
|
||||
print(f"Next build: {nv}-{n_builds}.{dist}")
|
||||
print(f"Next build: {nv}-{n_builds}.{args.dist}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue