Merge pull request #465 from dipsylala/master
Added exception handling to config.yml parsing
This commit is contained in:
commit
03b85ac66b
@ -65,12 +65,16 @@ def load_config(args):
|
|||||||
config = yaml.safe_load(fp)
|
config = yaml.safe_load(fp)
|
||||||
|
|
||||||
# load the user config
|
# load the user config
|
||||||
if os.path.exists(args.user_config):
|
try:
|
||||||
with open(args.user_config) as fp:
|
if os.path.exists(args.user_config):
|
||||||
user_config = yaml.safe_load(fp)
|
with open(args.user_config) as fp:
|
||||||
# if the file is empty, safe_load will return None and merge_config will boom.
|
user_config = yaml.safe_load(fp)
|
||||||
if user_config:
|
# if the file is empty, safe_load will return None and merge_config will boom.
|
||||||
config = merge_config(user_config, config)
|
if user_config:
|
||||||
|
config = merge_config(user_config, config)
|
||||||
|
except yaml.YAMLError as ex:
|
||||||
|
print("There was an error processing the configuration file:\n%s " % ex)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# the very first step is to normalize the display name so we don't need dozens of if/elif around
|
# the very first step is to normalize the display name so we don't need dozens of if/elif around
|
||||||
if config['ui']['display']['type'] in ('inky', 'inkyphat'):
|
if config['ui']['display']['type'] in ('inky', 'inkyphat'):
|
||||||
|
@ -87,8 +87,7 @@ def append_images(images, horizontal=True, xmargin=0, ymargin=0):
|
|||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="This program emulates\
|
parser = argparse.ArgumentParser(description="This program emulates\
|
||||||
the pwnagotchi display")
|
the pwnagotchi display")
|
||||||
parser.add_argument('--displays', help="Which displays to use.", nargs="+",
|
parser.add_argument('--displays', help="Which displays to use.", nargs="+", default=["waveshare_2"])
|
||||||
default="waveshare_2")
|
|
||||||
parser.add_argument('--lang', help="Language to use",
|
parser.add_argument('--lang', help="Language to use",
|
||||||
default="en")
|
default="en")
|
||||||
parser.add_argument('--output', help="Path to output image (PNG)", default="preview.png")
|
parser.add_argument('--output', help="Path to output image (PNG)", default="preview.png")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user