Compress report before uploading
* It's the new default but it can be disabled
This commit is contained in:
parent
2270236e42
commit
cf5b546183
2 changed files with 17 additions and 10 deletions
|
|
@ -26,10 +26,11 @@ WINDOWS_TIME_ZONE='Mountain Standard Time' # See 'tzutil /l' for valid values
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
CRASH_SERVER = {
|
CRASH_SERVER = {
|
||||||
#'Name': 'CrashServer',
|
'Name': 'CrashServer',
|
||||||
#'Url': '',
|
'Url': '',
|
||||||
#'User': '',
|
'User': '',
|
||||||
#'Pass': '',
|
'Pass': '',
|
||||||
|
'Headers': {'X-Requested-With': 'XMLHttpRequest'},
|
||||||
}
|
}
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import lzma
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
|
|
@ -381,10 +382,13 @@ def strip_colors(string):
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
def upload_debug_report(report, reason='DEBUG'):
|
def upload_debug_report(report, compress=True, reason='DEBUG'):
|
||||||
"""Upload debug report to CRASH_SERVER as specified in wk.cfg.main."""
|
"""Upload debug report to CRASH_SERVER as specified in wk.cfg.main."""
|
||||||
LOG.info('Uploading debug report to %s', CRASH_SERVER.get('Name', '?'))
|
LOG.info('Uploading debug report to %s', CRASH_SERVER.get('Name', '?'))
|
||||||
import requests
|
import requests
|
||||||
|
headers = CRASH_SERVER.get('Headers', {'X-Requested-With': 'XMLHttpRequest'})
|
||||||
|
if compress:
|
||||||
|
headers['Content-Type'] = 'application/octet-stream'
|
||||||
|
|
||||||
# Check if the required server details are available
|
# Check if the required server details are available
|
||||||
if not all(CRASH_SERVER.get(key, False) for key in ('Name', 'Url', 'User')):
|
if not all(CRASH_SERVER.get(key, False) for key in ('Name', 'Url', 'User')):
|
||||||
|
|
@ -406,15 +410,17 @@ def upload_debug_report(report, reason='DEBUG'):
|
||||||
)
|
)
|
||||||
LOG.debug('filename: %s', filename)
|
LOG.debug('filename: %s', filename)
|
||||||
|
|
||||||
|
# Compress report
|
||||||
|
if compress:
|
||||||
|
filename += '.xz'
|
||||||
|
xz_report = lzma.compress(report.encode('utf8'))
|
||||||
|
|
||||||
# Upload report
|
# Upload report
|
||||||
url = '{}/{}'.format(CRASH_SERVER['Url'], filename)
|
url = '{}/{}'.format(CRASH_SERVER['Url'], filename)
|
||||||
response = requests.put(
|
response = requests.put(
|
||||||
url,
|
url,
|
||||||
data=report,
|
data=xz_report if compress else report,
|
||||||
headers=CRASH_SERVER.get(
|
headers=headers,
|
||||||
'Headers',
|
|
||||||
{'X-Requested-With': 'XMLHttpRequest'},
|
|
||||||
),
|
|
||||||
auth=(CRASH_SERVER['User'], CRASH_SERVER.get('Pass', '')),
|
auth=(CRASH_SERVER['User'], CRASH_SERVER.get('Pass', '')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue