1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-09-19 22:33:25 +01:00

Start modularising tcllib.

This commit is contained in:
Markus Birth 2018-02-02 03:33:53 +01:00
parent f9398e6b5f
commit 4456f76032
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
11 changed files with 39 additions and 26 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/__pycache__/
__pycache__/
/logs/
/headers/
/.nvimlog

View File

@ -7,6 +7,7 @@ import os
import random
import sys
import tcllib
import tcllib.argparser
fc = tcllib.FotaCheck()
fc.serid = "3531510"
@ -16,7 +17,7 @@ dpdesc = """
Checks for the latest FULL updates for the specified PRD number or for an OTA from the
version specified as fvver.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011")
dp.add_argument("fvver", nargs="?", help="Firmware version to check for OTA updates, e.g. AAM481 (omit to run FULL check)", default="AAA000")
dp.add_argument("-i", "--imei", help="use specified IMEI instead of default", type=str)

View File

@ -5,6 +5,7 @@
import sys
import tcllib
import tcllib.argparser
from requests.exceptions import RequestException, Timeout
tcllib.make_escapes_work()
@ -18,7 +19,7 @@ dpdesc = """
Checks for the latest FULL updates for all PRD numbers or only for
the PRD specified as prd.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("-p", "--prd", help="CU Reference # to filter scan results", dest="tocheck", nargs="?", default=None, metavar="PRD")
args = dp.parse_args(sys.argv[1:])

View File

@ -7,6 +7,7 @@ import json
import requests
import sys
import tcllib
import tcllib.argparser
from requests.exceptions import RequestException
tcllib.make_escapes_work()
@ -21,7 +22,7 @@ dpdesc = """
Checks for the latest OTA updates for all PRD numbers or only for the PRD specified
as prd. Initial software version can be specified with forcever.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("forcever", help="Initial software version to check for OTA updates, e.g. AAM481", nargs="?", default=None)
dp.add_argument("-p", "--prd", help="CU Reference # to filter scan results", dest="tocheck", nargs="?", default=None, metavar="PRD")
args = dp.parse_args(sys.argv[1:])

View File

@ -6,6 +6,7 @@
import collections
import sys
import tcllib
import tcllib.argparser
from requests.exceptions import RequestException, Timeout
tcllib.make_escapes_work()
@ -23,7 +24,7 @@ dpdesc = """
Finds new PRD numbers for all known variants, or specified variants with tocheck. Scan range
can be set by floor and ceiling switches.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("tocheck", help="CU Reference # to filter scan results", nargs="?", default=None)
dp.add_argument("-f", "--floor", help="Beginning of scan range", dest="floor", nargs="?", type=int, default=0)
dp.add_argument("-c", "--ceiling", help="End of scan range", dest="ceiling", nargs="?", type=int, default=999)

View File

@ -6,6 +6,7 @@
import collections
import sys
import tcllib
import tcllib.argparser
from requests.exceptions import RequestException, Timeout
# Variants to scan for
@ -26,7 +27,7 @@ dpdesc = """
Finds new PRD numbers for a range of variants. Scan range can be set by
floor and ceiling switches.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("floor", nargs="?", help="Model number to start with", type=int, default=63116)
dp.add_argument("ceiling", nargs="?", help="Model number to end with", type=int, default=99999)
args = dp.parse_args(sys.argv[1:])

View File

@ -5,6 +5,7 @@
import sys
import tcllib
import tcllib.argparser
from requests.exceptions import RequestException, Timeout
tcllib.make_escapes_work()
@ -17,7 +18,7 @@ dpdesc = """
Finds all valid OTA updates for a given PRD. Scan range can be set by
startver and endver switches.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("prd", help="CU Reference #, e.g. PRD-63117-011")
dp.add_argument("startver", help="Beginning of scan range", nargs="?", default="AAA000")
dp.add_argument("endver", help="End of scan range", nargs="?", default="AAZ999")

View File

@ -7,6 +7,7 @@ import os
import random
import sys
import tcllib
import tcllib.argparser
fc = tcllib.FotaCheck()
@ -25,7 +26,7 @@ encslaves = [
dpdesc = """
Returns the checksum for a given firmware URI.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("uri", help="URI to firmware, starts with '/body/...'")
args = dp.parse_args(sys.argv[1:])

View File

@ -7,6 +7,7 @@ import os
import random
import sys
import tcllib
import tcllib.argparser
fc = tcllib.FotaCheck()
fc.serid = "3531510"
@ -15,7 +16,7 @@ fc.serid = "3531510"
dpdesc = """
Downloads the given firmware file.
"""
dp = tcllib.DefaultParser(__file__, dpdesc)
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011")
dp.add_argument("targetversion", nargs=1, help="Firmware version to download, e.g. AAN990")
dp.add_argument("fwid", nargs=1, help="Numeric firmware file id, e.g. 268932")

View File

@ -2,7 +2,6 @@
# pylint: disable=C0111,C0326
import argparse
import base64
import binascii
import enum
@ -14,7 +13,6 @@ import os
import platform
import random
import time
import webbrowser
import xml.dom.minidom
import zlib
from collections import OrderedDict
@ -56,21 +54,6 @@ def make_escapes_work():
def default_enum(enumname, vardict):
return enum.IntEnum(enumname, vardict, module=__name__, qualname="tcllib.FotaCheck.{}".format(enumname))
class DefaultParser(argparse.ArgumentParser):
def __init__(self, appname, desc=None):
super().__init__(prog=appname, description=desc, epilog="https://github.com/mbirth/tcl_ota_check")
self.add_argument("--webdb", help="open web database in browser and exit", action="store_true")
def parse_args(self, args=None, namespace=None):
if set(args) & {"--webdb"}: # if they intersect
webbrowser.open("https://tclota.birth-online.de/", new=2)
raise SystemExit
else:
argx = super().parse_args(args, namespace)
return argx
class FotaCheck:
VDKEY = b"eJwdjwEOwDAIAr8kKFr//7HhmqXp8AIIDrYAgg8byiUXrwRJRXja+d6iNxu0AhUooDCN9rd6rDLxmGIakUVWo3IGCTRWqCAt6X4jGEIUAxgN0eYWnp+LkpHQAg/PsO90ELsy0Npm/n2HbtPndFgGEV31R9OmT4O4nrddjc3Qt6nWscx7e+WRHq5UnOudtjw5skuV09pFhvmqnOEIs4ljPeel1wfLYUF4\n"
CKTP = default_enum("CKTP", ["AUTO", "MANUAL"])
@ -433,6 +416,9 @@ class FotaCheck:
req.encoding = "utf-8" # Force encoding as server doesn't give one
self.write_dump(req.text)
# <ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER> means ERROR (invalid ADDRESS!)
if "<ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER>" in req.text:
print("INVALID URI: {}".format(uri))
raise SystemExit
return req.text
else:
print("CHECKSUM: " + repr(req))

19
tcllib/argparser.py Normal file
View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# pylint: disable=C0111,C0326
import argparse
import webbrowser
class DefaultParser(argparse.ArgumentParser):
def __init__(self, appname, desc=None):
super().__init__(prog=appname, description=desc, epilog="https://github.com/mbirth/tcl_ota_check")
self.add_argument("--webdb", help="open web database in browser and exit", action="store_true")
def parse_args(self, args=None, namespace=None):
if set(args) & {"--webdb"}: # if they intersect
webbrowser.open("https://tclota.birth-online.de/", new=2)
raise SystemExit
else:
argx = super().parse_args(args, namespace)
return argx