mirror of
https://github.com/mbirth/tcl_ota_check.git
synced 2024-11-12 23:36:46 +00:00
replace numeric constants with enums
This commit is contained in:
parent
086240ffa2
commit
69315d8fe2
10
tclcheck.py
10
tclcheck.py
@ -8,7 +8,7 @@ import sys
|
|||||||
import tcllib
|
import tcllib
|
||||||
|
|
||||||
fc = tcllib.FotaCheck()
|
fc = tcllib.FotaCheck()
|
||||||
fc.cltp = 10
|
fc.cltp = fc.CLTP.MOBILE
|
||||||
fc.serid = "3531510"
|
fc.serid = "3531510"
|
||||||
#fc.osvs = "7.1.1"
|
#fc.osvs = "7.1.1"
|
||||||
|
|
||||||
@ -20,16 +20,16 @@ args = dp.parse_args(sys.argv[1:])
|
|||||||
if len(sys.argv) == 3: # python tclcheck.py $PRD $FV = OTA delta for $PRD from $FV
|
if len(sys.argv) == 3: # python tclcheck.py $PRD $FV = OTA delta for $PRD from $FV
|
||||||
fc.curef = args.prd
|
fc.curef = args.prd
|
||||||
fc.fv = args.fvver
|
fc.fv = args.fvver
|
||||||
fc.mode = fc.MODE_OTA
|
fc.mode = fc.MODE.OTA
|
||||||
elif len(sys.argv) == 2: # python tclcheck.py $PRD = FULL for $PRD
|
elif len(sys.argv) == 2: # python tclcheck.py $PRD = FULL for $PRD
|
||||||
fc.curef = args.prd
|
fc.curef = args.prd
|
||||||
fc.fv = "AAA000"
|
fc.fv = "AAA000"
|
||||||
fc.mode = fc.MODE_FULL
|
fc.mode = fc.MODE.FULL
|
||||||
fc.cltp = 2010
|
fc.cltp = fc.CLTP.DESKTOP
|
||||||
else: # python tclcheck.py = OTA for default PRD, FV
|
else: # python tclcheck.py = OTA for default PRD, FV
|
||||||
fc.curef = "PRD-63117-011"
|
fc.curef = "PRD-63117-011"
|
||||||
fc.fv = "AAM481"
|
fc.fv = "AAM481"
|
||||||
fc.mode = fc.MODE_OTA
|
fc.mode = fc.MODE.OTA
|
||||||
|
|
||||||
check_xml = fc.do_check()
|
check_xml = fc.do_check()
|
||||||
print(fc.pretty_xml(check_xml))
|
print(fc.pretty_xml(check_xml))
|
||||||
|
@ -11,11 +11,11 @@ tcllib.make_escapes_work()
|
|||||||
fc = tcllib.FotaCheck()
|
fc = tcllib.FotaCheck()
|
||||||
fc.serid = "3531510"
|
fc.serid = "3531510"
|
||||||
fc.fv = "AAA000"
|
fc.fv = "AAA000"
|
||||||
fc.mode = fc.MODE_FULL
|
fc.mode = fc.MODE.FULL
|
||||||
|
|
||||||
# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE_FULL)
|
# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE.FULL)
|
||||||
#fc.cltp = 10
|
#fc.cltp = fc.CLTP.MOBILE
|
||||||
fc.cltp = 2010
|
fc.cltp = fc.CLTP.DESKTOP
|
||||||
|
|
||||||
print("List of latest FULL firmware by PRD:")
|
print("List of latest FULL firmware by PRD:")
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ tcllib.make_escapes_work()
|
|||||||
fc = tcllib.FotaCheck()
|
fc = tcllib.FotaCheck()
|
||||||
fc.serid = "3531510"
|
fc.serid = "3531510"
|
||||||
#fc.osvs = "7.1.1"
|
#fc.osvs = "7.1.1"
|
||||||
fc.mode = fc.MODE_OTA
|
fc.mode = fc.MODE.OTA
|
||||||
fc.cltp = 10
|
fc.cltp = fc.CLTP.MOBILE
|
||||||
|
|
||||||
dp = tcllib.DefaultParser(__file__)
|
dp = tcllib.DefaultParser(__file__)
|
||||||
dp.add_argument("forcever", nargs="?", default=None)
|
dp.add_argument("forcever", nargs="?", default=None)
|
||||||
|
@ -13,11 +13,11 @@ tcllib.make_escapes_work()
|
|||||||
fc = tcllib.FotaCheck()
|
fc = tcllib.FotaCheck()
|
||||||
fc.serid = "3531510"
|
fc.serid = "3531510"
|
||||||
fc.fv = "AAA000"
|
fc.fv = "AAA000"
|
||||||
fc.mode = fc.MODE_FULL
|
fc.mode = fc.MODE.FULL
|
||||||
|
|
||||||
# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE_FULL)
|
# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE.FULL)
|
||||||
#fc.cltp = 10
|
#fc.cltp = fc.CLTP.MOBILE
|
||||||
fc.cltp = 2010
|
fc.cltp = fc.CLTP.DESKTOP
|
||||||
|
|
||||||
dp = tcllib.DefaultParser(__file__)
|
dp = tcllib.DefaultParser(__file__)
|
||||||
dp.add_argument("tocheck", nargs="?", default=None)
|
dp.add_argument("tocheck", nargs="?", default=None)
|
||||||
|
@ -11,7 +11,7 @@ tcllib.make_escapes_work()
|
|||||||
|
|
||||||
fc = tcllib.FotaCheck()
|
fc = tcllib.FotaCheck()
|
||||||
fc.serid = "3531510"
|
fc.serid = "3531510"
|
||||||
fc.mode = fc.MODE_OTA
|
fc.mode = fc.MODE.OTA
|
||||||
|
|
||||||
dp = tcllib.DefaultParser(__file__)
|
dp = tcllib.DefaultParser(__file__)
|
||||||
dp.add_argument("prd")
|
dp.add_argument("prd")
|
||||||
|
32
tcllib.py
32
tcllib.py
@ -5,6 +5,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
|
import enum
|
||||||
import hashlib
|
import hashlib
|
||||||
import platform
|
import platform
|
||||||
import random
|
import random
|
||||||
@ -36,6 +37,10 @@ def make_escapes_work():
|
|||||||
colorama.init()
|
colorama.init()
|
||||||
|
|
||||||
|
|
||||||
|
def default_enum(enumname, vardict):
|
||||||
|
return enum.IntEnum(enumname, vardict, module=__name__, qualname="tcllib.FotaCheck.{}".format(enumname))
|
||||||
|
|
||||||
|
|
||||||
class DefaultParser(argparse.ArgumentParser):
|
class DefaultParser(argparse.ArgumentParser):
|
||||||
def __init__(self, appname):
|
def __init__(self, appname):
|
||||||
super().__init__(prog=appname.replace(".py", ""), epilog="https://github.com/mbirth/tcl_ota_check")
|
super().__init__(prog=appname.replace(".py", ""), epilog="https://github.com/mbirth/tcl_ota_check")
|
||||||
@ -43,26 +48,23 @@ class DefaultParser(argparse.ArgumentParser):
|
|||||||
|
|
||||||
class FotaCheck:
|
class FotaCheck:
|
||||||
VDKEY = b"eJwdjwEOwDAIAr8kKFr//7HhmqXp8AIIDrYAgg8byiUXrwRJRXja+d6iNxu0AhUooDCN9rd6rDLxmGIakUVWo3IGCTRWqCAt6X4jGEIUAxgN0eYWnp+LkpHQAg/PsO90ELsy0Npm/n2HbtPndFgGEV31R9OmT4O4nrddjc3Qt6nWscx7e+WRHq5UnOudtjw5skuV09pFhvmqnOEIs4ljPeel1wfLYUF4\n"
|
VDKEY = b"eJwdjwEOwDAIAr8kKFr//7HhmqXp8AIIDrYAgg8byiUXrwRJRXja+d6iNxu0AhUooDCN9rd6rDLxmGIakUVWo3IGCTRWqCAt6X4jGEIUAxgN0eYWnp+LkpHQAg/PsO90ELsy0Npm/n2HbtPndFgGEV31R9OmT4O4nrddjc3Qt6nWscx7e+WRHq5UnOudtjw5skuV09pFhvmqnOEIs4ljPeel1wfLYUF4\n"
|
||||||
CKTP_CHECKAUTO = 1
|
CKTP = default_enum("CKTP", ["AUTO", "MANUAL"])
|
||||||
CKTP_CHECKMANUAL = 2
|
MODE = default_enum("MODE", {"OTA": 2, "FULL": 4})
|
||||||
MODE_OTA = 2
|
RTD = default_enum("RTD", ["UNROOTED", "ROOTED"])
|
||||||
MODE_FULL = 4
|
CHNL = default_enum("CHNL", ["3G", "WIFI"])
|
||||||
RTD_ROOTED = 2
|
CLTP = default_enum("CLTP", {"MOBILE": 10, "DESKTOP": 2010})
|
||||||
RTD_UNROOTED = 1
|
|
||||||
CHNL_WIFI = 2
|
|
||||||
CHNL_3G = 1
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.serid = "543212345000000"
|
self.serid = "543212345000000"
|
||||||
self.curef = "PRD-63117-011"
|
self.curef = "PRD-63117-011"
|
||||||
self.fv = "AAM481"
|
self.fv = "AAM481"
|
||||||
self.osvs = "7.1.1"
|
self.osvs = "7.1.1"
|
||||||
self.mode = self.MODE_FULL
|
self.mode = self.MODE.FULL
|
||||||
self.ftype = "Firmware"
|
self.ftype = "Firmware"
|
||||||
self.cltp = 10
|
self.cltp = self.CLTP.MOBILE
|
||||||
self.cktp = self.CKTP_CHECKMANUAL
|
self.cktp = self.CKTP.MANUAL
|
||||||
self.rtd = self.RTD_UNROOTED
|
self.rtd = self.RTD.UNROOTED
|
||||||
self.chnl = self.CHNL_WIFI
|
self.chnl = self.CHNL.WIFI
|
||||||
self.g2master = None
|
self.g2master = None
|
||||||
self.master_servers = [
|
self.master_servers = [
|
||||||
"g2master-us-east.tclclouds.com",
|
"g2master-us-east.tclclouds.com",
|
||||||
@ -80,7 +82,7 @@ class FotaCheck:
|
|||||||
def reset_session(self):
|
def reset_session(self):
|
||||||
self.g2master = self.get_master_server()
|
self.g2master = self.get_master_server()
|
||||||
self.sess = requests.Session()
|
self.sess = requests.Session()
|
||||||
if self.mode == self.MODE_FULL:
|
if self.mode == self.MODE.FULL:
|
||||||
self.sess.headers.update({"User-Agent": "com.tcl.fota/5.1.0.2.0029.0, Android"})
|
self.sess.headers.update({"User-Agent": "com.tcl.fota/5.1.0.2.0029.0, Android"})
|
||||||
else:
|
else:
|
||||||
self.sess.headers.update({"User-Agent": "tcl"})
|
self.sess.headers.update({"User-Agent": "tcl"})
|
||||||
@ -249,7 +251,7 @@ class FotaCheck:
|
|||||||
params["cltp"] = self.cltp
|
params["cltp"] = self.cltp
|
||||||
params["cktp"] = self.cktp
|
params["cktp"] = self.cktp
|
||||||
params["rtd"] = self.rtd
|
params["rtd"] = self.rtd
|
||||||
if self.mode == self.MODE_FULL:
|
if self.mode == self.MODE.FULL:
|
||||||
params["foot"] = 1
|
params["foot"] = 1
|
||||||
params["chnl"] = self.chnl
|
params["chnl"] = self.chnl
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user