Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 7fcd35b

Browse files
committed
A new function (add_base_path) used to add a basepath to paths specificed in a configuration.
1 parent 3ae1c0d commit 7fcd35b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/oidcmsg/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,33 @@ def proper_path(path):
2929
path += "/"
3030

3131
return path
32+
33+
34+
# This is for adding a base path to path specified in a configuration
35+
def add_base_path(conf, item_paths, base_path):
36+
for section, items in item_paths.items():
37+
if section == "":
38+
part = conf
39+
else:
40+
part = conf.get(section)
41+
42+
if part:
43+
if isinstance(items, list):
44+
for attr in items:
45+
_path = part.get(attr)
46+
if _path:
47+
if _path.startswith("/"):
48+
continue
49+
elif _path == "":
50+
part[attr] = "./" + _path
51+
else:
52+
part[attr] = os.path.join(base_path, _path)
53+
elif items is None:
54+
if part.startswith("/"):
55+
continue
56+
elif part == "":
57+
conf[section] = "./"
58+
else:
59+
conf[section] = os.path.join(base_path, part)
60+
else: # Assume items is dictionary like
61+
add_base_path(part, items, base_path)

0 commit comments

Comments
 (0)