Replace remaining docopt sections
This commit is contained in:
parent
58576cbdb4
commit
13b8dc8696
2 changed files with 69 additions and 41 deletions
|
|
@ -316,7 +316,7 @@ class State():
|
||||||
"""Get total size of all block_pairs in bytes, returns int."""
|
"""Get total size of all block_pairs in bytes, returns int."""
|
||||||
return sum(pair.size for pair in self.block_pairs)
|
return sum(pair.size for pair in self.block_pairs)
|
||||||
|
|
||||||
def init_recovery(self, docopt_args: dict[str, Any]) -> None:
|
def init_recovery(self, cli_args: dict[str, Any]) -> None:
|
||||||
"""Select source/dest and set env."""
|
"""Select source/dest and set env."""
|
||||||
cli.clear_screen()
|
cli.clear_screen()
|
||||||
disk_menu = menus.disks()
|
disk_menu = menus.disks()
|
||||||
|
|
@ -324,10 +324,10 @@ class State():
|
||||||
self.ui.set_progress_file(str(self.progress_out))
|
self.ui.set_progress_file(str(self.progress_out))
|
||||||
|
|
||||||
# Set mode
|
# Set mode
|
||||||
self.mode = set_mode(docopt_args)
|
self.mode = set_mode(cli_args)
|
||||||
|
|
||||||
# Select source
|
# Select source
|
||||||
self.source = select_disk_obj('source', disk_menu, docopt_args['<source>'])
|
self.source = select_disk_obj('source', disk_menu, cli_args['<source>'])
|
||||||
self.update_top_panes()
|
self.update_top_panes()
|
||||||
if self.source.trim:
|
if self.source.trim:
|
||||||
cli.print_warning('Source device supports TRIM')
|
cli.print_warning('Source device supports TRIM')
|
||||||
|
|
@ -340,12 +340,12 @@ class State():
|
||||||
self.destination = select_disk_obj(
|
self.destination = select_disk_obj(
|
||||||
'destination',
|
'destination',
|
||||||
disk_menu,
|
disk_menu,
|
||||||
docopt_args['<destination>'],
|
cli_args['<destination>'],
|
||||||
)
|
)
|
||||||
self.ui.add_title_pane('Destination', self.destination.name)
|
self.ui.add_title_pane('Destination', self.destination.name)
|
||||||
elif self.mode == 'Image':
|
elif self.mode == 'Image':
|
||||||
if docopt_args['<destination>']:
|
if cli_args['<destination>']:
|
||||||
self.destination = pathlib.Path(docopt_args['<destination>']).resolve()
|
self.destination = pathlib.Path(cli_args['<destination>']).resolve()
|
||||||
else:
|
else:
|
||||||
self.destination = menus.select_path('Destination')
|
self.destination = menus.select_path('Destination')
|
||||||
self.destination.mkdir(parents=True, exist_ok=True)
|
self.destination.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
@ -370,11 +370,11 @@ class State():
|
||||||
self.working_dir = get_working_dir(
|
self.working_dir = get_working_dir(
|
||||||
self.mode,
|
self.mode,
|
||||||
self.destination,
|
self.destination,
|
||||||
force_local=docopt_args['--force-local-map'],
|
force_local=cli_args['--force-local-map'],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Start fresh if requested
|
# Start fresh if requested
|
||||||
if docopt_args['--start-fresh']:
|
if cli_args['--start-fresh']:
|
||||||
clean_working_dir(self.working_dir)
|
clean_working_dir(self.working_dir)
|
||||||
|
|
||||||
# Add block pairs
|
# Add block pairs
|
||||||
|
|
@ -412,10 +412,10 @@ class State():
|
||||||
|
|
||||||
# Prep destination
|
# Prep destination
|
||||||
if self.mode == 'Clone':
|
if self.mode == 'Clone':
|
||||||
prep_destination(self, source_parts, dry_run=docopt_args['--dry-run'])
|
prep_destination(self, source_parts, dry_run=cli_args['--dry-run'])
|
||||||
|
|
||||||
# Safety Checks #2
|
# Safety Checks #2
|
||||||
if not docopt_args['--dry-run']:
|
if not cli_args['--dry-run']:
|
||||||
for pair in self.block_pairs:
|
for pair in self.block_pairs:
|
||||||
pair.safety_check()
|
pair.safety_check()
|
||||||
|
|
||||||
|
|
@ -1051,12 +1051,12 @@ def select_disk_obj(label:str, disk_menu: cli.Menu, disk_path: str) -> hw_disk.D
|
||||||
raise std.GenericAbort()
|
raise std.GenericAbort()
|
||||||
|
|
||||||
|
|
||||||
def set_mode(docopt_args) -> str:
|
def set_mode(cli_args) -> str:
|
||||||
"""Set mode from docopt_args or user selection, returns str."""
|
"""Set mode from cli_args or user selection, returns str."""
|
||||||
if docopt_args['clone']:
|
if cli_args['clone']:
|
||||||
return 'Clone'
|
return 'Clone'
|
||||||
|
|
||||||
if docopt_args['image']:
|
if cli_args['image']:
|
||||||
return 'Image'
|
return 'Image'
|
||||||
|
|
||||||
# Ask user if necessary
|
# Ask user if necessary
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""WizardKit: UFD Functions"""
|
"""WizardKit: UFD Functions"""
|
||||||
# vim: sts=2 sw=2 ts=2
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
|
@ -9,8 +10,6 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
from docopt import docopt
|
|
||||||
|
|
||||||
from wk import io, log
|
from wk import io, log
|
||||||
from wk.cfg.main import KIT_NAME_FULL, KIT_NAME_SHORT
|
from wk.cfg.main import KIT_NAME_FULL, KIT_NAME_SHORT
|
||||||
from wk.cfg.ufd import (
|
from wk.cfg.ufd import (
|
||||||
|
|
@ -29,30 +28,6 @@ from wk.ui import cli as ui
|
||||||
|
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
DOCSTRING = '''WizardKit: Build UFD
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
build-ufd [options] --ufd-device PATH
|
|
||||||
[--linux PATH]
|
|
||||||
[--main-kit PATH]
|
|
||||||
[--winpe PATH]
|
|
||||||
[--extra-dir PATH]
|
|
||||||
[EXTRA_IMAGES...]
|
|
||||||
build-ufd (-h | --help)
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-e PATH, --extra-dir PATH
|
|
||||||
-k PATH, --main-kit PATH
|
|
||||||
-l PATH, --linux PATH
|
|
||||||
-u PATH, --ufd-device PATH
|
|
||||||
-w PATH, --winpe PATH
|
|
||||||
|
|
||||||
-d --debug Enable debug mode
|
|
||||||
-h --help Show this page
|
|
||||||
-M --use-mbr Use real MBR instead of GPT w/ Protective MBR
|
|
||||||
-F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION!
|
|
||||||
-U --update Don't format device, just update
|
|
||||||
'''
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
EXTRA_IMAGES_LIST = '/mnt/UFD/arch/extra_images.list'
|
EXTRA_IMAGES_LIST = '/mnt/UFD/arch/extra_images.list'
|
||||||
MIB = 1024 ** 2
|
MIB = 1024 ** 2
|
||||||
|
|
@ -61,6 +36,54 @@ UFD_LABEL = f'{KIT_NAME_SHORT}_UFD'
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
def argparse_helper() -> dict[str, None|bool|str]:
|
||||||
|
"""Helper function to setup and return args, returns dict.
|
||||||
|
|
||||||
|
NOTE: A dict is used to match the legacy code.
|
||||||
|
"""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='build-ufd',
|
||||||
|
description=f'{KIT_NAME_FULL}: Build UFD',
|
||||||
|
)
|
||||||
|
parser.add_argument('-u', '--ufd-device', required=True)
|
||||||
|
parser.add_argument('-l', '--linux', required=False)
|
||||||
|
parser.add_argument('-e', '--extra-dir', required=False)
|
||||||
|
parser.add_argument('-k', '--main-kit', required=False)
|
||||||
|
parser.add_argument('-w', '--winpe', required=False)
|
||||||
|
parser.add_argument(
|
||||||
|
'-d', '--debug', action='store_true',
|
||||||
|
help='Enable debug mode',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-M', '--use-mbr', action='store_true',
|
||||||
|
help='Use real MBR instead of GPT w/ Protective MBR',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-F', '--force', action='store_true',
|
||||||
|
help='Bypass all confirmation messages. USE WITH EXTREME CAUTION!',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-U', '--update', action='store_true',
|
||||||
|
help="Don't format device, just update",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'EXTRA_IMAGES', nargs='*',
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
legacy_args = {
|
||||||
|
'--debug': args.debug,
|
||||||
|
'--extra-dir': args.extra_dir,
|
||||||
|
'--force': args.force,
|
||||||
|
'--linux': args.linux,
|
||||||
|
'--main-kit': args.main_kit,
|
||||||
|
'--ufd-device': args.ufd_device,
|
||||||
|
'--update': args.update,
|
||||||
|
'--use-mbr': args.use_mbr,
|
||||||
|
'--winpe': args.winpe,
|
||||||
|
'EXTRA_IMAGES': args.extra_images,
|
||||||
|
}
|
||||||
|
return legacy_args
|
||||||
|
|
||||||
def apply_image(part_path, image_path, hide_macos_boot=True) -> None:
|
def apply_image(part_path, image_path, hide_macos_boot=True) -> None:
|
||||||
"""Apply raw image to dev_path using dd."""
|
"""Apply raw image to dev_path using dd."""
|
||||||
cmd = [
|
cmd = [
|
||||||
|
|
@ -93,7 +116,12 @@ def apply_image(part_path, image_path, hide_macos_boot=True) -> None:
|
||||||
|
|
||||||
def build_ufd() -> None:
|
def build_ufd() -> None:
|
||||||
"""Build UFD using selected sources."""
|
"""Build UFD using selected sources."""
|
||||||
args = docopt(DOCSTRING)
|
try:
|
||||||
|
args = argparse_helper()
|
||||||
|
except SystemExit:
|
||||||
|
print('')
|
||||||
|
ui.pause('Press Enter to exit...')
|
||||||
|
raise
|
||||||
if args['--debug']:
|
if args['--debug']:
|
||||||
log.enable_debug_mode()
|
log.enable_debug_mode()
|
||||||
if args['--update'] and args['EXTRA_IMAGES']:
|
if args['--update'] and args['EXTRA_IMAGES']:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue