diff --git a/scripts/check_disk.py b/scripts/check_disk.py new file mode 100644 index 00000000..01126124 --- /dev/null +++ b/scripts/check_disk.py @@ -0,0 +1,49 @@ +"""Wizard Kit: Check or repair the %SYSTEMDRIVE% filesystem via CHKDSK""" +# vim: sts=2 sw=2 ts=2 + +import os +import wk + + +def main(): + """Run or schedule CHKDSK and show result.""" + menu = wk.std.Menu(title=title) + title = f'{wk.cfg.main.KIT_NAME_FULL}: Check Disk Tool' + try_print = wk.std.TryAndPrint() + wk.std.clear_screen() + wk.std.set_title(title) + print('') + + # Add menu entries + menu.add_option('Offline scan') + menu.add_option('Online scan') + + # Show menu and make selection + selection = menu.simple_select() + + # Run or schedule scan + if 'Offline' in selection[0]: + function = wk.os.win.run_chkdsk_offline + msg_good = 'Scheduled' + else: + function = wk.os.win.run_chkdsk_online + msg_good = 'No issues detected' + try_print.run(f'CHKDSK ( + message={os.environ.get("SYSTEMDRIVE})...', + function=function, + msg_good=msg_good, + ) + + # Done + print('') + print('Done.') + wk.std.pause('Press Enter to exit...') + + +if __name__ == '__main__': + try: + main() + except SystemExit: + raise + except: #pylint: disable=bare-except + wk.std.major_exception() diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 4c4dfa7f..df341d75 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -5,9 +5,7 @@ import logging import os import pathlib import platform -import time -from wk import cfg from wk.borrowed import acpi from wk.exe import run_program from wk.io import non_clobber_path @@ -128,7 +126,7 @@ def run_chkdsk_online(): cmd = ['CHKDSK', os.environ.get('SYSTEMDRIVE', 'C:')] if OS_VERSION >= 8: cmd.extend(['/scan', '/perf']) - log_path = format_log_path(log_name='CHKDSK', timestamp=False, tool=True) + log_path = format_log_path(log_name='CHKDSK', tool=True) err_path = log_path.with_suffix('.err') # Run scan @@ -137,7 +135,7 @@ def run_chkdsk_online(): # Check result if proc.returncode == 1: raise GenericWarning('Repaired (or manually aborted)') - elif proc.returncode > 1: + if proc.returncode > 1: raise GenericError('Issue(s) detected') # Save output @@ -151,7 +149,7 @@ def run_chkdsk_online(): def run_sfc_scan(): """Run SFC and save results.""" cmd = ['sfc', '/scannow'] - log_path = format_log_path(log_name='SFC', timestamp=False, tool=True) + log_path = format_log_path(log_name='SFC', tool=True) err_path = log_path.with_suffix('.err') # Run SFC