From bcdbf41bb8a3c753f1992b99c6fea4d2935b3423 Mon Sep 17 00:00:00 2001 From: Dispsylala Date: Tue, 29 Oct 2019 22:38:41 +0000 Subject: [PATCH 1/2] Added exception handling to config.yml parsing/merging --- pwnagotchi/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pwnagotchi/utils.py b/pwnagotchi/utils.py index c474ae2..7c374e3 100644 --- a/pwnagotchi/utils.py +++ b/pwnagotchi/utils.py @@ -65,12 +65,16 @@ def load_config(args): config = yaml.safe_load(fp) # load the user config - if os.path.exists(args.user_config): - with open(args.user_config) as fp: - user_config = yaml.safe_load(fp) - # if the file is empty, safe_load will return None and merge_config will boom. - if user_config: - config = merge_config(user_config, config) + try: + if os.path.exists(args.user_config): + with open(args.user_config) as fp: + user_config = yaml.safe_load(fp) + # if the file is empty, safe_load will return None and merge_config will boom. + 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 if config['ui']['display']['type'] in ('inky', 'inkyphat'): From 5255e5fd137297a8e41ce14076f4b226324b73c3 Mon Sep 17 00:00:00 2001 From: Dispsylala Date: Wed, 30 Oct 2019 01:05:58 +0000 Subject: [PATCH 2/2] Fix default setting to be an array, otherwise the iterator works over characters, not strings. --- scripts/preview.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/preview.py b/scripts/preview.py index c338db7..719d1fb 100755 --- a/scripts/preview.py +++ b/scripts/preview.py @@ -87,8 +87,7 @@ def append_images(images, horizontal=True, xmargin=0, ymargin=0): def main(): parser = argparse.ArgumentParser(description="This program emulates\ the pwnagotchi display") - parser.add_argument('--displays', help="Which displays to use.", nargs="+", - default="waveshare_2") + parser.add_argument('--displays', help="Which displays to use.", nargs="+", default=["waveshare_2"]) parser.add_argument('--lang', help="Language to use", default="en") parser.add_argument('--output', help="Path to output image (PNG)", default="preview.png")