Skip to content

Commit c7d0385

Browse files
authored
improve optional config handling
1 parent 25b4c86 commit c7d0385

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

pbpy/pbconfig.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from xml.etree.ElementTree import parse
66

77
from pbpy import pbtools
8+
from pbpy import pblog
89

910
# Singleton Config and path to said config
1011
config = 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

pbsync/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ def pbsync_config_parser_func(root):
885885
True,
886886
),
887887
"package_pdbs": ("project/packagepdbs", None, False, True),
888-
"publish_publishers": ("publish/publisher", None, [""], False),
888+
"publish_publishers": ("publish/publisher", None, [], False),
889889
"publish_stagedir": ("publish/stagedir", None, "Saved/StagedBuilds", True),
890890
"dispatch_config": ("dispatch/config", None, "", True),
891891
"butler_project": ("butler/project", None, "", True),

0 commit comments

Comments
 (0)