1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-14 00:06:46 +00:00

pylint, autopep8, isort runthroughs

This commit is contained in:
thurask 2018-02-03 15:24:36 -05:00
parent 42566d1195
commit da3663486a
No known key found for this signature in database
GPG Key ID: A6CCCDEA29795048
22 changed files with 148 additions and 107 deletions

View File

@ -6,9 +6,11 @@
import os import os
import random import random
import sys import sys
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"
#fc.osvs = "7.1.1" #fc.osvs = "7.1.1"
@ -21,12 +23,13 @@ dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011") 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("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) dp.add_argument("-i", "--imei", help="use specified IMEI instead of default", type=str)
dp.add_argument("-m", "--mode", help="force type of update to check for", default="auto", type=str ,choices=["full", "ota"]) dp.add_argument("-m", "--mode", help="force type of update to check for", default="auto", type=str, choices=["full", "ota"])
dp.add_argument("-t", "--type", help="force type of check to run", default="auto", type=str, choices=["desktop", "mobile"]) dp.add_argument("-t", "--type", help="force type of check to run", default="auto", type=str, choices=["desktop", "mobile"])
dp.add_argument("--rawmode", help="override --mode with raw value (2=OTA, 4=FULL)", metavar="MODE") dp.add_argument("--rawmode", help="override --mode with raw value (2=OTA, 4=FULL)", metavar="MODE")
dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)", metavar="CLTP") dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)", metavar="CLTP")
args = dp.parse_args(sys.argv[1:]) args = dp.parse_args(sys.argv[1:])
def sel_mode(txtmode, autoval, rawval): def sel_mode(txtmode, autoval, rawval):
if rawval: if rawval:
enum = tcllib.default_enum("MODE", {"RAW": rawval}) enum = tcllib.default_enum("MODE", {"RAW": rawval})
@ -37,6 +40,7 @@ def sel_mode(txtmode, autoval, rawval):
return fc.MODE.OTA return fc.MODE.OTA
return fc.MODE.FULL return fc.MODE.FULL
def sel_cltp(txtmode, autoval, rawval): def sel_cltp(txtmode, autoval, rawval):
if rawval: if rawval:
enum = tcllib.default_enum("CLTP", {"RAW": rawval}) enum = tcllib.default_enum("CLTP", {"RAW": rawval})
@ -47,6 +51,7 @@ def sel_cltp(txtmode, autoval, rawval):
return fc.CLTP.DESKTOP return fc.CLTP.DESKTOP
return fc.CLTP.MOBILE return fc.CLTP.MOBILE
if args.imei: if args.imei:
print("Use specified IMEI: {}".format(args.imei)) print("Use specified IMEI: {}".format(args.imei))
fc.serid = args.imei fc.serid = args.imei
@ -71,7 +76,7 @@ req_xml = fc.do_request(curef, fv, tv, fw_id)
print(fc.pretty_xml(req_xml)) print(fc.pretty_xml(req_xml))
fileid, fileurl, slaves, encslaves, s3_fileurl, s3_slaves = fc.parse_request(req_xml) fileid, fileurl, slaves, encslaves, s3_fileurl, s3_slaves = fc.parse_request(req_xml)
if len(encslaves) > 0: if encslaves:
chksum_xml = fc.do_checksum(random.choice(encslaves), fileurl, fileurl) chksum_xml = fc.do_checksum(random.choice(encslaves), fileurl, fileurl)
print(fc.pretty_xml(chksum_xml)) print(fc.pretty_xml(chksum_xml))
file_addr, sha1_body, sha1_enc_footer, sha1_footer = fc.parse_checksum(chksum_xml) file_addr, sha1_body, sha1_enc_footer, sha1_footer = fc.parse_checksum(chksum_xml)

View File

@ -4,10 +4,13 @@
# pylint: disable=C0111,C0326,C0103 # pylint: disable=C0111,C0326,C0103
import sys import sys
from requests.exceptions import RequestException
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
from tcllib import ansi from tcllib import ansi
from requests.exceptions import RequestException, Timeout
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"

View File

