55from xml .etree .ElementTree import parse
66
77from pbpy import pbtools
8+ from pbpy import pblog
89
910# Singleton Config and path to said config
1011config = None
@@ -17,9 +18,36 @@ def get(key):
1718 if key is None or config is None or config .get (str (key )) is None :
1819 pbtools .error_state (f"Invalid config get request: { key } " , hush = True )
1920 val = config .get (str (key ))
20- if val == "" :
21+ # this should be checked by missing_keys in pbsync_config_parser_func, but checking here just in case
22+ # TODO: remove?
23+ if val is None :
2124 pbtools .error_state (f"{ key } is not set in config" , hush = True )
22-
25+ # We checked None values that distingiush something is a required key and must be set at startup
26+ # now, we can check for empty values which we can translate into a None to represent an unset value
27+ # this allows more flexibility in type handling for None values rather empty strings
28+ if isinstance (val , str ):
29+ if val == "" :
30+ pblog .warning (f"{ key } is not set in config" )
31+ # TODO: replace with None for type handling
32+ #val = None
33+ else :
34+ # strip to allow for xml formatting
35+ val = val .strip ()
36+ elif isinstance (val , list ):
37+ if len (val ) < 1 :
38+ pblog .warning (f"{ key } is not set in config" )
39+ # TODO: should we replace empty lists with None?
40+ #val = None
41+ else :
42+ for idx in range (len (val )):
43+ item = val [idx ]
44+ if val == "" :
45+ pblog .warning (f"{ key } [{ idx } ] is not set in config" )
46+ # TODO: replace with None for type handling
47+ #val[idx] = None
48+ else :
49+ # strip to allow for xml formatting
50+ val = val .strip ()
2351 return val
2452
2553
0 commit comments