1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-10 06:16:46 +00:00
tcl_ota_check/tcllib/__init__.py

63 lines
1.9 KiB
Python
Raw Normal View History

2018-02-03 20:40:17 +00:00
#!/usr/bin/env python3
2017-09-01 12:43:10 +01:00
# -*- coding: utf-8 -*-
2018-02-03 20:40:17 +00:00
# pylint: disable=C0111,C0326,C0103
2017-09-01 12:43:10 +01:00
2018-02-03 21:25:26 +00:00
"""Library for TCL API work and related functions."""
2017-10-15 00:51:38 +01:00
import enum
2018-02-03 20:24:36 +00:00
2017-09-01 12:43:10 +01:00
import requests
2018-02-03 20:24:36 +00:00
2018-02-06 00:03:25 +00:00
from . import (dumpmgr, servervote, tclcheck, tclchecksum, tclencheader,
tclrequest)
2018-02-03 20:24:36 +00:00
def default_enum(enumname, vardict, qualroot="tcllib.FotaCheck"):
2018-02-03 21:25:26 +00:00
"""Enum with defaults set."""
2018-02-03 20:24:36 +00:00
return enum.IntEnum(enumname, vardict, module=__name__, qualname="{}.{}".format(qualroot, enumname))
2017-10-15 00:51:38 +01:00
class FotaCheck(
2018-02-03 21:25:26 +00:00
tclcheck.TclCheckMixin,
tclrequest.TclRequestMixin,
tclchecksum.TclChecksumMixin,
tclencheader.TclEncHeaderMixin,
servervote.ServerVoteMixin,
dumpmgr.DumpMgrMixin
2018-02-03 20:24:36 +00:00
):
2018-02-03 21:25:26 +00:00
"""Main API handler class."""
2017-10-15 00:51:38 +01:00
CKTP = default_enum("CKTP", ["AUTO", "MANUAL"])
MODE = default_enum("MODE", {"OTA": 2, "FULL": 4})
RTD = default_enum("RTD", ["UNROOTED", "ROOTED"])
CHNL = default_enum("CHNL", ["3G", "WIFI"])
CLTP = default_enum("CLTP", {"MOBILE": 10, "DESKTOP": 2010})
CKOT = default_enum("CKOT", ["ALL", "AOTA_ONLY", "FOTA_ONLY"])
2017-09-01 12:43:10 +01:00
def __init__(self):
2018-02-03 21:25:26 +00:00
"""Handle mixins and populate variables."""
2018-02-03 01:37:55 +00:00
super().__init__()
2017-09-01 12:43:10 +01:00
self.serid = "543212345000000"
self.curef = "PRD-63117-011"
2018-02-03 20:24:36 +00:00
self.fv = "AAM481"
self.osvs = "7.1.1"
self.mode = self.MODE.FULL
2017-09-01 12:43:10 +01:00
self.ftype = "Firmware"
2018-02-03 20:24:36 +00:00
self.cltp = self.CLTP.MOBILE
self.cktp = self.CKTP.MANUAL
self.ckot = self.CKOT.ALL
self.rtd = self.RTD.UNROOTED
self.chnl = self.CHNL.WIFI
self.reset_session()
def reset_session(self):
2018-02-03 21:25:26 +00:00
"""Reset everything to default."""
2017-09-01 12:43:10 +01:00
self.g2master = self.get_master_server()
self.sess = requests.Session()
2017-10-15 00:51:38 +01:00
if self.mode == self.MODE.FULL:
self.sess.headers.update({"User-Agent": "com.tcl.fota/5.1.0.2.0029.0, Android"})
else:
self.sess.headers.update({"User-Agent": "tcl"})
return self.sess