@ -3,13 +3,14 @@
# pylint: disable=C0111,C0326,C0103 # pylint: disable=C0111,C0326,C0103
import json
import requests
import sys import sys
from requests.exceptions import RequestException
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
from tcllib import ansi from tcllib import ansi
from requests.exceptions import RequestException
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"
@ -41,7 +42,7 @@ print("List of latest OTA firmware{} by PRD:".format(force_ver_text))
for prd, variant in prds.items(): for prd, variant in prds.items():
model = variant["variant"] model = variant["variant"]
lastver = variant["last_ota"] lastver = variant["last_ota"]
if lastver is None: lastver = variant["last_full"] lastver = variant["last_full"] if lastver is None else lastver
if args.forcever is not None: if args.forcever is not None:
lastver = args.forcever lastver = args.forcever
if prdcheck in prd: if prdcheck in prd:

View File

@ -5,10 +5,13 @@
import collections import collections
import sys import sys
from requests.exceptions import RequestException, Timeout
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
from tcllib import ansi from tcllib import ansi
from requests.exceptions import RequestException, Timeout
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"

View File

@ -3,12 +3,14 @@
# pylint: disable=C0111,C0326,C0103 # pylint: disable=C0111,C0326,C0103
import collections
import sys import sys
from requests.exceptions import RequestException, Timeout
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
from tcllib import ansi from tcllib import ansi
from requests.exceptions import RequestException, Timeout
# Variants to scan for # Variants to scan for
SCAN_VARIANTS = ["001", "003", "009", "010", "700"] SCAN_VARIANTS = ["001", "003", "009", "010", "700"]

View File

@ -4,10 +4,13 @@
# pylint: disable=C0111,C0326,C0103 # pylint: disable=C0111,C0326,C0103
import sys import sys
from requests.exceptions import RequestException, Timeout
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
from tcllib import ansi from tcllib import ansi
from requests.exceptions import RequestException, Timeout
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"

View File

@ -4,11 +4,13 @@
# pylint: disable=C0111,C0326,C0103 # pylint: disable=C0111,C0326,C0103
import json import json
import requests import requests
import sys
import tcllib
from requests.exceptions import RequestException from requests.exceptions import RequestException
import tcllib
# 1. Fetch list of missing OTAs (e.g. from ancient versions to current) # 1. Fetch list of missing OTAs (e.g. from ancient versions to current)
# 2. Query updates from FOTA servers (and store XML) # 2. Query updates from FOTA servers (and store XML)
# (3. Upload will be done manually with upload_logs.py) # (3. Upload will be done manually with upload_logs.py)

View File

