|
6 | 6 | from glob import iglob |
7 | 7 | import json |
8 | 8 |
|
| 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 |
9 | 36 |
|
10 | 37 | class ParticipantHandler(object): |
11 | 38 |
|
@@ -169,11 +196,7 @@ def get_process(self, trigger, project): |
169 | 196 | continue |
170 | 197 |
|
171 | 198 | 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]) |
177 | 200 | self.log.info("Found valid conf %s.conf" % filename[:-5]) |
178 | 201 | except IOError as exc: |
179 | 202 | # we don't care if there is no .conf file |
|
0 commit comments