mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Merge pull request #367 from Sniffleupagus/toml_two_times_baby
Toml two times baby
This commit is contained in:
@ -7,6 +7,7 @@ from pwnagotchi.ui.hw.base import DisplayImpl
|
|||||||
class DummyDisplay(DisplayImpl):
|
class DummyDisplay(DisplayImpl):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
super(DummyDisplay, self).__init__(config, 'DummyDisplay')
|
super(DummyDisplay, self).__init__(config, 'DummyDisplay')
|
||||||
|
self._display = self
|
||||||
|
|
||||||
def layout(self):
|
def layout(self):
|
||||||
width = 480 if 'width' not in self.config else self.config['width']
|
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['friend_name'] = (int(width/12), int(height/10))
|
||||||
self._layout['shakes'] = (0, height-int(height/25))
|
self._layout['shakes'] = (0, height-int(height/25))
|
||||||
self._layout['mode'] = (width-int(width/8), 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'] = {
|
self._layout['status'] = {
|
||||||
'pos': (int(width/48), int(height/3)),
|
'pos': (int(width/48), int(height/3)),
|
||||||
'font': fonts.status_font(fonts.Small),
|
'font': fonts.status_font(fonts.Small),
|
||||||
|
@ -151,10 +151,33 @@ def load_config(args):
|
|||||||
print("!!! file in %s is different than release defaults, overwriting !!!" % args.config)
|
print("!!! file in %s is different than release defaults, overwriting !!!" % args.config)
|
||||||
shutil.copy(ref_defaults_file, 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
|
# load the defaults
|
||||||
with open(args.config) as fp:
|
config = load_toml_file(args.config)
|
||||||
config = tomlkit.load(fp)
|
|
||||||
#config = toml.load(fp)
|
|
||||||
|
|
||||||
# load the user config
|
# load the user config
|
||||||
try:
|
try:
|
||||||
@ -173,9 +196,7 @@ def load_config(args):
|
|||||||
# toml.dump(user_config, toml_file)
|
# toml.dump(user_config, toml_file)
|
||||||
tomlkit.dump(user_config, toml_file)
|
tomlkit.dump(user_config, toml_file)
|
||||||
elif os.path.exists(args.user_config):
|
elif os.path.exists(args.user_config):
|
||||||
with open(args.user_config) as toml_file:
|
user_config = load_toml_file(args.user_config)
|
||||||
# user_config = toml.load(toml_file)
|
|
||||||
user_config = tomlkit.load(toml_file)
|
|
||||||
|
|
||||||
if user_config:
|
if user_config:
|
||||||
config = merge_config(user_config, config)
|
config = merge_config(user_config, config)
|
||||||
@ -188,10 +209,8 @@ def load_config(args):
|
|||||||
if dropin and os.path.isdir(dropin):
|
if dropin and os.path.isdir(dropin):
|
||||||
dropin += '*.toml' if dropin.endswith('/') else '/*.toml' # only toml here; yaml is no more
|
dropin += '*.toml' if dropin.endswith('/') else '/*.toml' # only toml here; yaml is no more
|
||||||
for conf in glob.glob(dropin):
|
for conf in glob.glob(dropin):
|
||||||
with open(conf) as toml_file:
|
additional_config = load_toml_file(conf)
|
||||||
# additional_config = toml.load(toml_file)
|
config = merge_config(additional_config, config)
|
||||||
additional_config = tomlkit.load(toml_file)
|
|
||||||
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
|
# the very first step is to normalize the display name, so we don't need dozens of if/elif around
|
||||||
# Dummy Display -------------------------------------------------------------------
|
# Dummy Display -------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user