当前位置: 首页>>代码示例>>Python>>正文


Python DbHelper.list_plugin_config方法代码示例

本文整理汇总了Python中domogik.common.database.DbHelper.list_plugin_config方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.list_plugin_config方法的具体用法?Python DbHelper.list_plugin_config怎么用?Python DbHelper.list_plugin_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在domogik.common.database.DbHelper的用法示例。


在下文中一共展示了DbHelper.list_plugin_config方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_plugin_config [as 别名]

#.........这里部分代码省略.........
        '''
        Fetch a plugin global config value in the database
        @param techno : the plugin of the element
        @param hostname : hostname
        @param key : the key of the config tuple to fetch
        '''
        # This array is here for information only but is not used anymore
        # Values are now on the database
        #vals = {'x10': {'heyu-cfg-path':'/etc/heyu/x10.conf',
        #                'heyu-file-0': 'TTY /dev/ttyUSB0',
        #                'heyu-file-1': 'TTY_AUX /dev/ttyUSB0 RFXCOM',
        #                'heyu-file-2': 'ALIAS back_door D5 DS10A 0x677'},
        #        'global': {'pid-dir-path': '/var/run/'},
        #        'onewire': {'temperature_refresh_delay' : '10'},
        #        'cidmodem': {'device' : '/dev/ttyUSB1',
        #                   'nbmaxtry' : '10',
        #                   'interval' : '15'},
        #        'mirror': {'device' : '/dev/hidraw0',
        #                   'nbmaxtry' : '10',
        #                   'interval' : '15'},
        #        'xbmc_not': {'address' : '192.168.0.20:8080',
        #                 'delay' : '15',
        #                 'maxdelay' : '20'},
        #        'gagenda': {'email' : "[email protected]",
        #                 'password' : 'XXXXXXXX',
        #                 'calendarname' : '[email protected]',
        #                 'startup-plugin':'True'},
        #        'teleinfo' : {'device' : '/dev/teleinfo',
        #            'interval' : '30'},
        #            'dawndusk' : {'startup-plugin':'True'},
        #            'plcbus' : {'device':'/dev/ttyUSB0'},
        #        }
        self.log.debug("FTC 1")
        try:
            if key:
                self.log.debug("FTC 2")
                try:
                    self.log.debug("Get plg conf for %s / %s / %s" % (techno, hostname, key))
                    result = self._db.get_plugin_config(techno, hostname, key)
                    # tricky loop as workaround for a (sqlalchemy?) bug :
                    # sometimes the given result is for another plugin/key
                    # so while we don't get the good data, we loop
                    # This bug happens rarely
                    while result.id != techno or \
                       result.hostname != hostname or \
                       result.key != key:
                        self.log.debug("Bad result : %s/%s != %s/%s" % (result.id, result.key, plugin, key))
                        result = self._db.get_plugin_config(techno, hostname, key)
                    self.log.debug("Get plg conf for %s / %s / %s Result=%s" % (techno, hostname, key, result))
                    val = result.value
                    self.log.debug("Get plg conf for %s / %s / %s = %s" % (techno, hostname, key, val))
                    if val == '':
                        val = "None"
                    self.log.debug("Get plg conf for %s / %s / %s = %s (2)" % (techno, hostname, key, val))
                    return val
                except AttributeError:
                    self.log.debug("Attribute error for %s / %s / %s" % (techno, hostname, key))
                    return "None"
            else:
                self.log.debug("FTC 3")
                vals = self._db.list_plugin_config(techno, hostname)
                res = {}
                for val in vals:
                    if val == '':
                        res[val.key] = "None"
                    else:
                        res[val.key] = val.value
                return res
        except:
            msg = "No config found h=%s, t=%s, k=%s" % (hostname, techno, key)
            print(msg)
            self.log.warn(msg)
            return "None"

    def _set_config(self, plugin, hostname, key, value):
        '''
        Send a config value message for an element's config item
        @param plugin : the plugin of the element
        @param hostname : hostname
        @param key : the key to set
        @param value : the value to set
        '''

        try:
            self._db.set_plugin_config(technology, hostname, key, value)
    
            mess = XplMessage()
            mess.set_type('xpl-stat')
            mess.set_schema('domogik.config')
            mess.add_data({'plugin' :  plugin})
            mess.add_data({'hostname' :  hostname})
            mess.add_data({'key' :  key})
            mess.add_data({'value' :  value})
            self.myxpl.send(mess)
        except:
            traceback.print_exc()
            msg = "Error while setting h=%s, t=%s, k=%s, v=%s" % (hostname, techno, key, value)
            print(msg)
            self.log.warn(msg)
            return "None"
开发者ID:capof,项目名称:domogik,代码行数:104,代码来源:dbmgr.py

示例2: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_plugin_config [as 别名]

#.........这里部分代码省略.........

        if msg_data['type'] != "plugin":
            status = False
            reason = "Config request not available for type={0}".format(msg_data['type'])

        if 'name' not in msg_data:
            status = False
            reason = "Config request : missing 'name' field : {0}".format(data)

        if 'host' not in msg_data:
            status = False
            reason = "Config request : missing 'host' field : {0}".format(data)

        if 'key' not in msg_data:
            get_all_keys = True
            key = "*"
        else:
            get_all_keys = False
            key = msg_data['key']

        if status == False:
            self.log.error(reason)
        else:
            reason = ""
            type = msg_data['type']
            name = msg_data['name']
            host = msg_data['host']
            msg.add_data('type', type)
            msg.add_data('name', name)
            msg.add_data('host', host)
            msg.add_data('key', key)  # we let this here to display key or * depending on the case
            try:
                if get_all_keys == True:
                    config = self._db.list_plugin_config(name, host)
                    self.log.info(u"Get config for {0} {1} with key '{2}' : value = {3}".format(type, name, key, config))
                    json_config = {}
                    for elt in config:
                        json_config[elt.key] = self.convert(elt.value)
                    msg.add_data('data', json_config)
                else:
                    value = self._fetch_techno_config(name, host, key)
                    # temporary fix : should be done in a better way (on db side)
                    value = self.convert(value)
                    self.log.info(u"Get config for {0} {1} with key '{2}' : value = {3}".format(type, name, key, value))
                    msg.add_data('value', value)
            except:
                status = False
                reason = "Error while getting configuration for '{0} {1} on {2}, key {3}' : {4}".format(type, name, host, key, traceback.format_exc())
                self.log.error(reason)

        msg.add_data('reason', reason)
        msg.add_data('status', status)

        self.log.debug(msg.get())
        self.reply(msg.get())


    def _mdp_reply_config_set(self, data):
        """ Reply to config.set MQ req
            @param data : MQ req message
        """
        print "#################"
        msg = MQMessage()
        msg.set_action('config.result')
        status = True
        msg_data = data.get_data()
开发者ID:anuraagkapoor,项目名称:domogik,代码行数:70,代码来源:dbmgr.py

示例3: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_plugin_config [as 别名]

#.........这里部分代码省略.........

        if msg_data['type'] not in ["plugin", "brain", "interface"]:
            status = False
            reason = "Configuration request not available for type={0}".format(msg_data['type'])

        if 'name' not in msg_data:
            status = False
            reason = "Config request : missing 'name' field : {0}".format(data)

        if 'host' not in msg_data:
            status = False
            reason = "Config request : missing 'host' field : {0}".format(data)

        if 'key' not in msg_data:
            get_all_keys = True
            key = "*"
        else:
            get_all_keys = False
            key = msg_data['key']

        if status == False:
            self.log.error(reason)
        else:
            reason = ""
            type = msg_data['type']
            name = msg_data['name']
            host = msg_data['host']
            msg.add_data('type', type)
            msg.add_data('name', name)
            msg.add_data('host', host)
            msg.add_data('key', key)  # we let this here to display key or * depending on the case
            try:
                if get_all_keys == True:
                    config = self._db.list_plugin_config(type, name, host)
                    self.log.info(u"Get config for {0} {1} with key '{2}' : value = {3}".format(type, name, key, config))
                    json_config = {}
                    for elt in config:
                        json_config[elt.key] = self.convert(elt.value)
                    msg.add_data('data', json_config)
                else:
                    value = self._fetch_techno_config(name, type, host, key)
                    # temporary fix : should be done in a better way (on db side)
                    value = self.convert(value)
                    self.log.info(u"Get config for {0} {1} with key '{2}' : value = {3}".format(type, name, key, value))
                    msg.add_data('value', value)
            except:
                status = False
                reason = "Error while getting configuration for '{0} {1} on {2}, key {3}' : {4}".format(type, name, host, key, traceback.format_exc())
                self.log.error(reason)

        msg.add_data('reason', reason)
        msg.add_data('status', status)

        self.log.debug(msg.get())
        self.reply(msg.get())


    def _mdp_reply_config_set(self, data):
        """ Reply to config.set MQ req
            @param data : MQ req message
        """
        msg = MQMessage()
        msg.set_action('config.result')
        status = True
        msg_data = data.get_data()
        if 'type' not in msg_data:
开发者ID:domogik,项目名称:domogik,代码行数:70,代码来源:dbmgr.py

示例4: DBConnector

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import list_plugin_config [as 别名]

#.........这里部分代码省略.........

        if msg_data['type'] != "plugin":
            status = False
            reason = "Config request not available for type={0}".format(msg_data['type'])

        if 'name' not in msg_data:
            status = False
            reason = "Config request : missing 'name' field : {0}".format(data)

        if 'host' not in msg_data:
            status = False
            reason = "Config request : missing 'host' field : {0}".format(data)

        if 'key' not in msg_data:
            get_all_keys = True
            key = "*"
        else:
            get_all_keys = False
            key = msg_data['key']

        if status == False:
            self.log.error(reason)
        else:
            reason = ""
            type = msg_data['type']
            name = msg_data['name']
            host = msg_data['host']
            msg.add_data('type', type)
            msg.add_data('name', name)
            msg.add_data('host', host)
            msg.add_data('key', key)  # we let this here to display key or * depending on the case
            try:
                if get_all_keys == True:
                    config = self._db.list_plugin_config(name, host)
                    self.log.info(u"Get config for {0} {1} with key '{2}' : value = {3}".format(type, name, key, config))
                    json_config = {}
                    for elt in config:
                        json_config[elt.key] = self.convert(elt.value)
                    msg.add_data('data', json_config)
                else:
                    value = self._fetch_techno_config(name, host, key)
                    # temporary fix : should be done in a better way (on db side)
                    value = self.convert(value)
                    self.log.info(u"Get config for {0} {1} with key '{2}' : value = {3}".format(type, name, key, value))
                    msg.add_data('value', value)
            except:
                status = False
                reason = "Error while getting configuration for '{0} {1} on {2}, key {3}' : {4}".format(type, name, host, key, traceback.format_exc())
                self.log.error(reason)

        msg.add_data('reason', reason)
        msg.add_data('status', status)

        self.log.debug(msg.get())
        self.reply(msg.get())


    def _mdp_reply_config_set(self, data):
        """ Reply to config.set MQ req
            @param data : MQ req message
        """
        print "#################"
        msg = MQMessage()
        msg.set_action('config.result')
        status = True
        msg_data = data.get_data()
开发者ID:Basilic,项目名称:domogik,代码行数:70,代码来源:dbmgr.py


注:本文中的domogik.common.database.DbHelper.list_plugin_config方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。