reorganized config schema

This commit is contained in:
Noah Swerhun 2023-04-03 14:41:32 -05:00
parent 09be7cd6da
commit 90bbfcd7fe
2 changed files with 43 additions and 38 deletions

View file

@ -17,25 +17,26 @@ def main():
else: else:
config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml" config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml"
bar_config, module_config_list = get_bar_config_and_module_config_list(config_file) #bar_config, module_config_list = get_bar_config_and_module_config_list(config_file)
padding = bar_config["padding"] get_bar_config_and_module_config_list(config_file)
seperator = bar_config["seperator"] #padding = bar_config["padding"]
margin = bar_config["margin"] #seperator = bar_config["seperator"]
#margin = bar_config["margin"]
signal_router = SignalRouter() #signal_router = SignalRouter()
bar = Bar(seperator, margin) #bar = Bar(seperator, margin)
for module_config in module_config_list: #for module_config in module_config_list:
module = Module(module_config, padding, bar) # module = Module(module_config, padding, bar)
bar.add_module(module) # bar.add_module(module)
module.start_thread() # module.start_thread()
if module.signal != 0: # if module.signal != 0:
signal_router.register_signal_thread(module.signal, module.ident) # signal_router.register_signal_thread(module.signal, module.ident)
create_pidfile(pidfile_name()) #create_pidfile(pidfile_name())
signal(SIGTERM, sigterm_handler) #signal(SIGTERM, sigterm_handler)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -20,32 +20,35 @@ def get_bar_config_and_module_config_list(filename):
Optional("seperator", default="|"): str, Optional("seperator", default="|"): str,
Optional("margin", default=""): str Optional("margin", default=""): str
}, },
"modules": [ "monitor": {
{ And(int, lambda n: 0 <= n <= 9): {
"name": str, "modules": {
"command": str, str: {
"refresh": And(int, lambda n : n >= 0), "command": str,
Optional("prefix"): str, "refresh": And(int, lambda n : n >= 0),
Optional("signal"): And(int, lambda n : SIGRTMIN <= SIGRTMIN+n <= SIGRTMAX), Optional("prefix"): str,
"format": { Optional("signal"): And(int, lambda n : SIGRTMIN <= SIGRTMIN+n <= SIGRTMAX),
"align": Or("left", "center", "right"), "format": {
Optional("bg_color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$'), "align": Or("left", "center", "right"),
Optional("fg_color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$'), Optional("bg_color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$'),
Optional("font"): And(int, lambda n: 1 <= n <= 5), Optional("fg_color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$'),
Optional("offset"): int, Optional("font"): And(int, lambda n: 1 <= n <= 5),
Optional("line"): { Optional("offset"): int,
"type": Or("underline", "overline"), Optional("line"): {
Optional("color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$') "type": Or("underline", "overline"),
Optional("color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$')
}
# Not yet implemented.
#Optional("button"): {
# "activator": Or("left", "center", "right", "scrup", "scrdown"),
# "command": str
#}
}
} }
# Not yet implemented.
#Optional("button"): {
# "activator": Or("left", "center", "right", "scrup", "scrdown"),
# "command": str
#}
} }
} }
] }
} }
}) })
@ -54,6 +57,7 @@ def get_bar_config_and_module_config_list(filename):
try: try:
validated_config = config_schema.validate(config_file) validated_config = config_schema.validate(config_file)
return validated_config["bar"]["config"], validated_config["bar"]["modules"] return validated_config
#return validated_config["bar"]["config"], validated_config["bar"]["modules"]
except SchemaError as se: except SchemaError as se:
raise se raise se