Commit 282540c5898396f85d14c8615d7c6fe7d79f5af3
1 parent
e90f64fc
Exists in
dev
Config class: improving inheritance of capabilities, and improving management of enum values
Showing
1 changed file
with
21 additions
and
13 deletions
Show diff stats
src/core/pyros_django/obsconfig/configpyros.py
... | ... | @@ -195,17 +195,11 @@ class ConfigPyros: |
195 | 195 | |
196 | 196 | # for each attributes of generic component attributes |
197 | 197 | for attribute_name in attributes.keys(): |
198 | - if "is_Enum" in component_attributes[attribute_name].keys(): | |
199 | - # check if value of this attribute is in Enum of general component attribute definition | |
200 | - enum_values = component_attributes[attribute_name]["value"] | |
201 | - if attributes[attribute_name]["value"][0] in enum_values: | |
202 | - # merge attributes of general component with specified component in device config file | |
203 | - new_attributes = {**component_attributes[attribute_name],**attributes[attribute_name]} | |
204 | - else: | |
205 | - print(f"Error in file {self.current_file} : attribute \"{attribute_name}\" isn't in enum. Accepted values for this attribute : \"{enum_values}\"") | |
206 | - exit(1) | |
207 | 198 | # merge attributes of general component with specified component in device config file |
208 | 199 | new_attributes = {**component_attributes[attribute_name],**attributes[attribute_name]} |
200 | + if "is_enum" in component_attributes[attribute_name].keys(): | |
201 | + # make an intersection of both list of values | |
202 | + new_attributes["value"] = list(set(attributes[attribute_name]["value"]) & set(component_attributes[attribute_name]["value"])) | |
209 | 203 | component_attributes[attribute_name] = new_attributes |
210 | 204 | |
211 | 205 | # return inherited and overwritten attributes of capability |
... | ... | @@ -279,24 +273,37 @@ class ConfigPyros: |
279 | 273 | if generic_device_config != None: |
280 | 274 | # we're making a copy of generic device config so we can remove items during loop |
281 | 275 | copy_generic_device_config = generic_device_config.copy() |
282 | - # We have to extend capabilities of generic device configuration's capabilities | |
276 | + # We have to extend capabilities of generic device configuration | |
283 | 277 | for capability in current_config["DEVICE"]["CAPABILITIES"]: |
284 | 278 | is_capability_in_generic_config = False |
285 | 279 | current_config_capability = capability["CAPABILITY"] |
286 | 280 | current_config_component = current_config_capability["component"] |
287 | - current_config_capability = self.read_capability_of_device(current_config_capability) | |
288 | 281 | # find if this component was defined in generic_device_config |
289 | 282 | for index,generic_config_capability in enumerate(generic_device_config["DEVICE"]["CAPABILITIES"]): |
290 | 283 | # if the current capability is the capability of the component we're looking for |
291 | 284 | if current_config_component == generic_config_capability["component"]: |
292 | 285 | is_capability_in_generic_config = True |
293 | 286 | # we're merging their attributes |
294 | - merged_attributes = {**generic_config_capability["attributes"],**current_config_capability["attributes"]} | |
287 | + new_attributes = generic_config_capability["attributes"] | |
288 | + attributes = {} | |
289 | + current_config_attributes = current_config_capability["attributes"] | |
290 | + generic_config_attributes = generic_config_capability["attributes"] | |
291 | + for attribute in current_config_attributes: | |
292 | + attribute = attribute["attribute"] | |
293 | + attributes[attribute.pop("key")] = attribute | |
294 | + # for each attributes of device component attributes | |
295 | + for attribute_name in attributes.keys(): | |
296 | + # merge attributes of general component with specified component in device config file | |
297 | + new_attributes[attribute_name] = {**generic_config_attributes[attribute_name],**attributes[attribute_name]} | |
298 | + if "is_enum" in generic_config_attributes[attribute_name].keys(): | |
299 | + # make an intersection of both list of values | |
300 | + new_attributes[attribute_name]["value"] = list(set(attributes[attribute_name]["value"]) & set(generic_config_attributes[attribute_name]["value"])) | |
295 | 301 | # removing this capability from generic device configuration |
296 | 302 | generic_device_config["DEVICE"]["CAPABILITIES"].pop(index) |
297 | - capabilities.append({"component": current_config_component,"attributes":merged_attributes}) | |
303 | + capabilities.append({"component": current_config_component,"attributes":new_attributes}) | |
298 | 304 | break |
299 | 305 | if is_capability_in_generic_config == False: |
306 | + current_config_capability = self.read_capability_of_device(current_config_capability) | |
300 | 307 | # the component defined in the current_config isn't defined in generic config (should not happen but we'll deal with that case anyway) : we're simply adding this capability |
301 | 308 | capabilities.append(current_config_capability) |
302 | 309 | # looping through generic device config's capabilities in order to add them to current device configuration |
... | ... | @@ -777,6 +784,7 @@ def main(): |
777 | 784 | print(config.get_devices()["FLI-Kepler4040"]["device_config"]) |
778 | 785 | print(config.get_devices()["FLI-Kepler4040"]["device_config"]["CAPABILITIES"][1]["attributes"]["manufacturer"]) |
779 | 786 | print(config.get_devices()["FLI-Kepler4040"]["device_config"]["CAPABILITIES"]) |
787 | + print(config.get_devices()["AstroMecCA-TM350"]["device_config"]["CAPABILITIES"]) | |
780 | 788 | if __name__ == "__main__": |
781 | 789 | |
782 | 790 | main() |
783 | 791 | \ No newline at end of file | ... | ... |