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

Dump all XML responses to files for later upload.

This commit is contained in:
Markus Birth 2017-11-02 02:02:13 +01:00
parent e6a8ac630f
commit 24ae0ba168
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
2 changed files with 15 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/__pycache__/ /__pycache__/
/logs/
/.nvimlog /.nvimlog
/header*.bin /header*.bin

View File

@ -6,7 +6,9 @@ import argparse
import base64 import base64
import binascii import binascii
import enum import enum
import errno
import hashlib import hashlib
import os
import platform import platform
import random import random
import time import time
@ -135,6 +137,17 @@ class FotaCheck:
elif last_duration > avg_duration + 0.5: elif last_duration > avg_duration + 0.5:
self.master_server_downvote() self.master_server_downvote()
def write_dump(self, data):
outfile = "logs/{}.xml".format(self.get_salt())
if not os.path.exists(os.path.dirname(outfile)):
try:
os.makedirs(os.path.dirname(outfile))
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(outfile, "w") as f:
f.write(data)
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://"
url = protocol + self.g2master + "/check.php" url = protocol + self.g2master + "/check.php"
@ -162,6 +175,7 @@ class FotaCheck:
last_response = req last_response = req
if req.status_code == 200: if req.status_code == 200:
self.master_server_vote_on_time(reqtime, reqtime_avg) self.master_server_vote_on_time(reqtime, reqtime_avg)
self.write_dump(req.text)
return req.text return req.text
elif req.status_code == 204: elif req.status_code == 204:
self.master_server_vote_on_time(reqtime, reqtime_avg) self.master_server_vote_on_time(reqtime, reqtime_avg)