diff --git a/scripts/wk/hw/ddrescue.py b/scripts/wk/hw/ddrescue.py index 5d3d7e2e..496ac01f 100644 --- a/scripts/wk/hw/ddrescue.py +++ b/scripts/wk/hw/ddrescue.py @@ -958,6 +958,7 @@ class State(): debug_dir.mkdir() # State (self) + std.save_pickles({'state': self}, debug_dir) with open(f'{debug_dir}/state.report', 'a') as _f: _f.write('[Debug report]\n') _f.write('\n'.join(debug.generate_object_report(self))) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index f36b5471..fbea7b98 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -331,6 +331,7 @@ class State(): debug_dir.mkdir() # State (self) + std.save_pickles({'state': self}, debug_dir) with open(f'{debug_dir}/state.report', 'a') as _f: _f.write('\n'.join(debug.generate_object_report(self))) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index e30c3fd7..31555d05 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -2,11 +2,13 @@ # pylint: disable=too-many-lines # vim: sts=2 sw=2 ts=2 +import inspect import itertools import logging import lzma import os import pathlib +import pickle import platform import re import socket @@ -26,6 +28,7 @@ from wk.cfg.main import ( WIDTH, ) from wk.cfg.net import CRASH_SERVER +from wk.log import get_root_logger_path # STATIC VARIABLES @@ -863,23 +866,26 @@ def major_exception(): LOG.critical('Major exception encountered', exc_info=True) print_error('Major exception', log=False) print_warning(SUPPORT_MESSAGE) + if ENABLED_UPLOAD_DATA: + print_warning('Also, please run upload-logs to help debugging!') print(traceback.format_exc()) - # Build report - report = generate_debug_report() + # TODO: Decide to remove or reinstate following section + ## Build report + #report = generate_debug_report() - # Upload details - prompt = f'Upload details to {CRASH_SERVER.get("Name", "?")}?' - if ENABLED_UPLOAD_DATA and ask(prompt): - print('Uploading... ', end='', flush=True) - try: - upload_debug_report(report, reason='CRASH') - except Exception: #pylint: disable=broad-except - print_error('FAILED', log=False) - LOG.error('Upload failed', exc_info=True) - else: - print_success('SUCCESS', log=False) - LOG.info('Upload successful') + ## Upload details + #prompt = f'Upload details to {CRASH_SERVER.get("Name", "?")}?' + #if ENABLED_UPLOAD_DATA and ask(prompt): + # print('Uploading... ', end='', flush=True) + # try: + # upload_debug_report(report, reason='CRASH') + # except Exception: #pylint: disable=broad-except + # print_error('FAILED', log=False) + # LOG.error('Upload failed', exc_info=True) + # else: + # print_success('SUCCESS', log=False) + # LOG.info('Upload successful') # Done pause('Press Enter to exit... ') @@ -960,6 +966,25 @@ def print_warning(msg, log=True, **kwargs): LOG.warning(msg) +def save_pickles(obj_dict, out_path=None): + """Save dict of objects using pickle.""" + LOG.info('Saving pickles') + + # Set path + if not out_path: + out_path = pathlib.Path(f'{get_root_logger_path().parent}/debug') + + # Save pickles + try: + for name, obj in obj_dict.copy().items(): + if name.startswith('__') or inspect.ismodule(obj): + continue + with open(f'{out_path}/{name}.pickle', 'wb') as _f: + pickle.dump(obj, _f, protocol=pickle.HIGHEST_PROTOCOL) + except Exception: # pylint: disable=broad-except + LOG.error('Failed to save all the pickles', exc_info=True) + + def set_title(title): """Set window title.""" LOG.debug('title: %s', title)