diff --git a/tclcheck.py b/tclcheck.py index 5092a01..20368fb 100755 --- a/tclcheck.py +++ b/tclcheck.py @@ -12,12 +12,17 @@ fc.cltp = 10 fc.serid = "3531510" #fc.osvs = "7.1.1" +dp = tcllib.DefaultParser(__file__) +dp.add_argument("prd", nargs="?", default="AAM481") +dp.add_argument("fvver", nargs="?", default="PRD-63117-011") +args = dp.parse_args(sys.argv[1:]) + if len(sys.argv) == 3: # python tclcheck.py $PRD $FV = OTA delta for $PRD from $FV - fc.curef = sys.argv[1] - fc.fv = sys.argv[2] + fc.curef = args.prd + fc.fv = args.fvver fc.mode = fc.MODE_OTA elif len(sys.argv) == 2: # python tclcheck.py $PRD = FULL for $PRD - fc.curef = sys.argv[1] + fc.curef = args.prd fc.fv = "AAA000" fc.mode = fc.MODE_FULL fc.cltp = 2010 diff --git a/tclcheck_allota.py b/tclcheck_allota.py index 4b0aa2f..6c712ae 100755 --- a/tclcheck_allota.py +++ b/tclcheck_allota.py @@ -15,11 +15,14 @@ fc.serid = "3531510" fc.mode = fc.MODE_OTA fc.cltp = 10 -force_ver = False -force_ver_text = "" -if len(sys.argv) > 1: - force_ver = sys.argv[1] - force_ver_text = " from {}".format(force_ver) +dp = tcllib.DefaultParser(__file__) +dp.add_argument("forcever", nargs="?", default=None) +args = dp.parse_args(sys.argv[1:]) + +if args.forcever is not None: + force_ver_text = " from {}".format(args.forcever) +else: + force_ver_text = "" print("List of latest OTA firmware{} by PRD:".format(force_ver_text)) @@ -27,8 +30,8 @@ with open("prds.txt", "r") as f: for prdline in f: prdline = prdline.strip() prd, lastver, model = prdline.split(" ", 2) - if force_ver != False: - lastver = force_ver + if args.forcever is not None: + lastver = args.forcever try: fc.reset_session() fc.curef = prd diff --git a/tclcheck_findprd.py b/tclcheck_findprd.py index 104231d..c54e780 100644 --- a/tclcheck_findprd.py +++ b/tclcheck_findprd.py @@ -19,6 +19,10 @@ fc.mode = fc.MODE_FULL #fc.cltp = 10 fc.cltp = 2010 +dp = tcllib.DefaultParser(__file__) +dp.add_argument("tocheck", nargs="?", default=None) +args = dp.parse_args(sys.argv[1:]) + print("Valid PRDs not already in database:") with open("prds.txt", "r") as afile: @@ -30,13 +34,12 @@ with open("prds.txt", "r") as afile: for key, value in prdc.items(): prddict[key].append(value) -if len(sys.argv) > 1: +if args.tocheck is not None: prdkeys = list(prddict.keys()) for k in prdkeys: - if k != sys.argv[1]: + if k != args.tocheck: del prddict[k] - for center in sorted(prddict.keys()): tails = [int(i) for i in prddict[center]] total_count = 1000 - len(tails) diff --git a/tclcheck_findver.py b/tclcheck_findver.py index 3019f82..e33974f 100644 --- a/tclcheck_findver.py +++ b/tclcheck_findver.py @@ -13,18 +13,15 @@ fc = tcllib.FotaCheck() fc.serid = "3531510" fc.mode = fc.MODE_OTA -if len(sys.argv) < 2: - print("Syntax: {} PRD [STARTVER] [ENDVER]".format(sys.argv[0])) - sys.exit() +dp = tcllib.DefaultParser(__file__) +dp.add_argument("prd") +dp.add_argument("startver", nargs="?", default="AAA000") +dp.add_argument("endver", nargs="?", default="AAZ999") +args = dp.parse_args(sys.argv[1:]) -start_ver = "AAA000" -end_ver = "AAZ999" -if len(sys.argv) >= 2: - fc.curef = sys.argv[1] -if len(sys.argv) >= 3: - start_ver = sys.argv[2] -if len(sys.argv) >= 4: - end_ver = sys.argv[3] +fc.curef = args.prd +start_ver = args.startver +end_ver = args.endver print("Valid firmwares for model {} (between {} and {}):".format(fc.curef, start_ver, end_ver)) diff --git a/tcllib.py b/tcllib.py index 9ca8a33..66c547d 100644 --- a/tcllib.py +++ b/tcllib.py @@ -2,6 +2,7 @@ # pylint: disable=C0111,C0326 +import argparse import base64 import binascii import hashlib @@ -35,6 +36,11 @@ def make_escapes_work(): colorama.init() +class DefaultParser(argparse.ArgumentParser): + def __init__(self, appname): + super().__init__(prog=appname.replace(".py", ""), epilog="https://github.com/mbirth/tcl_ota_check") + + class FotaCheck: VDKEY = b"eJwdjwEOwDAIAr8kKFr//7HhmqXp8AIIDrYAgg8byiUXrwRJRXja+d6iNxu0AhUooDCN9rd6rDLxmGIakUVWo3IGCTRWqCAt6X4jGEIUAxgN0eYWnp+LkpHQAg/PsO90ELsy0Npm/n2HbtPndFgGEV31R9OmT4O4nrddjc3Qt6nWscx7e+WRHq5UnOudtjw5skuV09pFhvmqnOEIs4ljPeel1wfLYUF4\n" CKTP_CHECKAUTO = 1