From 027db4a953f08f9bc6a7e8ddaf38b37f4417b069 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 18 Mar 2024 12:07:03 -0400 Subject: Switch build.py to argparse Provides much more reliable and consistent argumentation and help documentation for the script. Also supports "auto" as a version identical to "master" for better clarity of what it does. --- build.py | 63 ++++++++++++++++++++++----------------------------------------- 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/build.py b/build.py index 770b663..aedda11 100755 --- a/build.py +++ b/build.py @@ -5,6 +5,7 @@ # Part of the Jellyfin CI system ############################################################################### +from argparse import ArgumentParser from datetime import datetime from email.utils import format_datetime, localtime from os import getenv @@ -544,56 +545,36 @@ function_definitions = { "build_nuget": build_nuget, } -try: - jellyfin_version = sys.argv[1] - build_type = sys.argv[2] -except IndexError: - log("Error: Missing required arguments ('JELLYFIN_VERSION' and/or 'BUILD_TYPE')") - log("") - usage() - exit(1) -if build_type not in configurations.keys(): - log(f"Error: The specified build type '{build_type}' is not valid") - log("") - usage() - exit(1) +parser = ArgumentParser( + prog='build.py', + description='Jellyfin build automator', + epilog='See "README.md" and "build.yaml" for the full details of what this tool can build at this time.', +) -try: - if configurations[build_type]["build_function"] not in function_definitions.keys(): - raise ValueError -except Exception: - log( - f"Error: The specified valid build type '{build_type}' does not define a valid build function" - ) - log( - "This is a misconfiguration of the YAML or the build script; please report a bug!" - ) - exit(1) +parser.add_argument('jellyfin_version', help='The output version') +parser.add_argument('build_type', choices=configurations.keys(), help='The build platform') +parser.add_argument('build_arch', default=None, nargs='?', help='The build architecture') +parser.add_argument('build_version', default=None, nargs='?', help='The build release version [debian/ubuntu only]') +parser.add_argument('--no-push', action='store_true', help='Do not generate Docker manifests or push them [docker only]') -# Optional argument (only required for some build functions) -try: - build_arch = sys.argv[3] -except IndexError: - build_arch = None +args = parser.parse_args() -# Optional argument (only required for some build functions) -try: - build_version = sys.argv[4] -except IndexError: - build_version = None +jellyfin_version = args.jellyfin_version +build_type = args.build_type +build_arch = args.build_arch +build_version = args.build_version + +if build_type not in ["portable", "docker"] and not build_arch: + log(f"Error: You must specify an architecture for build platform {build_type}") + exit(1) # Autocorrect "master" to a dated version string -if jellyfin_version == "master": +if jellyfin_version in ["auto", "master"]: jellyfin_version = datetime.now().strftime("%Y%m%d%H") log(f"NOTE: Autocorrecting 'master' version to {jellyfin_version}") -if "--no-push" in sys.argv: - no_push = True -else: - no_push = False - # Launch the builder function function_definitions[configurations[build_type]["build_function"]]( - jellyfin_version, build_type, build_arch, build_version, no_push=no_push + jellyfin_version, build_type, build_arch, build_version, no_push=args.no_push ) -- cgit