mirror of
https://github.com/mbirth/tcl_ota_check.git
synced 2024-11-09 22:06:47 +00:00
Cleanup, moved dumpmgr class.
This commit is contained in:
parent
e6e0e83039
commit
e582642936
@ -11,9 +11,9 @@ import sys
|
|||||||
|
|
||||||
from tcllib import argparser
|
from tcllib import argparser
|
||||||
from tcllib.devices import Device
|
from tcllib.devices import Device
|
||||||
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, \
|
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, \
|
||||||
ChecksumRequest, EncryptHeaderRequest, ServerSelector, \
|
ChecksumRequest, EncryptHeaderRequest, ServerSelector
|
||||||
write_info_if_dumps_found
|
|
||||||
|
|
||||||
|
|
||||||
dpdesc = """
|
dpdesc = """
|
||||||
|
@ -9,7 +9,8 @@ import sys
|
|||||||
|
|
||||||
from tcllib import ansi, argparser, devlist
|
from tcllib import ansi, argparser, devlist
|
||||||
from tcllib.devices import DesktopDevice
|
from tcllib.devices import DesktopDevice
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, write_info_if_dumps_found
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
||||||
|
|
||||||
|
|
||||||
dev = DesktopDevice()
|
dev = DesktopDevice()
|
||||||
|
@ -9,7 +9,8 @@ import sys
|
|||||||
|
|
||||||
from tcllib import ansi, argparser, devlist
|
from tcllib import ansi, argparser, devlist
|
||||||
from tcllib.devices import MobileDevice
|
from tcllib.devices import MobileDevice
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, write_info_if_dumps_found
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
||||||
|
|
||||||
|
|
||||||
dev = MobileDevice()
|
dev = MobileDevice()
|
||||||
|
@ -10,8 +10,8 @@ import sys
|
|||||||
|
|
||||||
from tcllib import ansi, argparser, devlist
|
from tcllib import ansi, argparser, devlist
|
||||||
from tcllib.devices import DesktopDevice
|
from tcllib.devices import DesktopDevice
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, \
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
write_info_if_dumps_found
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
||||||
|
|
||||||
|
|
||||||
dpdesc = """
|
dpdesc = """
|
||||||
|
@ -9,8 +9,8 @@ import sys
|
|||||||
|
|
||||||
from tcllib import ansi, argparser, devlist
|
from tcllib import ansi, argparser, devlist
|
||||||
from tcllib.devices import DesktopDevice
|
from tcllib.devices import DesktopDevice
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, \
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
write_info_if_dumps_found
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
||||||
|
|
||||||
|
|
||||||
# Variants to scan for
|
# Variants to scan for
|
||||||
|
@ -9,8 +9,8 @@ import sys
|
|||||||
|
|
||||||
from tcllib import ansi, argparser, devlist
|
from tcllib import ansi, argparser, devlist
|
||||||
from tcllib.devices import MobileDevice
|
from tcllib.devices import MobileDevice
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, \
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
write_info_if_dumps_found
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
||||||
|
|
||||||
|
|
||||||
dpdesc = """
|
dpdesc = """
|
||||||
|
@ -10,8 +10,8 @@ import requests
|
|||||||
|
|
||||||
from tcllib import ansi
|
from tcllib import ansi
|
||||||
from tcllib.devices import MobileDevice
|
from tcllib.devices import MobileDevice
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, \
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
write_info_if_dumps_found
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
||||||
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -10,9 +10,9 @@ import sys
|
|||||||
|
|
||||||
from tcllib import argparser
|
from tcllib import argparser
|
||||||
from tcllib.devices import DesktopDevice
|
from tcllib.devices import DesktopDevice
|
||||||
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
||||||
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, \
|
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, \
|
||||||
ChecksumRequest, EncryptHeaderRequest, ServerSelector, \
|
ChecksumRequest, EncryptHeaderRequest, ServerSelector
|
||||||
write_info_if_dumps_found
|
|
||||||
|
|
||||||
|
|
||||||
dpdesc = """
|
dpdesc = """
|
||||||
|
@ -1,35 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# pylint: disable=C0111,C0326,C0103
|
|
||||||
|
|
||||||
"""Library for TCL API work and related functions."""
|
"""Library for TCL API work and related functions."""
|
||||||
|
|
||||||
import requests
|
from .ansi import *
|
||||||
|
from .argparser import *
|
||||||
from . import (dumpmgr, servervote, tclcheck, tclchecksum, tclencheader,
|
from .dumpmgr import write_info_if_dumps_found
|
||||||
tclrequest)
|
|
||||||
|
|
||||||
|
|
||||||
class FotaCheck(
|
|
||||||
tclcheck.TclCheckMixin,
|
|
||||||
tclrequest.TclRequestMixin,
|
|
||||||
tclchecksum.TclChecksumMixin,
|
|
||||||
tclencheader.TclEncHeaderMixin,
|
|
||||||
servervote.ServerVoteMixin,
|
|
||||||
dumpmgr.DumpMgrMixin
|
|
||||||
):
|
|
||||||
"""Main API handler class."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Handle mixins and populate variables."""
|
|
||||||
super().__init__()
|
|
||||||
self.reset_session()
|
|
||||||
|
|
||||||
def reset_session(self, device=None):
|
|
||||||
"""Reset everything to default."""
|
|
||||||
self.g2master = self.get_master_server()
|
|
||||||
self.sess = requests.Session()
|
|
||||||
if device:
|
|
||||||
self.sess.headers.update({"User-Agent": device.ua})
|
|
||||||
return self.sess
|
|
||||||
|
@ -15,23 +15,32 @@ from math import floor
|
|||||||
from . import ansi
|
from . import ansi
|
||||||
|
|
||||||
|
|
||||||
class DumpMgrMixin:
|
|
||||||
"""A mixin component for XML dump management."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Populate dump file name."""
|
|
||||||
self.last_dump_filename = None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_timestamp_random():
|
def get_timestamp_random():
|
||||||
"""Generate timestamp + random part to avoid collisions."""
|
"""Generate timestamp + random part to avoid collisions."""
|
||||||
millis = floor(time.time() * 1000)
|
millis = floor(time.time() * 1000)
|
||||||
tail = "{:06d}".format(random.randint(0, 999999))
|
tail = "{:06d}".format(random.randint(0, 999999))
|
||||||
return "{}_{}".format(str(millis), tail)
|
return "{}_{}".format(str(millis), tail)
|
||||||
|
|
||||||
|
def write_info_if_dumps_found():
|
||||||
|
"""Notify user to upload dumps if present."""
|
||||||
|
# To disable this info, uncomment the following line.
|
||||||
|
# return
|
||||||
|
files = glob.glob(os.path.normpath("logs/*.xml"))
|
||||||
|
if files:
|
||||||
|
print()
|
||||||
|
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))
|
||||||
|
|
||||||
|
class DumpMgr:
|
||||||
|
"""A class for XML dump management."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""Populate dump file name."""
|
||||||
|
self.last_dump_filename = None
|
||||||
|
|
||||||
def write_dump(self, data):
|
def write_dump(self, data):
|
||||||
"""Write dump to file."""
|
"""Write dump to file."""
|
||||||
outfile = os.path.normpath("logs/{}.xml".format(self.get_timestamp_random()))
|
outfile = os.path.normpath("logs/{}.xml".format(get_timestamp_random()))
|
||||||
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))
|
||||||
@ -47,14 +56,3 @@ class DumpMgrMixin:
|
|||||||
if self.last_dump_filename:
|
if self.last_dump_filename:
|
||||||
os.unlink(self.last_dump_filename)
|
os.unlink(self.last_dump_filename)
|
||||||
self.last_dump_filename = None
|
self.last_dump_filename = None
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def write_info_if_dumps_found():
|
|
||||||
"""Notify user to upload dumps if present."""
|
|
||||||
# To disable this info, uncomment the following line.
|
|
||||||
# return
|
|
||||||
files = glob.glob(os.path.normpath("logs/*.xml"))
|
|
||||||
if files:
|
|
||||||
print()
|
|
||||||
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))
|
|
||||||
|
@ -6,4 +6,3 @@ from .checksumrequest import ChecksumRequest
|
|||||||
from .encryptheaderrequest import EncryptHeaderRequest
|
from .encryptheaderrequest import EncryptHeaderRequest
|
||||||
from .runner import *
|
from .runner import *
|
||||||
from .serverselector import *
|
from .serverselector import *
|
||||||
from .dumpmgr import write_info_if_dumps_found
|
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# pylint: disable=C0111,C0326,C0103
|
|
||||||
|
|
||||||
"""Tools to manage dumps of API requests."""
|
|
||||||
|
|
||||||
import errno
|
|
||||||
import glob
|
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import time
|
|
||||||
from math import floor
|
|
||||||
|
|
||||||
from .. import ansi
|
|
||||||
|
|
||||||
|
|
||||||
def get_timestamp_random():
|
|
||||||
"""Generate timestamp + random part to avoid collisions."""
|
|
||||||
millis = floor(time.time() * 1000)
|
|
||||||
tail = "{:06d}".format(random.randint(0, 999999))
|
|
||||||
return "{}_{}".format(str(millis), tail)
|
|
||||||
|
|
||||||
def write_info_if_dumps_found():
|
|
||||||
"""Notify user to upload dumps if present."""
|
|
||||||
# To disable this info, uncomment the following line.
|
|
||||||
# return
|
|
||||||
files = glob.glob(os.path.normpath("logs/*.xml"))
|
|
||||||
if files:
|
|
||||||
print()
|
|
||||||
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))
|
|
||||||
|
|
||||||
class DumpMgr:
|
|
||||||
"""A class for XML dump management."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Populate dump file name."""
|
|
||||||
self.last_dump_filename = None
|
|
||||||
|
|
||||||
def write_dump(self, data):
|
|
||||||
"""Write dump to file."""
|
|
||||||
outfile = os.path.normpath("logs/{}.xml".format(get_timestamp_random()))
|
|
||||||
if not os.path.exists(os.path.dirname(outfile)):
|
|
||||||
try:
|
|
||||||
os.makedirs(os.path.dirname(outfile))
|
|
||||||
except OSError as err:
|
|
||||||
if err.errno != errno.EEXIST:
|
|
||||||
raise
|
|
||||||
with open(outfile, "w", encoding="utf-8") as fhandle:
|
|
||||||
fhandle.write(data)
|
|
||||||
self.last_dump_filename = outfile
|
|
||||||
|
|
||||||
def delete_last_dump(self):
|
|
||||||
"""Delete last dump."""
|
|
||||||
if self.last_dump_filename:
|
|
||||||
os.unlink(self.last_dump_filename)
|
|
||||||
self.last_dump_filename = None
|
|
@ -4,7 +4,7 @@ import xml.dom.minidom
|
|||||||
|
|
||||||
from defusedxml import ElementTree
|
from defusedxml import ElementTree
|
||||||
|
|
||||||
from . import dumpmgr
|
from .. import dumpmgr
|
||||||
|
|
||||||
|
|
||||||
class TclResult:
|
class TclResult:
|
||||||
|
Loading…
Reference in New Issue
Block a user