1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
"""Generic TCL API result handlers.""" |
5
|
|
|
|
6
|
|
|
import xml.dom.minidom |
7
|
|
|
|
8
|
|
|
from defusedxml import ElementTree |
9
|
|
|
|
10
|
|
|
from .. import dumpmgr |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class TclResult: |
|
|
|
|
14
|
|
|
"""Generic TCL API result.""" |
15
|
|
|
|
16
|
|
|
def __init__(self, xmlstr: str): |
17
|
|
|
"""Populate variables.""" |
18
|
|
|
self.raw_xml = xmlstr |
19
|
|
|
self.dumper = dumpmgr.DumpMgr() |
20
|
|
|
self.dumper.write_dump(xmlstr) |
21
|
|
|
|
22
|
|
|
def delete_dump(self): |
23
|
|
|
"""Delete last dump.""" |
24
|
|
|
self.dumper.delete_last_dump() |
25
|
|
|
|
26
|
|
|
def pretty_xml(self): |
27
|
|
|
"""Return prettified input XML with ``xml.dom.minidom``.""" |
28
|
|
|
mdx = xml.dom.minidom.parseString(self.raw_xml) |
29
|
|
|
return mdx.toprettyxml(indent=" ") |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class CheckResult(TclResult): |
|
|
|
|
33
|
|
|
"""Handle check request result.""" |
34
|
|
|
|
35
|
|
|
def __init__(self, xmlstr: str): |
36
|
|
|
"""Extract data from check request result.""" |
37
|
|
|
super().__init__(xmlstr) |
38
|
|
|
root = ElementTree.fromstring(xmlstr) |
39
|
|
|
self.curef = root.find("CUREF").text |
40
|
|
|
self.fvver = root.find("VERSION").find("FV").text |
41
|
|
|
self.tvver = root.find("VERSION").find("TV").text |
42
|
|
|
self.fw_id = root.find("FIRMWARE").find("FW_ID").text |
43
|
|
|
fileinfo = root.find("FIRMWARE").find("FILESET").find("FILE") |
44
|
|
|
self.fileid = fileinfo.find("FILE_ID").text |
45
|
|
|
self.filename = fileinfo.find("FILENAME").text |
46
|
|
|
self.filesize = fileinfo.find("SIZE").text |
47
|
|
|
self.filehash = fileinfo.find("CHECKSUM").text |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
class DownloadResult(TclResult): |
|
|
|
|
51
|
|
|
"""Handle download request result.""" |
52
|
|
|
|
53
|
|
|
def __init__(self, xmlstr: str): |
54
|
|
|
"""Extract data from download request result.""" |
55
|
|
|
super().__init__(xmlstr) |
56
|
|
|
root = ElementTree.fromstring(xmlstr) |
57
|
|
|
file = root.find("FILE_LIST").find("FILE") |
58
|
|
|
self.fileid = file.find("FILE_ID").text |
59
|
|
|
self.fileurl = file.find("DOWNLOAD_URL").text |
60
|
|
|
s3_fileurl_node = file.find("S3_DOWNLOAD_URL") |
61
|
|
|
self.s3_fileurl = None |
62
|
|
|
if s3_fileurl_node is not None: |
63
|
|
|
self.s3_fileurl = s3_fileurl_node.text |
64
|
|
|
slave_list = root.find("SLAVE_LIST").findall("SLAVE") |
65
|
|
|
enc_list = root.find("SLAVE_LIST").findall("ENCRYPT_SLAVE") |
66
|
|
|
s3_slave_list = root.find("SLAVE_LIST").findall("S3_SLAVE") |
67
|
|
|
self.slaves = [s.text for s in slave_list] |
68
|
|
|
self.encslaves = [s.text for s in enc_list] |
69
|
|
|
self.s3_slaves = [s.text for s in s3_slave_list] |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
class ChecksumResult(TclResult): |
|
|
|
|
73
|
|
|
"""Handle checksum request result.""" |
74
|
|
|
|
75
|
|
|
def __init__(self, xmlstr: str): |
76
|
|
|
"""Extract data from checksum request result.""" |
77
|
|
|
super().__init__(xmlstr) |
78
|
|
|
root = ElementTree.fromstring(xmlstr) |
79
|
|
|
file = root.find("FILE_CHECKSUM_LIST").find("FILE") |
80
|
|
|
self.file_addr = file.find("ADDRESS").text |
81
|
|
|
self.sha1_enc_footer = file.find("ENCRYPT_FOOTER").text |
82
|
|
|
self.sha1_footer = file.find("FOOTER").text |
83
|
|
|
self.sha1_body = file.find("BODY").text |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
class EncryptHeaderResult(TclResult): |
|
|
|
|
87
|
|
|
"""Handle encrypted header request result.""" |
88
|
|
|
|
89
|
|
|
def __init__(self, contents: str): |
|
|
|
|
90
|
|
|
"""Extract data from encrypted header request result.""" |
91
|
|
|
self.rawdata = contents |
92
|
|
|
|