From 827f9bce6a192ed1f57864a21753204135b9ece2 Mon Sep 17 00:00:00 2001 From: Alan Mason <1923621+2Shirt@users.noreply.github.com> Date: Fri, 24 Nov 2017 21:11:56 -0800 Subject: [PATCH] 2017-03: Retroactive Updates Fixed using local windows images * Bugfix: remove_volume_letters() was not preserving the "keep" letter * First issue: if keep==None then it would crash * Second issue: The passed keep value was outdated (See bugfix below) * Bugfix: undesired call of assign_volume_letters() * prep_disk_for_formatting() resets the volume letters thus breaking local installs * By moving find_windows_image() to be called afterwards this is fixed but perhaps another refactor is in order? --- Scripts/functions.py | 24 +++++++++++++----------- Scripts/menu.py | 21 ++++++++++++--------- WK/amd64/ConEmu/ConEmu.xml | 2 +- WK/x86/ConEmu/ConEmu.xml | 2 +- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Scripts/functions.py b/Scripts/functions.py index 6a8f5c66..9b3b8e9d 100644 --- a/Scripts/functions.py +++ b/Scripts/functions.py @@ -116,8 +116,8 @@ def assign_volume_letters(): try: # Run script with open(diskpart_script, 'w') as script: - for vol in get_volume_numbers(): - script.write('select volume {number}\n'.format(number=vol)) + for vol in get_volumes(): + script.write('select volume {Number}\n'.format(**vol)) script.write('assign\n') run_program('diskpart /s {script}'.format(script=diskpart_script)) except subprocess.CalledProcessError: @@ -543,8 +543,8 @@ def get_ticket_id(): return ticket_id -def get_volume_numbers(): - vol_nums = [] +def get_volumes(): + vols = [] try: # Run script @@ -557,10 +557,9 @@ def get_volume_numbers(): else: # Append volume numbers for tmp in re.findall(r'Volume (\d+)\s+([A-Za-z]?)\s+', process_return): - if tmp[1] == '': - vol_nums.append(tmp[0]) + vols.append({'Number': tmp[0], 'Letter': tmp[1]}) - return vol_nums + return vols def human_readable_size(size, decimals=0): # Prep string formatting @@ -812,13 +811,16 @@ def print_success(message='Generic success', **kwargs): def print_warning(message='Generic warning', **kwargs): print('{YELLOW}{message}{CLEAR}'.format(message=message, **COLORS, **kwargs)) -def remove_volume_letters(keep=None): +def remove_volume_letters(keep=''): + if keep is None: + keep = '' try: # Run script with open(diskpart_script, 'w') as script: - for vol in get_volume_numbers(): - script.write('select volume {number}\n'.format(number=vol)) - script.write('remove\n') + for vol in get_volumes(): + if vol['Letter'].upper() != keep.upper(): + script.write('select volume {Number}\n'.format(**vol)) + script.write('remove noerr\n') run_program('diskpart /s {script}'.format(script=diskpart_script)) except subprocess.CalledProcessError: pass diff --git a/Scripts/menu.py b/Scripts/menu.py index a834026a..d7d010d1 100644 --- a/Scripts/menu.py +++ b/Scripts/menu.py @@ -92,13 +92,15 @@ def menu_windows_setup(): # Select the version of Windows to apply windows_version = select_windows_version() - - # Find Windows image - windows_image = find_windows_image(bin, windows_version) # Select drive to use as the OS drive dest_disk = select_disk('To which drive are we installing Windows?') prep_disk_for_formatting(dest_disk) + + # Find Windows image + ## NOTE: Needs to happen AFTER select_disk() is called as there's a hidden assign_volume_letters(). + ## This changes the current letters thus preventing installing from a local source. + windows_image = find_windows_image(bin, windows_version) # Display details for setup task os.system('cls') @@ -119,7 +121,8 @@ def menu_windows_setup(): # Safety check print('\nSAFETY CHECK') print_warning('All data will be DELETED from the drive and partition(s) listed above.') - print_error('This is irreversible and will lead to DATA LOSS.') + print_error('This is irreversible and will lead to ', end='', flush=True) + print('DATA LOSS.') if (not ask('Asking again to confirm, is this correct?')): abort_to_main_menu('Aborting Windows setup') @@ -127,7 +130,7 @@ def menu_windows_setup(): remove_volume_letters(keep=windows_image['Source']) # Format and partition drive - print('\n Formatting Drive...\t\t'.format(**par), end='', flush=True) + print('\n Formatting Drive... \t\t', end='', flush=True) try: if (dest_disk['Use GPT']): format_gpt(dest_disk, windows_version['Family']) @@ -140,7 +143,7 @@ def menu_windows_setup(): raise # Apply Image - print(' Applying Image...\t\t'.format(**par), end='', flush=True) + print(' Applying Image... \t\t', end='', flush=True) try: setup_windows(bin, windows_image, windows_version) print_success('Complete.') @@ -153,7 +156,7 @@ def menu_windows_setup(): raise # Create Boot files - print(' Update Boot Partition...\t\t'.format(**par), end='', flush=True) + print(' Update Boot Partition...\t\t', end='', flush=True) try: update_boot_partition() print_success('Complete.') @@ -166,12 +169,12 @@ def menu_windows_setup(): raise # Setup WinRE - print(' Update Recovery Tools...\t\t'.format(**par), end='', flush=True) + print(' Update Recovery Tools...\t\t', end='', flush=True) try: setup_windows_re(windows_version) print_success('Complete.') except SetupError: - print_error('Skipped.') + print('Skipped.') except: # Don't need to crash as this is (potentially) recoverable print_error('Failed.') diff --git a/WK/amd64/ConEmu/ConEmu.xml b/WK/amd64/ConEmu/ConEmu.xml index 68fa0f50..8a2049b9 100644 --- a/WK/amd64/ConEmu/ConEmu.xml +++ b/WK/amd64/ConEmu/ConEmu.xml @@ -138,7 +138,7 @@ - + diff --git a/WK/x86/ConEmu/ConEmu.xml b/WK/x86/ConEmu/ConEmu.xml index 68fa0f50..8a2049b9 100644 --- a/WK/x86/ConEmu/ConEmu.xml +++ b/WK/x86/ConEmu/ConEmu.xml @@ -138,7 +138,7 @@ - +