Skip to content

Commit 62d3bc9

Browse files
committed
robogrator: Inherit config values from parent project(s)
Start reading config values from root and merge changes defined later in project path.
1 parent 0b07383 commit 62d3bc9

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

launchers/robogrator.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@
66
from glob import iglob
77
import json
88

9+
def merge_config(config_path):
10+
""" takes full path to config file requested. Tries to read that file
11+
from root dir and then overwrite value if they are defined later in
12+
project hierarcy.
13+
"""
14+
15+
conf_look_path = ""
16+
final_config = None
17+
path, conf_filename = os.path.split(config_path)
18+
19+
# start looking / reading conf file from the root dir and
20+
# then add / modify keys found from childer
21+
for p in path.split(os.sep):
22+
conf_look_path = os.path.join(conf_look_path, p)
23+
mconf = os.path.join(conf_look_path, conf_filename)
24+
if os.path.exists(mconf):
25+
with open(mconf, 'r') as config_file:
26+
lines = [line.strip() if not line.strip().startswith('#') else \
27+
"" for line in config_file.readlines()]
28+
config = json.loads("\n".join(lines))
29+
if not final_config:
30+
final_config = config
31+
else:
32+
# overwrite keys in base config
33+
for key, value in config.items():
34+
final_config[key] = value
35+
return final_config
936

1037
class ParticipantHandler(object):
1138

@@ -169,11 +196,7 @@ def get_process(self, trigger, project):
169196
continue
170197

171198
try:
172-
config = None
173-
with open("%s.conf" % filename[:-5], 'r') as config_file:
174-
lines = [line.strip() if not line.strip().startswith('#') \
175-
else "" for line in config_file.readlines()]
176-
config = json.loads("\n".join(lines))
199+
config = merge_config("%s.conf" % filename[:-5])
177200
self.log.info("Found valid conf %s.conf" % filename[:-5])
178201
except IOError as exc:
179202
# we don't care if there is no .conf file

0 commit comments

Comments
 (0)