本文整理汇总了Python中domogik.common.database.DbHelper.get_plugin_config方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.get_plugin_config方法的具体用法?Python DbHelper.get_plugin_config怎么用?Python DbHelper.get_plugin_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.get_plugin_config方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import get_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"
示例2: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import get_plugin_config [as 别名]
#.........这里部分代码省略.........
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)
try:
self._db.del_plugin_config(name, host)
self.log.info(u"Delete config for {0} {1}".format(type, name))
self.publish_config_updated(type, name, host)
except:
status = False
reason = "Error while deleting configuration for '{0} {1} on {2} : {3}".format(type, name, host, 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 _fetch_techno_config(self, name, host, key):
'''
Fetch a plugin global config value in the database
@param name : the plugin of the element
@param host : hostname
@param key : the key of the config tuple to fetch
'''
try:
try:
result = self._db.get_plugin_config(name, host, 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 != name or \
result.hostname != host or \
result.key != key:
self.log.debug(u"Bad result : {0}/{1} != {2}/{3}".format(result.id, result.key, plugin, key))
result = self._db.get_plugin_config(name, host, key)
val = result.value
if val == '':
val = "None"
return val
except AttributeError:
# if no result is found
#self.log.error(u"Attribute error : {0}".format(traceback.format_exc()))
return "None"
except:
msg = "No config found host={0}, plugin={1}, key={2}".format(host, name, key)
self.log.warn(msg)
return "None"
def _mdp_reply_devices_delete_result(self, data):
status = True
reason = False
try:
did = data.get_data()['did']
if did:
res = self._db.del_device(did)
if not res:
status = False
示例3: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import get_plugin_config [as 别名]
#.........这里部分代码省略.........
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)
try:
self._db.del_plugin_config(type, name, host)
self.log.info(u"Delete config for {0} {1}".format(type, name))
self.publish_config_updated(type, name, host)
except:
status = False
reason = "Error while deleting configuration for '{0} {1} on {2} : {3}".format(type, name, host, 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 _fetch_techno_config(self, name, type, host, key):
'''
Fetch a plugin global config value in the database
@param name : the plugin of the element
@param host : hostname
@param key : the key of the config tuple to fetch
'''
try:
try:
result = self._db.get_plugin_config(type, name, host, 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 != name or \
result.type != type or \
result.hostname != host or \
result.key != key:
self.log.debug(u"Bad result : {0}-{1}/{2} != {3}/{4}".format(result.id, result.type, result.key, plugin, key))
result = self._db.get_plugin_config(type, name, host, key)
val = result.value
if val == '':
val = "None"
return val
except AttributeError:
# if no result is found
#self.log.error(u"Attribute error : {0}".format(traceback.format_exc()))
return "None"
except:
msg = "No config found host={0}, plugin={1}, key={2}".format(host, name, key)
self.log.warn(msg)
return "None"
def _mdp_reply_devices_delete_result(self, data):
status = True
reason = False
self.log.debug(u"Deleting device : {0}".format(data))
try:
did = data.get_data()['did']
if did:
res = self._db.del_device(did)
示例4: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import get_plugin_config [as 别名]
#.........这里部分代码省略.........
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)
try:
self._db.del_plugin_config(name, host)
self.log.info(u"Delete config for {0} {1}".format(type, name))
self.publish_config_updated(type, name, host)
except:
status = False
reason = "Error while deleting configuration for '{0} {1} on {2} : {3}".format(type, name, host, 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 _fetch_techno_config(self, name, host, key):
'''
Fetch a plugin global config value in the database
@param name : the plugin of the element
@param host : hostname
@param key : the key of the config tuple to fetch
'''
try:
try:
result = self._db.get_plugin_config(name, host, 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 != name or \
result.hostname != host or \
result.key != key:
self.log.debug(u"Bad result : {0}/{1} != {2}/{3}".format(result.id, result.key, plugin, key))
result = self._db.get_plugin_config(name, host, key)
val = result.value
if val == '':
val = "None"
return val
except AttributeError:
# if no result is found
#self.log.error(u"Attribute error : {0}".format(traceback.format_exc()))
return "None"
except:
msg = "No config found host={0}, plugin={1}, key={2}".format(host, name, key)
self.log.warn(msg)
return "None"
def _mdp_reply_devices_result(self, data):
""" Reply to device.get MQ req
@param data : MQ req message
"""
msg = MQMessage()
msg.set_action('device.result')
status = True
msg_data = data.get_data()