Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

Class properties dump implemented. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

piogor
Copy link

@piogor piogor commented Jan 7, 2019

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 :).

Copy link
Member

@AntoineDupre AntoineDupre left a 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.

Copy link
Member

@AntoineDupre AntoineDupre left a 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,
Copy link
Member

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):
Copy link
Member

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)

@piogor
Copy link
Author

piogor commented Jan 11, 2019

Hi, yes you are right about moving the logic to tangodb.py. I use PyTango API for two reason:

  • I know how to do it with PyTango whereas I am not so confident with SQL schema
  • To be sure it will work even there is any change to tagno db schema between different deployments and versions. I am probably too cautious ;-).
    So, I will follow your review and implement to be compatible with your original approach.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants