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

Moved device-specific settings to own class. Only used in

tclcheck_allfull for now.
This commit is contained in:
Markus Birth 2018-02-06 00:22:24 +01:00
parent ba99c104d0
commit 808282c347
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
4 changed files with 104 additions and 22 deletions

View File

@ -13,12 +13,13 @@ import tcllib
import tcllib.argparser
from tcllib import ansi
from tcllib import devlist
from tcllib.devices import DesktopDevice
dev = DesktopDevice()
fc = tcllib.FotaCheck()
fc.serid = "3531510"
fc.fv = "AAA000"
fc.mode = fc.MODE.FULL
fc.mode = fc.MODE.FULL # still needed to set User-Agent
dpdesc = """
Checks for the latest FULL updates for all PRD numbers or only for
@ -28,10 +29,6 @@ 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:])
# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE.FULL)
#fc.cltp = fc.CLTP.MOBILE
fc.cltp = fc.CLTP.DESKTOP
prdcheck = "" if args.tocheck is None else args.tocheck
print("Loading list of devices.")
@ -45,8 +42,8 @@ for prd, variant in prds.items():
if prdcheck in prd:
try:
fc.reset_session()
fc.curef = prd
check_xml = fc.do_check(max_tries=20)
dev.curef = prd
check_xml = fc.do_check(dev, max_tries=20)
curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml)
txt_tv = tv
if tv != lastver:

View File

@ -10,7 +10,7 @@ import enum
import requests
from . import (dumpmgr, servervote, tclcheck,
tclchecksum, tclencheader, tclrequest, xmltools)
tclchecksum, tclencheader, tclrequest)
def default_enum(enumname, vardict, qualroot="tcllib.FotaCheck"):

71
tcllib/devices.py Normal file
View File

@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
"""Pseudo-devices for desktop/mobile requests"""
class Device():
CLTP_STATES = {
"MOBILE": 10, # only show actual newer versions or HTTP 206
"DESKTOP": 2010, # always show latest version for FULL updates
}
MODE_STATES = {"OTA": 2, "FULL": 4}
CHNL_STATES = {"3G": 1, "WIFI": 2}
CKTP_STATES = {"AUTO": 1, "MANUAL": 2}
CKOT_STATES = {"ALL": 1, "AOTA_ONLY": 2, "FOTA_ONLY": 3}
def __init__(self, curef, fwver):
self.curef = curef
self.imei = ""
self.osver = "7.1.1"
self.fwver = fwver
self.rtd = 0
self.cltp = self.CLTP_STATES["DESKTOP"]
self.mode = self.MODE_STATES["FULL"]
self.type = "Firmware"
self.chnl = self.CHNL_STATES["WIFI"]
self.cktp = self.CKTP_STATES["MANUAL"]
self.ckot = self.CKOT_STATES["ALL"]
self.ua = "tcl"
def is_rooted(self):
return (self.rtd == 1)
def set_rooted(self, new_state: bool):
if new_state:
self.rtd = 1
else:
self.rtd = 0
def set_cltp(self, new_cltp: str):
# (Numerical CLTPs can be set by direct assigns.)
# Throws exception when invalid cltp given:
self.cltp = self.CLTP_STATES[new_cltp]
def set_mode(self, new_mode: str):
# (Numerical MODEs can be set by direct assigns.)
# Throws exception when invalid mode given:
self.mode = self.MODE_STATES[new_mode]
def set_chnl(self, new_chnl: str):
# (Numerical CHNLs can be set by direct assigns.)
# Throws exception when invalid mode given:
self.chnl = self.CHNL_STATES[new_chnl]
def set_ckot(self, new_ckot: str):
# (Numerical CKOTs can be set by direct assigns.)
# Throws exception when invalid mode given:
self.ckot = self.CKOT_STATES[new_ckot]
class MobileDevice(Device):
def __init__(self, curef="PRD-63117-011", fwver="AAO472"):
super().__init__(curef, fwver)
self.imei = "3531510"
self.set_cltp("MOBILE")
self.set_mode("OTA")
self.ua = "com.tcl.fota/5.1.0.2.0029.0, Android"
class DesktopDevice(Device):
def __init__(self, curef="PRD-63117-011", fwver="AAA000"):
super().__init__(curef, fwver)
self.imei = "543212345000000"
self.set_cltp("DESKTOP")
self.set_mode("FULL")

View File

@ -14,22 +14,36 @@ from defusedxml import ElementTree
class TclCheckMixin:
"""A mixin component for TCL's update request API."""
def do_check(self, https=True, timeout=10, max_tries=5):
def do_check(self, device=None, https=True, timeout=10, max_tries=5):
"""Perform update request with given parameters."""
protocol = "https://" if https else "http://"
url = protocol + self.g2master + "/check.php"
params = OrderedDict()
params["id"] = self.serid
params["curef"] = self.curef
params["fv"] = self.fv
params["mode"] = self.mode.value
params["type"] = self.ftype
params["cltp"] = self.cltp.value
params["cktp"] = self.cktp.value
params["rtd"] = self.rtd.value
params["chnl"] = self.chnl.value
#params["osvs"] = self.osvs
#params["ckot"] = self.ckot.value
if device:
# Need to support both ways for now
params["id"] = device.imei
params["curef"] = device.curef
params["fv"] = device.fwver
params["mode"] = device.mode
params["type"] = device.type
params["cltp"] = device.cltp
params["cktp"] = device.cktp
params["rtd"] = device.rtd
params["chnl"] = device.chnl
#params["osvs"] = device.osvs
#params["ckot"] = device.ckot
else:
params["id"] = self.serid
params["curef"] = self.curef
params["fv"] = self.fv
params["mode"] = self.mode.value
params["type"] = self.ftype
params["cltp"] = self.cltp.value
params["cktp"] = self.cktp.value
params["rtd"] = self.rtd.value
params["chnl"] = self.chnl.value
#params["osvs"] = self.osvs
#params["ckot"] = self.ckot.value
last_response = None
for _ in range(0, max_tries):