Added check_disk.py

This commit is contained in:
2Shirt 2019-10-02 21:40:56 -07:00
parent ad06fab8a2
commit a2017fa415
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 52 additions and 5 deletions

49
scripts/check_disk.py Normal file
View file

@ -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()

View file

@ -5,9 +5,7 @@ import logging
import os import os
import pathlib import pathlib
import platform import platform
import time
from wk import cfg
from wk.borrowed import acpi from wk.borrowed import acpi
from wk.exe import run_program from wk.exe import run_program
from wk.io import non_clobber_path from wk.io import non_clobber_path
@ -128,7 +126,7 @@ def run_chkdsk_online():
cmd = ['CHKDSK', os.environ.get('SYSTEMDRIVE', 'C:')] cmd = ['CHKDSK', os.environ.get('SYSTEMDRIVE', 'C:')]
if OS_VERSION >= 8: if OS_VERSION >= 8:
cmd.extend(['/scan', '/perf']) 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') err_path = log_path.with_suffix('.err')
# Run scan # Run scan
@ -137,7 +135,7 @@ def run_chkdsk_online():
# Check result # Check result
if proc.returncode == 1: if proc.returncode == 1:
raise GenericWarning('Repaired (or manually aborted)') raise GenericWarning('Repaired (or manually aborted)')
elif proc.returncode > 1: if proc.returncode > 1:
raise GenericError('Issue(s) detected') raise GenericError('Issue(s) detected')
# Save output # Save output
@ -151,7 +149,7 @@ def run_chkdsk_online():
def run_sfc_scan(): def run_sfc_scan():
"""Run SFC and save results.""" """Run SFC and save results."""
cmd = ['sfc', '/scannow'] 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') err_path = log_path.with_suffix('.err')
# Run SFC # Run SFC