From 94b01b2fc7f0cf015cd674835774856e6ce3f083 Mon Sep 17 00:00:00 2001 From: Sniffleupagus Date: Sat, 8 Mar 2025 13:25:32 -0800 Subject: [PATCH 1/2] get_bbox fails on 2.9.5. get_size works --- pwnagotchi/ui/hw/dummydisplay.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/ui/hw/dummydisplay.py b/pwnagotchi/ui/hw/dummydisplay.py index fde83696..e6eae681 100644 --- a/pwnagotchi/ui/hw/dummydisplay.py +++ b/pwnagotchi/ui/hw/dummydisplay.py @@ -7,6 +7,7 @@ from pwnagotchi.ui.hw.base import DisplayImpl class DummyDisplay(DisplayImpl): def __init__(self, config): super(DummyDisplay, self).__init__(config, 'DummyDisplay') + self._display = self def layout(self): width = 480 if 'width' not in self.config else self.config['width'] @@ -25,7 +26,7 @@ class DummyDisplay(DisplayImpl): self._layout['friend_name'] = (int(width/12), int(height/10)) self._layout['shakes'] = (0, height-int(height/25)) self._layout['mode'] = (width-int(width/8), height - int (height/25)) - lw, lh = fonts.Small.getbbox("W") + lw, lh = fonts.Small.getsize("W") self._layout['status'] = { 'pos': (int(width/48), int(height/3)), 'font': fonts.status_font(fonts.Small), From dbcc4889000afc60079aaccd38c1e7f1ad95f837 Mon Sep 17 00:00:00 2001 From: Sniffleupagus Date: Sat, 8 Mar 2025 13:26:13 -0800 Subject: [PATCH 2/2] Load dotted toml files with old toml library, new ones with tomlkit to preserve format and comments --- pwnagotchi/utils.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/pwnagotchi/utils.py b/pwnagotchi/utils.py index bce1e3d4..727b28ce 100644 --- a/pwnagotchi/utils.py +++ b/pwnagotchi/utils.py @@ -151,10 +151,33 @@ def load_config(args): print("!!! file in %s is different than release defaults, overwriting !!!" % args.config) shutil.copy(ref_defaults_file, args.config) + + def load_toml_file(filename): + """Load toml data from a file. Use toml for dotted, tomlkit for nice formatted""" + with open(filename) as fp: + text = fp.read() + # look for "[main]". if not there, then load + # dotted toml with toml instead of tomlkit + if text.find("[main]") != -1: + return tomlkit.loads(text) + else: + print("Converting dotted toml %s: %s" % (filename, text[0:100])) + import toml + data = toml.loads(text) + # save original as a backup + try: + backup = filename + ".ORIG" + os.rename(filename, backup) + with open(filename, "w") as fp2: + tomlkit.dump(data, fp2) + print("Converted to new format. Original saved at %s" % backup) + except Exception as e: + print("Unable to convert %s to new format: %s" % (backup, e)) + return data + # load the defaults - with open(args.config) as fp: - config = tomlkit.load(fp) - #config = toml.load(fp) + config = load_toml_file(args.config) + # load the user config try: @@ -173,9 +196,7 @@ def load_config(args): # toml.dump(user_config, toml_file) tomlkit.dump(user_config, toml_file) elif os.path.exists(args.user_config): - with open(args.user_config) as toml_file: - # user_config = toml.load(toml_file) - user_config = tomlkit.load(toml_file) + user_config = load_toml_file(args.user_config) if user_config: config = merge_config(user_config, config) @@ -188,10 +209,8 @@ def load_config(args): if dropin and os.path.isdir(dropin): dropin += '*.toml' if dropin.endswith('/') else '/*.toml' # only toml here; yaml is no more for conf in glob.glob(dropin): - with open(conf) as toml_file: - # additional_config = toml.load(toml_file) - additional_config = tomlkit.load(toml_file) - config = merge_config(additional_config, config) + additional_config = load_toml_file(conf) + config = merge_config(additional_config, config) # the very first step is to normalize the display name, so we don't need dozens of if/elif around # Dummy Display -------------------------------------------------------------------