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?
This commit is contained in:
Alan Mason 2017-11-24 21:11:56 -08:00
parent 1da75165f9
commit 827f9bce6a
4 changed files with 27 additions and 22 deletions

View file

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

View file

@ -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.')

View file

@ -138,7 +138,7 @@
<value name="CompressLongStrings" type="hex" data="01"/>
<value name="BackGround Image show" type="hex" data="01"/>
<value name="BackGround Image" type="string" data="ConEmu.jpg"/>
<value name="bgImageDarker" type="hex" data="50"/>
<value name="bgImageDarker" type="hex" data="60"/>
<value name="bgImageColors" type="dword" data="ffffffff"/>
<value name="bgOperation" type="hex" data="07"/>
<value name="bgPluginAllowed" type="hex" data="01"/>

View file

@ -138,7 +138,7 @@
<value name="CompressLongStrings" type="hex" data="01"/>
<value name="BackGround Image show" type="hex" data="01"/>
<value name="BackGround Image" type="string" data="ConEmu.jpg"/>
<value name="bgImageDarker" type="hex" data="50"/>
<value name="bgImageDarker" type="hex" data="60"/>
<value name="bgImageColors" type="dword" data="ffffffff"/>
<value name="bgOperation" type="hex" data="07"/>
<value name="bgPluginAllowed" type="hex" data="01"/>