Add run_dism()

This commit is contained in:
2Shirt 2021-04-15 23:33:11 -06:00
parent 47b49077da
commit e088f705ba
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 38 additions and 3 deletions

View file

@ -247,10 +247,10 @@ def wait_for_procs(name, exact=True, timeout=None):
"""Wait for all process matching name."""
LOG.debug('name: %s, exact: %s, timeout: %s', name, exact, timeout)
target_procs = get_procs(name, exact=exact)
results = psutil.wait_procs(target_procs, timeout=timeout)
procs = psutil.wait_procs(target_procs, timeout=timeout)
# Raise exception if necessary
if results[1]: # Alive processes
if procs[1]: # Alive processes
raise psutil.TimeoutExpired(name=name, seconds=timeout)

View file

@ -15,7 +15,7 @@ except ImportError as err:
raise err
from wk.borrowed import acpi
from wk.exe import get_procs, run_program
from wk.exe import get_procs, run_program, wait_for_procs
from wk.io import non_clobber_path
from wk.log import format_log_path
from wk.std import GenericError, GenericWarning, sleep
@ -355,6 +355,41 @@ def run_chkdsk_online():
raise GenericError('Issue(s) detected')
def run_dism(repair=True):
"""Run DISM to either scan or repair component store health."""
conemu_args = ['-new_console:n', '-new_console:s33V'] if CONEMU else []
# Bail early
if OS_VERSION < 8:
raise GenericWarning('Unsupported OS')
# Run (repair) scan
log_path = format_log_path(
log_name=f'DISM_{"Restore" if repair else "Scan"}Health', tool=True,
)
cmd = [
'DISM', '/Online', '/Cleanup-Image',
'/RestoreHealth' if repair else '/ScanHealth',
f'/LogPath:{log_path}',
*conemu_args,
]
run_program(cmd, check=False, pipe=False)
wait_for_procs('dism.exe')
# Run check health
log_path = format_log_path(log_name='DISM_CheckHealth.log', tool=True)
cmd = [
'DISM', '/Online', '/Cleanup-Image',
'/CheckHealth',
f'/LogPath:{log_path}',
]
proc = run_program(cmd, check=False)
# Check for errors
if 'no component store corruption detected' not in proc.stdout.lower():
raise GenericError('Issue(s) detected')
def run_sfc_scan():
"""Run SFC and save results."""
cmd = ['sfc', '/scannow']