From 82251214b814db66e83c821c625e1b586510c00e Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 7 Oct 2019 13:38:30 -0400 Subject: Improve theme validation --- src/theme.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/theme.py') diff --git a/src/theme.py b/src/theme.py index d83b6b5..943832c 100644 --- a/src/theme.py +++ b/src/theme.py @@ -1,4 +1,4 @@ -import yaml,re +import yaml,re, sys def configure(theme): if "colors" in theme: @@ -22,8 +22,27 @@ def configure(theme): theme["bar_colors"]=bar_colors return(theme) +def validate(theme): + abort=lambda msg: sys.exit("Error while loading theme: "+msg) + inv_key=lambda key: abort("invalid key \""+key+"\"") + for key,value in theme.items(): + if not(key in ["meta","colors","window_colors","bar_colors"]): + inv_key(key) + if key=="bar_colors": + for key,value in value.items(): + if not(key in ["separator","background","statusline", + "focused_workspace","active_workspace","inactive_workspace","urgent_workspace"]): + inv_key(key) + if key=="window_colors": + for key,value in value.items(): + if not(key in ["focused","focused_inactive","unfocused","urgent","child_border"]): + inv_key(key) + + def load(theme_file): f=open(theme_file,mode="r") theme=yaml.load(f,Loader=yaml.FullLoader) f.close() - return(configure(theme)) + theme=configure(theme) + validate(theme) + return(theme) -- cgit v1.2.3