Add wk_debug.py

This commit is contained in:
2Shirt 2022-10-08 18:28:17 -07:00
parent 2c9e56e830
commit bb43c7447d
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 78 additions and 0 deletions

5
scripts/wk-debug Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
#
## WizardKit: Debug Launcher
python3 -i wk_debug.py

73
scripts/wk_debug.py Executable file
View file

@ -0,0 +1,73 @@
#!/usr/bin/env python3
"""WizardKit: Debug Launcher"""
# pylint: disable=invalid-name
# vim: sts=2 sw=2 ts=2
import os
import pathlib
import pickle
import sys
os.chdir(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.getcwd())
import wk # pylint: disable=wrong-import-position
# STATIC VARIABLES
OPTIONS = {
'Cloning / Imaging': 'ddrescue-TUI',
'Hardware Diagnostics': 'Hardware-Diagnostics',
}
def get_debug_prefix() -> str:
"""Ask what we're debugging, returns log dir prefix."""
menu = wk.std.Menu(title=f'{wk.cfg.main.KIT_NAME_FULL}: Debugging Menu\n')
for name, prefix in OPTIONS.items():
menu.add_option(name, {'Prefix': prefix})
selection = menu.simple_select()
return selection[1]['Prefix']
def get_debug_path() -> pathlib.Path:
"""Get debug path."""
log_dir = pathlib.Path('~/Logs').expanduser().resolve()
debug_paths = []
prefix = get_debug_prefix()
# Build list of options
for item in log_dir.iterdir():
if item.is_dir() and item.name.startswith(prefix):
debug_paths.append(item.joinpath('debug'))
debug_paths = [item for item in debug_paths if item.exists()]
debug_paths.sort()
# Safety check
if not debug_paths:
wk.std.abort('No logs found, aborting.')
# Use latest option
if wk.std.ask('Use latest session?'):
return debug_paths[-1]
# Select from list
menu = wk.std.Menu(title=f'{wk.cfg.main.KIT_NAME_FULL}: Debugging Menu\n')
for item in debug_paths:
menu.add_option(item.parent.name, {'Path': item})
selection = menu.simple_select()
# Done
return selection[1]['Path']
if __name__ == '__main__':
# Leaving this at the global level
try:
debug_path = get_debug_path()
except SystemExit:
pass
else:
state = None
# Load pickle
with open(debug_path.joinpath('state.pickle'), 'rb') as f:
state = pickle.load(f)