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
This commit is contained in:
parent
78e28bb6d2
commit
b71d3479be
1 changed files with 53 additions and 54 deletions
|
|
@ -81,7 +81,7 @@ def build_ufd():
|
||||||
try_print.run(
|
try_print.run(
|
||||||
message='Mounting UFD...',
|
message='Mounting UFD...',
|
||||||
function=linux.mount,
|
function=linux.mount,
|
||||||
mount_source=find_first_partition(ufd_dev),
|
source=find_first_partition(ufd_dev),
|
||||||
mount_point='/mnt/UFD',
|
mount_point='/mnt/UFD',
|
||||||
read_write=True,
|
read_write=True,
|
||||||
)
|
)
|
||||||
|
|
@ -124,7 +124,7 @@ def build_ufd():
|
||||||
try_print.run(
|
try_print.run(
|
||||||
message='Unmounting UFD...',
|
message='Unmounting UFD...',
|
||||||
function=linux.unmount,
|
function=linux.unmount,
|
||||||
mount_point='/mnt/UFD',
|
source_or_mountpoint='/mnt/UFD',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install syslinux (to device)
|
# Install syslinux (to device)
|
||||||
|
|
@ -300,59 +300,54 @@ def prep_device(dev_path, label, use_mbr=False):
|
||||||
try_print = std.TryAndPrint()
|
try_print = std.TryAndPrint()
|
||||||
try_print.indent = 2
|
try_print.indent = 2
|
||||||
|
|
||||||
# Zero-out first 64MB
|
def _create_table():
|
||||||
cmd = [
|
"""Create GPT or DOS partition table."""
|
||||||
'dd',
|
cmd = [
|
||||||
'bs=4M',
|
'parted', dev_path,
|
||||||
'count=16',
|
'--script',
|
||||||
'if=/dev/zero',
|
'--',
|
||||||
f'of={dev_path}',
|
'mklabel', 'msdos' if use_mbr else 'gpt',
|
||||||
]
|
'mkpart', 'primary', 'fat32', '4MiB',
|
||||||
try_print.run(
|
'-1s' if use_mbr else '-4MiB',
|
||||||
message='Zeroing first 64MiB...',
|
]
|
||||||
function=run_program,
|
run_program(cmd)
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create partition table
|
def _format_partition():
|
||||||
cmd = [
|
"""Format first partition on device FAT32."""
|
||||||
'parted', dev_path,
|
cmd = [
|
||||||
'--script',
|
'mkfs.vfat',
|
||||||
'--',
|
'-F', '32',
|
||||||
'mklabel', 'msdos' if use_mbr else 'gpt',
|
'-n', label,
|
||||||
'-1s' if use_mbr else '-4MiB',
|
find_first_partition(dev_path),
|
||||||
]
|
]
|
||||||
try_print.run(
|
run_program(cmd)
|
||||||
message='Creating partition table...',
|
|
||||||
function=run_program,
|
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set boot flag
|
def _set_boot_flag():
|
||||||
cmd = [
|
"""Set modern or legacy boot flag."""
|
||||||
'parted', dev_path,
|
cmd = [
|
||||||
'set', '1',
|
'parted', dev_path,
|
||||||
'boot' if use_mbr else 'legacy_boot',
|
'set', '1',
|
||||||
'on',
|
'boot' if use_mbr else 'legacy_boot',
|
||||||
]
|
'on',
|
||||||
try_print.run(
|
]
|
||||||
message='Setting boot flag...',
|
run_program(cmd)
|
||||||
function=run_program,
|
|
||||||
cmd=cmd,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Format partition
|
def _zero_device():
|
||||||
cmd = [
|
"""Zero-out first 64MB of device."""
|
||||||
'mkfs.vfat',
|
cmd = [
|
||||||
'-F', '32',
|
'dd',
|
||||||
'-n', label,
|
'bs=4M',
|
||||||
find_first_partition(dev_path),
|
'count=16',
|
||||||
]
|
'if=/dev/zero',
|
||||||
try_print.run(
|
f'of={dev_path}',
|
||||||
message='Formatting partition...',
|
]
|
||||||
function=run_program,
|
run_program(cmd)
|
||||||
cmd=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():
|
def remove_arch():
|
||||||
|
|
@ -370,7 +365,7 @@ def show_selections(args, sources, ufd_dev, ufd_sources):
|
||||||
std.print_info('Sources')
|
std.print_info('Sources')
|
||||||
for label in ufd_sources.keys():
|
for label in ufd_sources.keys():
|
||||||
if label in sources:
|
if label in sources:
|
||||||
std.print_standard(f' {label+":":<18} {sources["label"]}')
|
std.print_standard(f' {label+":":<18} {sources[label]}')
|
||||||
else:
|
else:
|
||||||
std.print_colored(
|
std.print_colored(
|
||||||
[f' {label+":":<18}', 'Not Specified'],
|
[f' {label+":":<18}', 'Not Specified'],
|
||||||
|
|
@ -411,7 +406,11 @@ def update_boot_entries():
|
||||||
|
|
||||||
# Find config files
|
# Find config files
|
||||||
for c_path, c_ext in BOOT_FILES.items():
|
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):
|
for item in os.scandir(c_path):
|
||||||
if item.name.lower().endswith(c_ext.lower()):
|
if item.name.lower().endswith(c_ext.lower()):
|
||||||
configs.append(item.path)
|
configs.append(item.path)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue