From 3b7703a565e840fb89af0d9d3263b2df8719a0f5 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 9 Jun 2025 09:58:01 +0200 Subject: [PATCH] add script args parser --- bin/streaming/telecaster.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bin/streaming/telecaster.py b/bin/streaming/telecaster.py index ad1f15b..538efa3 100755 --- a/bin/streaming/telecaster.py +++ b/bin/streaming/telecaster.py @@ -6,6 +6,7 @@ import subprocess import sys import yaml import time +import argparse from threading import Thread from copy import deepcopy @@ -116,11 +117,11 @@ class TeleCasterCommand: class TeleCaster(Thread): - def __init__(self, conf_file_path, verbose, dry_run): + def __init__(self, args): Thread.__init__(self) - conf_file = open(conf_file_path, 'r') - self.verbose = verbose - self.dry_run = dry_run + conf_file = open(args["config"], 'r') + self.verbose = args["verbose"] + self.dry_run = args["dry_run"] self.conf = yaml.safe_load(conf_file)["telecaster"] self.stream_types = ["audio", "video"] self.deefuzzer_video_conf_file = "/tmp/telecaster_deefuzzer_webm_monitor.yml" @@ -273,18 +274,17 @@ class TeleCaster(Thread): def main(): - verbose = False - dry_run = False - - if len(sys.argv) >= 2: - tc = TeleCaster(sys.argv[-1], verbose, dry_run) - tc.start() - elif os.path.exists(DEFAULT_CONFIG_FILE): - tc = TeleCaster(DEFAULT_CONFIG_FILE, verbose, dry_run) - tc.start() - else: - sys.exit() - + description ="""Start a TeleCaster streaming server""" + parser = argparse.ArgumentParser(description=description) + parser.add_argument("--config", help="config file", type=str) + parser.add_argument("--verbose", help="verbose", action="store_true") + parser.add_argument("--dry-run", help="dry run", action="store_true") + args = vars(parser.parse_args()) + if os.path.exists(DEFAULT_CONFIG_FILE) and not args["config"]: + args['config'] = DEFAULT_CONFIG_FILE + print(args) + tc = TeleCaster(args) + tc.start() if __name__ == '__main__': main() -- 2.39.5