From b3f4a31ed27f0078ee681b1e5807060aad157506 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 19 Feb 2022 18:42:41 -0700 Subject: [PATCH] Move detect drives logic to its own function --- scripts/wk/hw/ddrescue.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/wk/hw/ddrescue.py b/scripts/wk/hw/ddrescue.py index bf1739ba..932b84ef 100644 --- a/scripts/wk/hw/ddrescue.py +++ b/scripts/wk/hw/ddrescue.py @@ -1532,6 +1532,18 @@ def clean_working_dir(working_dir): shutil.move(entry.path, new_path) +def detect_drives(state): + """Detect connected drives and check source/dest selections.""" + std.clear_screen() + std.print_warning(DETECT_DRIVES_NOTICE) + if std.ask('Are you sure you proceed?'): + std.print_standard('Forcing controllers to rescan for devices...') + cmd = 'echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan' + exe.run_program(cmd, check=False, shell=True) + if source_or_destination_changed(state): + std.abort() + + def format_status_string(status, width): """Format colored status string, returns str.""" color = None @@ -1895,14 +1907,7 @@ def main(): # Detect drives if 'Detect drives' in selection[0]: - std.clear_screen() - std.print_warning(DETECT_DRIVES_NOTICE) - if std.ask('Are you sure you proceed?'): - std.print_standard('Forcing controllers to rescan for devices...') - cmd = 'echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan' - exe.run_program(cmd, check=False, shell=True) - if source_or_destination_changed(state): - std.abort() + detect_drives(state) # Start recovery if 'Start' in selection: