diff --git a/tangostationcontrol/tangostationcontrol/common/configuration.py b/tangostationcontrol/tangostationcontrol/common/configuration.py index 9a028d06b22daac3f206543bb5f33335103d3f5f..58de159095784293fec060d6040318b54faa195e 100644 --- a/tangostationcontrol/tangostationcontrol/common/configuration.py +++ b/tangostationcontrol/tangostationcontrol/common/configuration.py @@ -1,3 +1,11 @@ +# +# Code re-adapted from dsconfig python package in DSConfig container +# See: https://gitlab.com/MaxIV/lib-maxiv-dsconfig +# License: GPLv3 +# + +from tango import DeviceProxy + from collections import defaultdict import six try: @@ -10,6 +18,18 @@ except ImportError: from collections import Mapping from itertools import islice +def get_db_data(db): + # dump TANGO database into JSON. Optionally filter which things to include + # (currently only "positive" filters are possible; you can say which + # servers/classes/devices to include, but you can't exclude selectively) + # By default, dserver devices aren't included! + dbproxy = DeviceProxy(db.dev_name()) + data = SetterDict() + # the user did not specify a pattern, so we will dump *everything* + servers = get_servers_with_filters(dbproxy) + data.servers.update(servers) + return data.to_dict() + def get_servers_with_filters(dbproxy, server="*", clss="*", device="*", properties=True, attribute_properties=True, aliases=True, dservers=False, @@ -239,7 +259,7 @@ class SetterDict(CaselessDictionary, defaultdict): def __init__(self, value=None, factory=None): factory = factory or SetterDict - value = {} + value = value or {} self.__dict__["_factory"] = factory CaselessDictionary.__init__(self) defaultdict.__init__(self, factory) diff --git a/tangostationcontrol/tangostationcontrol/devices/configuration_device.py b/tangostationcontrol/tangostationcontrol/devices/configuration_device.py index 7f5092354c0e73eea5787b52599c3ad0a1f5211a..2d6c69722cae1a524e289b6e8aad8b61deeff84a 100644 --- a/tangostationcontrol/tangostationcontrol/devices/configuration_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/configuration_device.py @@ -13,11 +13,11 @@ Handles and exposes the station configuration """ # PyTango imports -from tango import AttrWriteType, Database, DeviceProxy +from tango import AttrWriteType, Database from tango.server import attribute # Additional import -from tangostationcontrol.common.configuration import SetterDict, get_servers_with_filters +from tangostationcontrol.common.configuration import get_db_data from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.devices.lofar_device import lofar_device from tangostationcontrol.common.lofar_logging import device_logging_to_python @@ -48,17 +48,14 @@ class Configuration(lofar_device): N.B. it does not update, it loads a full new configuration. """ - # TODO(Stefano): implement load configuration + # TODO(Stefano): L2SS-1031 implement load configuration self.proxy.tangodb_properties_RW = tangodb_properties def _dump_configdb(self): """ Returns the TangoDB station configuration as a JSON string """ - dbproxy = DeviceProxy(Database().dev_name()) - # Create a special dictionary to prevent Tango case errors - data = SetterDict() - servers = get_servers_with_filters(dbproxy) - data.servers.update(servers) - return json.dumps(data.to_dict(), ensure_ascii=False, indent=4, sort_keys=True) + db = Database() # TangoDB + dbdata = get_db_data(db) + return json.dumps(dbdata, ensure_ascii=False, indent=4, sort_keys=True) # ----------