-
Notifications
You must be signed in to change notification settings - Fork 5
Class properties dump implemented. #2
base: master
Are you sure you want to change the base?
Class properties dump implemented. #2
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Piotr,
Thanks for your contribution. Classes configuration is missing in the dsconfig and it is definitely useful to get this feature in the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is maybe worth it to move all the logic from dump.py
to tangodb.py
in is own function (like get_classes_properties
)
Maybe we can keep the same approach used for devices and servers configuration, withh advanced sql querries, and wildcard on server name:
def get_classes_properties(dbproxy, server='*', cls_properties=True,
cls_attribute_properties=True, timeout=10):
"""
Get all classes properties from server wildcard
"""
# Mysql wildcards
server = server.replace("*", "%")
# Change device proxy timeout
dbproxy.set_timeout_millis(timeout*1000)
# Classes output dict
classes = AppendingDict()
# Get class properties
if cls_properties:
querry = (
"select DISTINCT property_class.class, "
"property_class.name, "
"property_class.value "
"FROM property_class "
"INNER JOIN device "
"ON property_class.class = device.class "
"WHERE server like '%s' "
"AND device.class != 'DServer' "
"AND device.class != 'TangoAccessControl'")
_, result = dbproxy.command_inout("DbMySqlSelect", querry % (server))
# Build the output based on: class, property: value
for c, p, v in nwise(result, 3):
# the properties are encoded in latin-1; we want utf-8
decoded_value = v.decode('iso-8859-1').encode('utf8')
classes[c].properties[p] = decoded_value
# Get class attribute properties
if cls_attribute_properties:
querry = (
"select DISTINCT property_attribute_class.class, "
"property_attribute_class.attribute, "
"property_attribute_class.name, "
"property_attribute_class.value "
"FROM property_attribute_class "
"INNER JOIN device "
"ON property_attribute_class.class = device.class "
"WHERE server like '%s' "
"AND device.class != 'DServer' "
"AND device.class != 'TangoAccessControl'")
_, result = dbproxy.command_inout("DbMySqlSelect", querry % (server))
# Build output: class, attribute, property: value
for c, a, p, v in nwise(result, 4):
# the properties are encoded in latin-1; we want utf-8
decoded_value = v.decode('iso-8859-1').encode('utf8')
classes[c].attribute_properties[a][p] = decoded_value
# Return classes collection
return classes
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This argument class_properties
is not used in this method.
It's probably better to pop it out of the options
dict before calling get_servers_with_filters
data.classes[cls].properties[prop] = value | ||
|
||
# attribute properties | ||
if not options.get('attribute_properties', False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attribute_properties
can not be set from the cli. (in the cli, there is an option named --no-attribute-properties
)
Hi, yes you are right about moving the logic to tangodb.py. I use PyTango API for two reason:
|
Hi, I have just made an extension to dsconfig.dump which implements dumping of class properties along with servers (enabled with -c option). This may be worth to be merged to your original :).