From 78e28bb6d23a5bbdb1440611f9fe2edd43a4d978 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 22 Jan 2020 23:07:03 -0700 Subject: [PATCH 1/3] Log wk.exe.run_program result in debug mode --- scripts/wk/exe.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/wk/exe.py b/scripts/wk/exe.py index fe2f1b0d..17f49249 100644 --- a/scripts/wk/exe.py +++ b/scripts/wk/exe.py @@ -194,9 +194,11 @@ def run_program(cmd, check=True, pipe=True, shell=False, **kwargs): pipe=pipe, shell=shell, **kwargs) + proc = subprocess.run(**cmd_kwargs) + LOG.debug('proc: %s', proc) - # Ready to run program - return subprocess.run(**cmd_kwargs) + # Done + return proc def start_thread(function, args=None, daemon=True): From b71d3479beb72bbdb2ab21135fabe148f0d13cc9 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 22 Jan 2020 23:11:24 -0700 Subject: [PATCH 2/3] Updated wk.kit.ufd * Moved TryAndPrint run_program calls to private functions * Only need PASS/FAIL and to hide the cmd output * Avoid crash when searching for boot config files * Misc Bugfixes --- scripts/wk/kit/ufd.py | 107 +++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/scripts/wk/kit/ufd.py b/scripts/wk/kit/ufd.py index 2a4be45e..7bfc2351 100644 --- a/scripts/wk/kit/ufd.py +++ b/scripts/wk/kit/ufd.py @@ -81,7 +81,7 @@ def build_ufd(): try_print.run( message='Mounting UFD...', function=linux.mount, - mount_source=find_first_partition(ufd_dev), + source=find_first_partition(ufd_dev), mount_point='/mnt/UFD', read_write=True, ) @@ -124,7 +124,7 @@ def build_ufd(): try_print.run( message='Unmounting UFD...', function=linux.unmount, - mount_point='/mnt/UFD', + source_or_mountpoint='/mnt/UFD', ) # Install syslinux (to device) @@ -300,59 +300,54 @@ def prep_device(dev_path, label, use_mbr=False): try_print = std.TryAndPrint() try_print.indent = 2 - # Zero-out first 64MB - cmd = [ - 'dd', - 'bs=4M', - 'count=16', - 'if=/dev/zero', - f'of={dev_path}', - ] - try_print.run( - message='Zeroing first 64MiB...', - function=run_program, - cmd=cmd, - ) + def _create_table(): + """Create GPT or DOS partition table.""" + cmd = [ + 'parted', dev_path, + '--script', + '--', + 'mklabel', 'msdos' if use_mbr else 'gpt', + 'mkpart', 'primary', 'fat32', '4MiB', + '-1s' if use_mbr else '-4MiB', + ] + run_program(cmd) - # Create partition table - cmd = [ - 'parted', dev_path, - '--script', - '--', - 'mklabel', 'msdos' if use_mbr else 'gpt', - '-1s' if use_mbr else '-4MiB', - ] - try_print.run( - message='Creating partition table...', - function=run_program, - cmd=cmd, - ) + def _format_partition(): + """Format first partition on device FAT32.""" + cmd = [ + 'mkfs.vfat', + '-F', '32', + '-n', label, + find_first_partition(dev_path), + ] + run_program(cmd) - # Set boot flag - cmd = [ - 'parted', dev_path, - 'set', '1', - 'boot' if use_mbr else 'legacy_boot', - 'on', - ] - try_print.run( - message='Setting boot flag...', - function=run_program, - cmd=cmd, - ) + def _set_boot_flag(): + """Set modern or legacy boot flag.""" + cmd = [ + 'parted', dev_path, + 'set', '1', + 'boot' if use_mbr else 'legacy_boot', + 'on', + ] + run_program(cmd) - # Format partition - cmd = [ - 'mkfs.vfat', - '-F', '32', - '-n', label, - find_first_partition(dev_path), - ] - try_print.run( - message='Formatting partition...', - function=run_program, - cmd=cmd, - ) + def _zero_device(): + """Zero-out first 64MB of device.""" + cmd = [ + 'dd', + 'bs=4M', + 'count=16', + 'if=/dev/zero', + f'of={dev_path}', + ] + run_program(cmd) + + # Run steps + try_print.run('Zeroing first 64MiB...', function=_zero_device) + try_print.run('Creating partition table...', function=_create_table) + try_print.run('Setting boot flag...', function=_set_boot_flag) + try_print.run('Formatting partition...', function=_format_partition) def remove_arch(): @@ -370,7 +365,7 @@ def show_selections(args, sources, ufd_dev, ufd_sources): std.print_info('Sources') for label in ufd_sources.keys(): if label in sources: - std.print_standard(f' {label+":":<18} {sources["label"]}') + std.print_standard(f' {label+":":<18} {sources[label]}') else: std.print_colored( [f' {label+":":<18}', 'Not Specified'], @@ -411,7 +406,11 @@ def update_boot_entries(): # Find config files for c_path, c_ext in BOOT_FILES.items(): - c_path = io.case_insensitive_path('/mnt/UFD{c_path}') + try: + c_path = io.case_insensitive_path(f'/mnt/UFD{c_path}') + except FileNotFoundError: + # Ignore and continue to next file + continue for item in os.scandir(c_path): if item.name.lower().endswith(c_ext.lower()): configs.append(item.path) From ea3240772e855ef17d8ccacc589263dea0073fb6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 22 Jan 2020 23:15:12 -0700 Subject: [PATCH 3/3] Create mount_point before mounting source --- scripts/wk/os/linux.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/wk/os/linux.py b/scripts/wk/os/linux.py index a62013ca..3a8c346d 100644 --- a/scripts/wk/os/linux.py +++ b/scripts/wk/os/linux.py @@ -75,6 +75,8 @@ def mount(source, mount_point=None, read_write=False): if not running_as_root(): cmd.insert(0, 'udevil') if mount_point: + mount_point = pathlib.Path(mount_point).resolve() + mount_point.mkdir(parents=True, exist_ok=True) cmd.append(mount_point) # Run mount command