Updated UFD sections

This commit is contained in:
2Shirt 2019-06-04 17:06:11 -06:00
parent 617bb1484a
commit 798876eb10
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 25 additions and 16 deletions

View file

@ -54,16 +54,8 @@ if __name__ == '__main__':
confirm_selections(args) confirm_selections(args)
# Prep UFD # Prep UFD
print_info('Prep UFD') if not args['--update']:
if args['--update']: print_info('Prep UFD')
# Remove arch folder
try_and_print(
indent=2,
message='Removing Linux...',
function=remove_arch,
)
else:
# Format and partition
prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr']) prep_device(ufd_dev, UFD_LABEL, use_mbr=args['--use-mbr'])
# Mount UFD # Mount UFD
@ -73,8 +65,17 @@ if __name__ == '__main__':
function=mount, function=mount,
mount_source=find_first_partition(ufd_dev), mount_source=find_first_partition(ufd_dev),
mount_point='/mnt/UFD', mount_point='/mnt/UFD',
read_write=True,
) )
# Remove Arch folder
if args['--update']:
try_and_print(
indent=2,
message='Removing Linux...',
function=remove_arch,
)
# Copy sources # Copy sources
print_standard(' ') print_standard(' ')
print_info('Copy Sources') print_info('Copy Sources')

View file

@ -60,16 +60,16 @@ def confirm_selections(args):
def copy_source(source, items, overwrite=False): def copy_source(source, items, overwrite=False):
"""Copy source items to /mnt/UFD.""" """Copy source items to /mnt/UFD."""
is_iso = source.name.lower().endswith('.iso') is_image = source.is_file()
# Mount source if necessary # Mount source if necessary
if is_iso: if is_image:
mount(source, '/mnt/Source') mount(source, '/mnt/Source')
# Copy items # Copy items
for i_source, i_dest in items: for i_source, i_dest in items:
i_source = '{}{}'.format( i_source = '{}{}'.format(
'/mnt/Source' if is_iso else source, '/mnt/Source' if is_image else source,
i_source, i_source,
) )
i_dest = '/mnt/UFD{}'.format(i_dest) i_dest = '/mnt/UFD{}'.format(i_dest)
@ -80,7 +80,7 @@ def copy_source(source, items, overwrite=False):
pass pass
# Unmount source if necessary # Unmount source if necessary
if is_iso: if is_image:
unmount('/mnt/Source') unmount('/mnt/Source')
@ -199,6 +199,8 @@ def is_valid_path(path_obj, path_type):
valid_path = path_obj.is_dir() valid_path = path_obj.is_dir()
elif path_type == 'KIT': elif path_type == 'KIT':
valid_path = path_obj.is_dir() and path_obj.joinpath('.bin').exists() valid_path = path_obj.is_dir() and path_obj.joinpath('.bin').exists()
elif path_type == 'IMG':
valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.img'
elif path_type == 'ISO': elif path_type == 'ISO':
valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.iso' valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.iso'
elif path_type == 'UFD': elif path_type == 'UFD':
@ -207,10 +209,16 @@ def is_valid_path(path_obj, path_type):
return valid_path return valid_path
def mount(mount_source, mount_point): def mount(mount_source, mount_point, read_write=False):
"""Mount mount_source on mount_point.""" """Mount mount_source on mount_point."""
os.makedirs(mount_point, exist_ok=True) os.makedirs(mount_point, exist_ok=True)
cmd = ['mount', mount_source, mount_point] cmd = [
'mount',
mount_source,
mount_point,
'-o',
'rw' if read_write else 'ro',
]
run_program(cmd) run_program(cmd)