Update upload-logs to work under live-macOS

This commit is contained in:
2Shirt 2021-03-13 03:12:36 -07:00
parent 7a9d62cdd1
commit ccaf2a67b2

View file

@ -25,6 +25,54 @@ if PLATFORM not in ('macOS', 'Linux'):
# Functions
def compress(reason):
dest = pathlib.Path(f'~/{reason}_{NOW.strftime("%Y-%m-%dT%H%M%S%z")}.txz')
dest = dest.expanduser().resolve()
cmd = ['tar', 'caf', dest.name, LOG_DIR.name]
proc = wk.exe.run_program(cmd, check=False)
return dest
def compress_live_macos(reason):
"""Compress log_dir using the RAM disk."""
dest = pathlib.Path(
f'/Volumes/RAM_Disk/{reason}_{NOW.strftime("%Y-%m-%dT%H%M%S%z")}.txz',
)
tmp_file = dest.with_suffix('.tar')
cmd = ['tar', '-cf', tmp_file.name, LOG_DIR.name]
proc = wk.exe.run_program(cmd, check=False)
cmd = ['xz', '-z', tmp_file.name]
proc = wk.exe.run_program(cmd, check=False)
tmp_file = tmp_file.with_suffix('.tar.xz')
tmp_file.rename(dest.name)
return dest
def compress_and_upload(reason='Testing'):
"""Upload compressed log_dir to the crash server."""
server = wk.cfg.net.CRASH_SERVER
upload_args = {
'headers': server['Headers'],
'auth': (server['User'], server['Pass']),
}
# Compress LOG_DIR (relative to parent dir)
if os.path.exists('/.wk-live-macos'):
dest = compress_live_macos(reason)
upload_args['verify'] = '/.1201_Root_CA.crt'
else:
dest = compress(reason)
upload_args['data'] = dest.read_bytes()
# Upload compressed data
url = f'{server["Url"]}/{dest.name}'
result = requests.put(url, **upload_args)
# Check result
if not result.ok:
raise wk.std.GenericError('Failed to upload logs')
def main():
"""Upload logs for review."""
lines = []
@ -51,40 +99,16 @@ def main():
_f.write('\n'.join(lines))
# Compress and upload logs
os.chdir(LOG_DIR.parent)
print(os.getcwd())
result = try_and_print.run(
message='Uploading logs...',
function=upload_log_dir,
function=compress_and_upload,
reason='Review',
)
if not result['Failed']:
raise SystemExit(1)
def upload_log_dir(reason='Testing'):
"""Upload compressed log_dir to the crash server."""
server = wk.cfg.net.CRASH_SERVER
dest = pathlib.Path(f'~/{reason}_{NOW.strftime("%Y-%m-%dT%H%M%S%z")}.txz')
dest = dest.expanduser().resolve()
data = None
# Compress LOG_DIR (relative to parent dir)
os.chdir(LOG_DIR.parent)
cmd = ['tar', 'caf', dest.name, LOG_DIR.name]
proc = wk.exe.run_program(cmd, check=False)
# Upload compressed data
url = f'{server["Url"]}/{dest.name}'
result = requests.put(
url,
data=dest.read_bytes(),
headers=server['Headers'],
auth=(server['User'], server['Pass']),
)
# Check result
if not result.ok:
raise wk.std.GenericError('Failed to upload logs')
if __name__ == '__main__':
main()