Skip to content
Snippets Groups Projects
Commit feacaef7 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-544: Improve LibConfiguration parsing, and return a dict instead of list...

L2SS-544: Improve LibConfiguration parsing, and return a dict instead of list to avoid needing to use indices to indicate specific values
parent 813fc198
No related branches found
No related tags found
1 merge request!199L2SS-544: Improve LibConfiguration parsing, and return a dict instead of list...
...@@ -80,27 +80,25 @@ class Archiver(): ...@@ -80,27 +80,25 @@ class Archiver():
except Exception as e: except Exception as e:
raise Exception("Error in selecting configuration. Archiving framework will not be updated.") from e raise Exception("Error in selecting configuration. Archiving framework will not be updated.") from e
def get_db_config(self, device_name:str): def get_db_config(self, device_name:str) -> dict:
""" """
Retrieve the DB credentials from the Tango properties of Configuration Manager or EventSubscribers Retrieve the DB credentials from the Tango properties of Configuration Manager or EventSubscribers
""" """
device = DeviceProxy(device_name) device = DeviceProxy(device_name)
config_list = device.get_property('LibConfiguration')['LibConfiguration'] # dictionary {'LibConfiguration': list of strings} # example LibConfiguration property value:
host = str([s for s in config_list if "host" in s][0].split('=')[1]) # ['connect_string= user=postgres password=password host=archiver-timescale port=5432 dbname=hdb', 'host=archiver-timescale', 'libname=libhdb++timescale.so', 'dbname=hdb', 'port=5432', 'user=postgres', 'password=password']
libname = str([s for s in config_list if "libname" in s][0].split('=')[1]) config_strs = device.get_property('LibConfiguration')['LibConfiguration']
dbname = str([s for s in config_list if "dbname" in s][0].split('=')[1])
port = str([s for s in config_list if "port" in s][0].split('=')[1]) config = dict(config_str.split("=",1) for config_str in config_strs)
user = str([s for s in config_list if "user" in s][0].split('=')[1]) return config
pw = str([s for s in config_list if "password" in s][0].split('=')[1])
return [host,libname,dbname,port,user,pw]
def get_hdbpp_libname(self, device_name:str): def get_hdbpp_libname(self, device_name:str):
""" """
Get the hdbpp library name used by the Configuration Manager or by the EventSubscribers Get the hdbpp library name used by the Configuration Manager or by the EventSubscribers
Useful in the case of different DBMS architectures (e.g. MySQL, TimescaleDB) Useful in the case of different DBMS architectures (e.g. MySQL, TimescaleDB)
""" """
config_list = self.get_db_config(device_name) config = self.get_db_config(device_name)
return config_list[1] return config["libname"]
def get_subscribers(self, from_db:bool=False): def get_subscribers(self, from_db:bool=False):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment