Fixed source validation

This commit is contained in:
2Shirt 2019-04-08 00:35:53 -07:00
parent b166172d10
commit 4c33c110b7
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 50 additions and 33 deletions

View file

@ -7,6 +7,7 @@ import sys
# Init # Init
sys.path.append(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from collections import OrderedDict
from docopt import docopt from docopt import docopt
from functions.ufd import * from functions.ufd import *
from settings.ufd import * from settings.ufd import *
@ -18,33 +19,39 @@ set_log_file('Build UFD ({Date-Time}).log'.format(**global_vars))
if __name__ == '__main__': if __name__ == '__main__':
try: try:
args = docopt(DOCSTRING) args = docopt(DOCSTRING)
sources = () sources = OrderedDict()
# Verify selections # Verify selections
## UFD ## UFD
try: try:
ufd_dev = get_full_path(args['--ufd-device']) ufd_dev = find_path(args['--ufd-device'])
if not is_block_device(ufd_dev): except FileNotFoundError:
print_error('Invalid UFD device: {}'.format(ufd_dev)) print_error('ERROR: UFD device not found: {}'.format(
abort() args['--ufd-device']))
except Exception: abort()
# TODO Catch FileNotFound exception and abort accordingly if not is_valid_path(ufd_dev, 'UFD'):
raise print_error('ERROR: Invalid UFD device: {}'.format(ufd_dev))
abort()
## Sources ## Sources
for label, source in UFD_SOURCES: for label, data in UFD_SOURCES.items():
if args[source]: s_path = args[data['Arg']]
if s_path:
try: try:
sources.append((label, get_full_path(source))) s_path_obj = find_path(s_path)
except Exception: except FileNotFoundError:
# TODO Catch FileNotFound exception and abort accordingly print_error('ERROR: {} not found: {}'.format(label, s_path))
raise abort()
if not is_valid_path(s_path_obj, data['Type']):
print_error('ERROR: Invalid {} source: {}'.format(label, s_path))
abort()
sources[label] = s_path_obj
# Show selections # Show selections
# TODO FIXME # TODO FIXME
print_standard('UFD: {}'.format(ufd_dev)) print_standard('UFD: {}'.format(ufd_dev))
print_standard('Sources:') print_standard('Sources:')
for s in sources: for label, s_path in sources.items():
print_standard(' {}: {}'.format(*s)) print_standard(' {:<16} {}'.format(label+':', s_path))
# Double-check if formating device # Double-check if formating device

View file

@ -60,9 +60,19 @@ def find_path(path):
return path_obj return path_obj
def is_valid_main_kit(path_obj): def is_valid_path(path_obj, path_type):
"""Verify PathObj contains the main kit, returns bool.""" """Verify path_obj is valid by type, returns bool."""
return path_obj.is_dir() and path_obj.joinpath('.bin').exists() valid_path = False
if path_type == 'DIR':
valid_path = path_obj.is_dir()
elif path_type == 'KIT':
valid_path = path_obj.is_dir() and path_obj.joinpath('.bin').exists()
elif path_type == 'ISO':
valid_path = path_obj.is_file() and path_obj.suffix.lower() == '.iso'
elif path_type == 'UFD':
valid_path = path_obj.is_block_device()
return valid_path
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,25 +1,26 @@
# Wizard Kit: Settings - UFD # Wizard Kit: Settings - UFD
from collections import OrderedDict
from settings.main import * from settings.main import *
# General # General
DOCSTRING = '''WizardKit: Build UFD DOCSTRING = '''WizardKit: Build UFD
Usage: Usage:
build-ufd [options] --ufd-device PATH --linux-iso PATH build-ufd [options] --ufd-device PATH --linux PATH
[--linux-minimal-iso PATH] [--linux-minimal PATH]
[--main-kit PATH] [--main-kit PATH]
[--winpe-iso PATH] [--winpe PATH]
[--extra-dir PATH] [--extra-dir PATH]
build-ufd (-h | --help) build-ufd (-h | --help)
Options: Options:
-e PATH, --extra-dir PATH -e PATH, --extra-dir PATH
-k PATH, --main-kit PATH -k PATH, --main-kit PATH
-l PATH, --linux-iso PATH -l PATH, --linux PATH
-m PATH, --linux-minimal-iso PATH -m PATH, --linux-minimal PATH
-u PATH, --ufd-device PATH -u PATH, --ufd-device PATH
-w PATH, --winpe-iso PATH -w PATH, --winpe PATH
-d --debug Enable debug mode -d --debug Enable debug mode
-h --help Show this page -h --help Show this page
@ -30,14 +31,13 @@ Options:
''' '''
ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT) ISO_LABEL = '{}_LINUX'.format(KIT_NAME_SHORT)
UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT) UFD_LABEL = '{}_UFD'.format(KIT_NAME_SHORT)
UFD_SOURCES = ( UFD_SOURCES = ({
# NOTE: Using tuple of tuples to ensure copy order 'Linux': {'Arg': '--linux', 'Type': 'ISO'},
('Linux', '--linux-iso'), 'Linux (Minimal)': {'Arg': '--linux-minimal', 'Type': 'ISO'},
('Linux (Minimal)', '--linux-minimal-iso'), 'WinPE': {'Arg': '--winpe', 'Type': 'ISO'},
('WinPE', '--winpe-iso'), 'Main Kit': {'Arg': '--main-kit', 'Type': 'KIT'},
('Main Kit', '--main-kit'), 'Extra Dir': {'Arg': '--extra-dir', 'Type': 'DIR'},
('Extras', '--extra-dir'), })
)
# Definitions: Boot entries # Definitions: Boot entries
## NOTE: if key path exists uncomment #value# lines ## NOTE: if key path exists uncomment #value# lines