updated backup_partition()

This commit is contained in:
Alan Mason 2017-11-30 17:17:00 -08:00
parent 80cb9b8cea
commit 45f0b4d2b1
3 changed files with 32 additions and 29 deletions

View file

@ -2,31 +2,21 @@
from functions.common import * from functions.common import *
def backup_partition(bin=None, disk=None, par=None): def backup_partition(disk, partition):
# Bail early if par['Image Exists'] or par['Number'] in disk['Bad Partitions']:
if bin is None: raise GenericAbort
raise Exception('bin path not specified.')
if disk is None:
raise Exception('Disk not specified.')
if par is None:
raise Exception('Partition not specified.')
print(' Partition {Number} Backup...\t\t'.format(**par), end='', flush=True) cmd = [
if par['Number'] in disk['Bad Partitions']: global_vars['Tools']['wimlib-imagex'],
print_warning('Skipped.') 'capture'
else: '{}:\\'.format(par['Letter']),
cmd = '{bin}\\wimlib\\wimlib-imagex capture {Letter}:\\ "{Image Path}\\{Image File}" "{Image Name}" "{Image Name}" --compress=none'.format(bin=bin, **par) r'{}\{}'.format(par['Image Path'], par['Image File']),
if par['Image Exists']: par['Image Name'], # Image name
print_warning('Skipped.') par['Image Name'], # Image description
else: ' --compress=none',
try: ]
os.makedirs('{Image Path}'.format(**par), exist_ok=True) os.makedirs(par['Image Path'], exist_ok=True)
run_program(cmd) run_program(cmd)
print_success('Complete.')
except subprocess.CalledProcessError as err:
print_error('Failed.')
par['Error'] = err.stderr.decode().splitlines()
raise BackupError
def prep_disk_for_backup(dest=None, disk=None, ticket_id=None): def prep_disk_for_backup(dest=None, disk=None, ticket_id=None):
disk['Backup Warnings'] = '\n' disk['Backup Warnings'] = '\n'

View file

@ -37,6 +37,9 @@ class BIOSKeyNotFoundError(Exception):
class BinNotFoundError(Exception): class BinNotFoundError(Exception):
pass pass
class GenericAbort(Exception):
pass
class GenericError(Exception): class GenericError(Exception):
pass pass
@ -52,7 +55,7 @@ class NotInstalledError(Exception):
class NoProfilesError(Exception): class NoProfilesError(Exception):
pass pass
class PathNotFoundException(Exception): class PathNotFoundError(Exception):
pass pass
class UnsupportedOSError(Exception): class UnsupportedOSError(Exception):
@ -432,7 +435,7 @@ def try_and_print(message='Trying...',
err = traceback.format_exc() err = traceback.format_exc()
# Return or raise? # Return or raise?
if bool(err) and not catch_all: if err and not catch_all:
raise raise
else: else:
return {'CS': not bool(err), 'Error': err} return {'CS': not bool(err), 'Error': err}

View file

@ -53,6 +53,14 @@ PE_TOOLS = {
def menu_backup(): def menu_backup():
"""Take backup images of partition(s) in the WIM format and save them to a backup share""" """Take backup images of partition(s) in the WIM format and save them to a backup share"""
errors = False errors = False
other_results = {
'Error': {
'CalledProcessError': 'Unknown Error',
},
'Warning': {
'GenericAbort': 'Skipped',
'GenericRepair': 'Repaired',
}}
# Set ticket ID # Set ticket ID
os.system('cls') os.system('cls')
@ -89,10 +97,12 @@ def menu_backup():
# Backup partition(s) # Backup partition(s)
print('\n\nStarting task.\n') print('\n\nStarting task.\n')
for par in disk['Partitions']: for par in disk['Partitions']:
try: message = 'Partition {} Backup...'.format(par['Number'])
backup_partition(bin, disk, par) result = try_and_print(message=message, function=backup_partition,
except BackupError: other_results=other_results, disk=disk, partition=par)
if not result['CS']:
errors = True errors = True
par['Error'] = result['Error']
# Verify backup(s) # Verify backup(s)
if disk['Valid Partitions'] > 1: if disk['Valid Partitions'] > 1: