From 8e606a13c4335d82451bb2dd541ecbff7b41cb7f Mon Sep 17 00:00:00 2001 From: Piotr Goryl Date: Mon, 7 Jan 2019 14:43:45 +0100 Subject: [PATCH 1/2] Class properties dump implemented. --- dsconfig/dump.py | 34 +++++++++++++++++++++++++++++++++- dsconfig/tangodb.py | 1 + setup.py | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/dsconfig/dump.py b/dsconfig/dump.py index 2a7a859..480cb2e 100755 --- a/dsconfig/dump.py +++ b/dsconfig/dump.py @@ -37,6 +37,33 @@ def get_db_data(db, patterns=None, **options): servers = get_servers_with_filters(dbproxy, **kwargs) data.servers.update(servers) + # dump class properties upon request + if options.get('class_properties', False): + # go through all classes in servers + for server, instances in data.servers.to_dict().items(): + for instance, classes in instances.items(): + for cls, devices in classes.items(): + # skip classes already dump + if cls not in data.classes.keys(): + # class properties + print db.get_class_property_list(cls).value_string + for prop, value in db.get_class_property(cls, list(db.get_class_property_list(cls))).items(): + + if value: + value = [str(v) for v in value] + data.classes[cls].properties[prop] = value + + # attribute properties + if not options.get('attribute_properties', False): + attr_props = db.get_class_attribute_property( + cls, + list(db.get_class_attribute_list(cls,'*')) + ) + for attr, props in attr_props.items(): + props = dict((prop, [str(v) for v in values]) + for prop, values in props.items()) + data.classes[cls].attribute_properties[attr] = props + return data.to_dict() @@ -62,6 +89,10 @@ def main(): parser.add_option("-s", "--subdevices", dest="subdevices", action="store_true", default=False, help="Include __SubDevices property") + parser.add_option("-c", "--class-properties", + dest="class_properties", + action="store_true", default=False, + help="Include class properties") options, args = parser.parse_args() @@ -70,7 +101,8 @@ def main(): properties=options.properties, attribute_properties=options.attribute_properties, aliases=options.aliases, dservers=options.dservers, - subdevices=options.subdevices) + subdevices=options.subdevices, + class_properties=options.class_properties) print json.dumps(dbdata, ensure_ascii=False, indent=4, sort_keys=True) diff --git a/dsconfig/tangodb.py b/dsconfig/tangodb.py index f2a8494..a752e5a 100755 --- a/dsconfig/tangodb.py +++ b/dsconfig/tangodb.py @@ -334,6 +334,7 @@ def maybe_upper(s, upper=False): def get_servers_with_filters(dbproxy, server="*", clss="*", device="*", properties=True, attribute_properties=True, + class_properties=False, aliases=True, dservers=False, subdevices=False, uppercase_devices=False, timeout=10): diff --git a/setup.py b/setup.py index ed7286b..d64cdeb 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( # Package name="python-dsconfig", - version="1.2.3", + version="1.2.4", packages=['dsconfig', 'dsconfig.appending_dict'], description="Library and utilities for Tango device configuration.", # Requirements From aff9f5ba4a5e8ea21f25cbf014f21a510e4bceb7 Mon Sep 17 00:00:00 2001 From: Piotr Goryl Date: Mon, 7 Jan 2019 15:22:01 +0100 Subject: [PATCH 2/2] Debug print removed... --- dsconfig/dump.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dsconfig/dump.py b/dsconfig/dump.py index 480cb2e..6078885 100755 --- a/dsconfig/dump.py +++ b/dsconfig/dump.py @@ -46,9 +46,7 @@ def get_db_data(db, patterns=None, **options): # skip classes already dump if cls not in data.classes.keys(): # class properties - print db.get_class_property_list(cls).value_string for prop, value in db.get_class_property(cls, list(db.get_class_property_list(cls))).items(): - if value: value = [str(v) for v in value] data.classes[cls].properties[prop] = value