@ -3,12 +3,13 @@
# pylint: disable=C0111,C0326,C0103 # pylint: disable=C0111,C0326,C0103
import os
import random import random
import sys import sys
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
encslaves = [ encslaves = [

View File

@ -6,9 +6,11 @@
import os import os
import random import random
import sys import sys
import tcllib import tcllib
import tcllib.argparser import tcllib.argparser
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"
#fc.osvs = "7.1.1" #fc.osvs = "7.1.1"
@ -27,12 +29,14 @@ dp.add_argument("--rawmode", help="override --mode with raw value (2=OTA, 4=FULL
dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)", metavar="CLTP") dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)", metavar="CLTP")
args = dp.parse_args(sys.argv[1:]) args = dp.parse_args(sys.argv[1:])
def sel_mode(defaultmode, rawval): def sel_mode(defaultmode, rawval):
if rawval: if rawval:
enum = tcllib.default_enum("MODE", {"RAW": rawval}) enum = tcllib.default_enum("MODE", {"RAW": rawval})
return enum.RAW return enum.RAW
return defaultmode return defaultmode
def sel_cltp(txtmode, rawval): def sel_cltp(txtmode, rawval):
if rawval: if rawval:
enum = tcllib.default_enum("CLTP", {"RAW": rawval}) enum = tcllib.default_enum("CLTP", {"RAW": rawval})
@ -41,6 +45,7 @@ def sel_cltp(txtmode, rawval):
return fc.CLTP.MOBILE return fc.CLTP.MOBILE
return fc.CLTP.DESKTOP return fc.CLTP.DESKTOP
if args.imei: if args.imei:
print("Use specified IMEI: {}".format(args.imei)) print("Use specified IMEI: {}".format(args.imei))
fc.serid = args.imei fc.serid = args.imei

View File

@ -3,19 +3,16 @@
# pylint: disable=C0111,C0326 # pylint: disable=C0111,C0326
import enum import enum
import requests
from . import credentials
from . import devlist
from . import dumpmgr
from . import servervote
from . import tclcheck
from . import tclrequest
from . import tclchecksum
from . import tclencheader
from . import xmltools
def default_enum(enumname, vardict): import requests
return enum.IntEnum(enumname, vardict, module=__name__, qualname="tcllib.FotaCheck.{}".format(enumname))
from . import (credentials, devlist, dumpmgr, servervote, tclcheck,
tclchecksum, tclencheader, tclrequest, xmltools)
def default_enum(enumname, vardict, qualroot="tcllib.FotaCheck"):
return enum.IntEnum(enumname, vardict, module=__name__, qualname="{}.{}".format(qualroot, enumname))
class FotaCheck( class FotaCheck(
tclcheck.TclCheckMixin, tclcheck.TclCheckMixin,
@ -27,7 +24,7 @@ class FotaCheck(
devlist.DevListMixin, devlist.DevListMixin,
dumpmgr.DumpMgrMixin, dumpmgr.DumpMgrMixin,
xmltools.XmlToolsMixin xmltools.XmlToolsMixin
): ):
VDKEY = b"eJwdjwEOwDAIAr8kKFr//7HhmqXp8AIIDrYAgg8byiUXrwRJRXja+d6iNxu0AhUooDCN9rd6rDLxmGIakUVWo3IGCTRWqCAt6X4jGEIUAxgN0eYWnp+LkpHQAg/PsO90ELsy0Npm/n2HbtPndFgGEV31R9OmT4O4nrddjc3Qt6nWscx7e+WRHq5UnOudtjw5skuV09pFhvmqnOEIs4ljPeel1wfLYUF4\n" VDKEY = b"eJwdjwEOwDAIAr8kKFr//7HhmqXp8AIIDrYAgg8byiUXrwRJRXja+d6iNxu0AhUooDCN9rd6rDLxmGIakUVWo3IGCTRWqCAt6X4jGEIUAxgN0eYWnp+LkpHQAg/PsO90ELsy0Npm/n2HbtPndFgGEV31R9OmT4O4nrddjc3Qt6nWscx7e+WRHq5UnOudtjw5skuV09pFhvmqnOEIs4ljPeel1wfLYUF4\n"
CKTP = default_enum("CKTP", ["AUTO", "MANUAL"]) CKTP = default_enum("CKTP", ["AUTO", "MANUAL"])
MODE = default_enum("MODE", {"OTA": 2, "FULL": 4}) MODE = default_enum("MODE", {"OTA": 2, "FULL": 4})

View File

@ -3,8 +3,8 @@
import platform import platform
# Needed to make ANSI escape sequences work in Windows # Needed to make ANSI escape sequences work in Windows
system = platform.system() SYSTEM = platform.system()
if system == "Windows": if SYSTEM == "Windows":
try: try:
import colorama import colorama
colorama.init() colorama.init()

View File

@ -5,6 +5,7 @@
import argparse import argparse
import webbrowser import webbrowser
class DefaultParser(argparse.ArgumentParser): class DefaultParser(argparse.ArgumentParser):
def __init__(self, appname, desc=None): def __init__(self, appname, desc=None):
super().__init__(prog=appname, description=desc, epilog="https://github.com/mbirth/tcl_ota_check") super().__init__(prog=appname, description=desc, epilog="https://github.com/mbirth/tcl_ota_check")

View File

@ -2,6 +2,7 @@
import base64 import base64
class CredentialsMixin: class CredentialsMixin:
@staticmethod @staticmethod
def get_creds(): def get_creds():

View File

@ -2,14 +2,18 @@
import json import json
import os import os
import requests
import time import time
import requests
from . import ansi from . import ansi
DEVICELIST_URL = "https://tclota.birth-online.de/json_lastupdates.php" DEVICELIST_URL = "https://tclota.birth-online.de/json_lastupdates.php"
DEVICELIST_FILE = "prds.json" DEVICELIST_FILE = "prds.json"
DEVICELIST_CACHE_SECONDS = 86400 DEVICELIST_CACHE_SECONDS = 86400
class DevListMixin: class DevListMixin:
@staticmethod @staticmethod
def get_devicelist(force=False, output_diff=True): def get_devicelist(force=False, output_diff=True):
@ -21,18 +25,18 @@ class DevListMixin:
filemtime = filestat.st_mtime filemtime = filestat.st_mtime
if filemtime > time.time() - DEVICELIST_CACHE_SECONDS: if filemtime > time.time() - DEVICELIST_CACHE_SECONDS:
need_download = False need_download = False
with open(DEVICELIST_FILE, "rt") as df: with open(DEVICELIST_FILE, "rt") as dlfile:
old_prds = json.load(df) old_prds = json.load(dlfile)
except FileNotFoundError: except FileNotFoundError:
pass pass
if need_download or force: if need_download or force:
prds_json = requests.get(DEVICELIST_URL).text prds_json = requests.get(DEVICELIST_URL).text
with open(DEVICELIST_FILE, "wt") as df: with open(DEVICELIST_FILE, "wt") as dlfile:
df.write(prds_json) dlfile.write(prds_json)
with open(DEVICELIST_FILE, "rt") as df: with open(DEVICELIST_FILE, "rt") as dlfile:
prds = json.load(df) prds = json.load(dlfile)
if old_prds and output_diff: if old_prds and output_diff:
DevListMixin.print_prd_diff(old_prds, prds) DevListMixin.print_prd_diff(old_prds, prds)

View File

@ -3,8 +3,10 @@
import errno import errno
import glob import glob
import os import os
from . import ansi from . import ansi
class DumpMgrMixin: class DumpMgrMixin:
def __init__(self): def __init__(self):
self.last_dump_filename = None self.last_dump_filename = None
@ -14,11 +16,11 @@ class DumpMgrMixin:
if not os.path.exists(os.path.dirname(outfile)): if not os.path.exists(os.path.dirname(outfile)):
try: try:
os.makedirs(os.path.dirname(outfile)) os.makedirs(os.path.dirname(outfile))
except OSError as e: except OSError as err:
if e.errno != errno.EEXIST: if err.errno != errno.EEXIST:
raise raise
with open(outfile, "w", encoding="utf-8") as f: with open(outfile, "w", encoding="utf-8") as fhandle:
f.write(data) fhandle.write(data)
self.last_dump_filename = outfile self.last_dump_filename = outfile
def delete_last_dump(self): def delete_last_dump(self):
@ -29,9 +31,9 @@ class DumpMgrMixin:
@staticmethod @staticmethod
def write_info_if_dumps_found(): def write_info_if_dumps_found():
# To disable this info, uncomment the following line. # To disable this info, uncomment the following line.
#return # return
files = glob.glob(os.path.normpath("logs/*.xml")) files = glob.glob(os.path.normpath("logs/*.xml"))
if len(files) > 0: if files:
print() print()
print("{}There are {} logs collected in the logs/ directory.{} Please consider uploading".format(ansi.YELLOW, len(files), ansi.RESET)) print("{}There are {} logs collected in the logs/ directory.{} Please consider uploading".format(ansi.YELLOW, len(files), ansi.RESET))
print("them to https://tclota.birth-online.de/ by running {}./upload_logs.py{}.".format(ansi.CYAN, ansi.RESET)) print("them to https://tclota.birth-online.de/ by running {}./upload_logs.py{}.".format(ansi.CYAN, ansi.RESET))

View File

@ -2,6 +2,7 @@
import numpy import numpy
class ServerVoteMixin: class ServerVoteMixin:
def __init__(self): def __init__(self):
self.g2master = None self.g2master = None
@ -41,7 +42,7 @@ class ServerVoteMixin:
self.check_time_count += 1 self.check_time_count += 1
def check_time_avg(self): def check_time_avg(self):
return (self.check_time_sum / self.check_time_count) return self.check_time_sum / self.check_time_count
def master_server_vote_on_time(self, last_duration, avg_duration): def master_server_vote_on_time(self, last_duration, avg_duration):
if last_duration < avg_duration - 0.5: if last_duration < avg_duration - 0.5:

View File

@ -2,9 +2,11 @@
import time import time
from collections import OrderedDict from collections import OrderedDict
import requests import requests
from defusedxml import ElementTree from defusedxml import ElementTree
class TclCheckMixin: class TclCheckMixin:
def do_check(self, https=True, timeout=10, max_tries=5): def do_check(self, https=True, timeout=10, max_tries=5):
protocol = "https://" if https else "http://" protocol = "https://" if https else "http://"
@ -12,7 +14,7 @@ class TclCheckMixin:
params = OrderedDict() params = OrderedDict()
params["id"] = self.serid params["id"] = self.serid
params["curef"] = self.curef params["curef"] = self.curef
params["fv"] = self.fv params["fv"] = self.fvver
params["mode"] = self.mode.value params["mode"] = self.mode.value
params["type"] = self.ftype params["type"] = self.ftype
params["cltp"] = self.cltp.value params["cltp"] = self.cltp.value
@ -23,7 +25,7 @@ class TclCheckMixin:
#params["ckot"] = self.ckot.value #params["ckot"] = self.ckot.value
last_response = None last_response = None
for num_try in range(0, max_tries): for _ in range(0, max_tries):
try: try:
reqtime_start = time.perf_counter() reqtime_start = time.perf_counter()
req = self.sess.get(url, params=params, timeout=timeout) req = self.sess.get(url, params=params, timeout=timeout)
@ -59,12 +61,12 @@ class TclCheckMixin:
def parse_check(xmlstr): def parse_check(xmlstr):
root = ElementTree.fromstring(xmlstr) root = ElementTree.fromstring(xmlstr)
curef = root.find("CUREF").text curef = root.find("CUREF").text
fv = root.find("VERSION").find("FV").text fvver = root.find("VERSION").find("FV").text
tv = root.find("VERSION").find("TV").text tvver = root.find("VERSION").find("TV").text
fw_id = root.find("FIRMWARE").find("FW_ID").text fw_id = root.find("FIRMWARE").find("FW_ID").text
fileinfo = root.find("FIRMWARE").find("FILESET").find("FILE") fileinfo = root.find("FIRMWARE").find("FILESET").find("FILE")
fileid = fileinfo.find("FILE_ID").text fileid = fileinfo.find("FILE_ID").text
filename = fileinfo.find("FILENAME").text filename = fileinfo.find("FILENAME").text
filesize = fileinfo.find("SIZE").text filesize = fileinfo.find("SIZE").text
filehash = fileinfo.find("CHECKSUM").text filehash = fileinfo.find("CHECKSUM").text
return curef, fv, tv, fw_id, fileid, filename, filesize, filehash return curef, fvver, tvver, fw_id, fileid, filename, filesize, filehash

View File

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json import json
from defusedxml import ElementTree from defusedxml import ElementTree
class TclChecksumMixin: class TclChecksumMixin:
def do_checksum(self, encslave, address, uri): def do_checksum(self, encslave, address, uri):
url = "http://" + encslave + "/checksum.php" url = "http://" + encslave + "/checksum.php"
@ -12,7 +14,7 @@ class TclChecksumMixin:
payload_json = json.dumps(payload) payload_json = json.dumps(payload)
params[b"address"] = bytes(payload_json, "utf-8") params[b"address"] = bytes(payload_json, "utf-8")
#print(repr(dict(params))) # print(repr(dict(params)))
req = self.sess.post(url, data=params) req = self.sess.post(url, data=params)
if req.status_code == 200: if req.status_code == 200:
req.encoding = "utf-8" # Force encoding as server doesn't give one req.encoding = "utf-8" # Force encoding as server doesn't give one

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
class TclEncHeaderMixin: class TclEncHeaderMixin:
def do_encrypt_header(self, encslave, address): def do_encrypt_header(self, encslave, address):
params = self.get_creds2() params = self.get_creds2()

View File

@ -4,11 +4,13 @@ import binascii
import hashlib import hashlib
import random import random
import time import time
from math import floor
import zlib import zlib
from collections import OrderedDict from collections import OrderedDict
from math import floor
from defusedxml import ElementTree from defusedxml import ElementTree
''' '''
private HashMap<String, String> buildDownloadUrisParams(UpdatePackageInfo updatePackageInfo) { private HashMap<String, String> buildDownloadUrisParams(UpdatePackageInfo updatePackageInfo) {
FotaLog.m28v(TAG, "doAfterCheck"); FotaLog.m28v(TAG, "doAfterCheck");
@ -31,6 +33,7 @@ from defusedxml import ElementTree
} }
''' '''
class TclRequestMixin: class TclRequestMixin:
@staticmethod @staticmethod
def get_salt(): def get_salt():
@ -41,10 +44,10 @@ class TclRequestMixin:
def get_vk2(self, params_dict, cltp): def get_vk2(self, params_dict, cltp):
params_dict["cltp"] = cltp params_dict["cltp"] = cltp
query = "" query = ""
for k, v in params_dict.items(): for key, val in params_dict.items():
if len(query) > 0: if query:
query += "&" query += "&"
query += k + "=" + str(v) query += key + "=" + str(val)
vdk = zlib.decompress(binascii.a2b_base64(self.VDKEY)) vdk = zlib.decompress(binascii.a2b_base64(self.VDKEY))
query += vdk.decode("utf-8") query += vdk.decode("utf-8")
engine = hashlib.sha1() engine = hashlib.sha1()
@ -52,14 +55,14 @@ class TclRequestMixin:
hexhash = engine.hexdigest() hexhash = engine.hexdigest()
return hexhash return hexhash
def do_request(self, curef, fv, tv, fw_id): def do_request(self, curef, fvver, tvver, fw_id):
url = "https://" + self.g2master + "/download_request.php" url = "https://" + self.g2master + "/download_request.php"
params = OrderedDict() params = OrderedDict()
params["id"] = self.serid params["id"] = self.serid
params["salt"] = self.get_salt() params["salt"] = self.get_salt()
params["curef"] = curef params["curef"] = curef
params["fv"] = fv params["fv"] = fvver
params["tv"] = tv params["tv"] = tvver
params["type"] = self.ftype params["type"] = self.ftype
params["fw_id"] = fw_id params["fw_id"] = fw_id
params["mode"] = self.mode.value params["mode"] = self.mode.value
@ -71,7 +74,7 @@ class TclRequestMixin:
params["foot"] = 1 params["foot"] = 1
params["chnl"] = self.chnl.value params["chnl"] = self.chnl.value
#print(repr(dict(params))) # print(repr(dict(params)))
req = self.sess.post(url, data=params) req = self.sess.post(url, data=params)
if req.status_code == 200: if req.status_code == 200:
req.encoding = "utf-8" # Force encoding as server doesn't give one req.encoding = "utf-8" # Force encoding as server doesn't give one

View File

@ -2,6 +2,7 @@
import xml.dom.minidom import xml.dom.minidom
class XmlToolsMixin: class XmlToolsMixin:
@staticmethod @staticmethod
def pretty_xml(xmlstr): def pretty_xml(xmlstr):

View File

@ -7,13 +7,15 @@
import glob import glob
import os import os
import requests import requests
# This is the URL to an installation of https://github.com/mbirth/tcl_update_db # This is the URL to an installation of https://github.com/mbirth/tcl_update_db
UPLOAD_URL = "https://tclota.birth-online.de/" UPLOAD_URL = "https://tclota.birth-online.de/"
LOGS_GLOB = os.path.normpath("logs/*.xml") LOGS_GLOB = os.path.normpath("logs/*.xml")
headers = { "Content-Type": "text/xml" } headers = {"Content-Type": "text/xml"}
file_list = glob.glob(LOGS_GLOB) file_list = glob.glob(LOGS_GLOB)
print("Found {} logs to upload.".format(len(file_list))) print("Found {} logs to upload.".format(len(file_list)))
@ -39,4 +41,3 @@ try:
print(" OK") print(" OK")
except OSError as e: except OSError as e:
print(" FAILED") print(" FAILED")