本文整理汇总了Python中domogik.common.database.DbHelper.set_plugin_config方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.set_plugin_config方法的具体用法?Python DbHelper.set_plugin_config怎么用?Python DbHelper.set_plugin_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.set_plugin_config方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import set_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 set_plugin_config [as 别名]
#.........这里部分代码省略.........
if 'type' not in msg_data:
status = False
reason = "Config set : missing 'type' field : {0}".format(data)
if msg_data['type'] != "plugin":
status = False
reason = "Config set not available for type={0}".format(msg_data['type'])
if 'name' not in msg_data:
status = False
reason = "Config set : missing 'name' field : {0}".format(data)
if 'host' not in msg_data:
status = False
reason = "Config set : missing 'host' field : {0}".format(data)
if 'data' not in msg_data:
status = False
reason = "Config set : missing 'data' field : {0}".format(data)
if status == False:
self.log.error(reason)
else:
reason = ""
type = msg_data['type']
name = msg_data['name']
host = msg_data['host']
data = msg_data['data']
msg.add_data('type', type)
msg.add_data('name', name)
msg.add_data('host', host)
try:
# we add a configured key set to true to tell the UIs and plugins that there are some configuration elements
self._db.set_plugin_config(name, host, "configured", True)
for key in msg_data['data']:
self._db.set_plugin_config(name, host, key, data[key])
self.publish_config_updated(type, name, host)
except:
reason = "Error while setting configuration for '{0} {1} on {2}' : {3}".format(type, name, host, traceback.format_exc())
status = False
self.log.error(reason)
msg.add_data('status', status)
msg.add_data('reason', reason)
self.log.debug(msg.get())
self.reply(msg.get())
def _mdp_reply_config_delete(self, data):
""" Reply to config.delete MQ req
Delete all the config items for the given type, name and host
@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:
status = False
reason = "Config request : missing 'type' field : {0}".format(data)
if msg_data['type'] != "plugin":
status = False
reason = "Config request not available for type={0}".format(msg_data['type'])
示例3: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import set_plugin_config [as 别名]
#.........这里部分代码省略.........
if 'type' not in msg_data:
status = False
reason = "Config set : missing 'type' field : {0}".format(data)
if msg_data['type'] not in ["plugin", "brain", "interface"]:
status = False
reason = "You are not able to configure items for type={0}".format(msg_data['type'])
if 'name' not in msg_data:
status = False
reason = "Config set : missing 'name' field : {0}".format(data)
if 'host' not in msg_data:
status = False
reason = "Config set : missing 'host' field : {0}".format(data)
if 'data' not in msg_data:
status = False
reason = "Config set : missing 'data' field : {0}".format(data)
if status == False:
self.log.error(reason)
else:
reason = ""
type = msg_data['type']
name = msg_data['name']
host = msg_data['host']
data = msg_data['data']
msg.add_data('type', type)
msg.add_data('name', name)
msg.add_data('host', host)
try:
# we add a configured key set to true to tell the UIs and plugins that there are some configuration elements
self._db.set_plugin_config(type, name, host, "configured", True)
for key in msg_data['data']:
self._db.set_plugin_config(type, name, host, key, data[key])
self.publish_config_updated(type, name, host)
except:
reason = "Error while setting configuration for '{0} {1} on {2}' : {3}".format(type, name, host, traceback.format_exc())
status = False
self.log.error(reason)
msg.add_data('status', status)
msg.add_data('reason', reason)
self.log.debug(msg.get())
self.reply(msg.get())
def _mdp_reply_config_delete(self, data):
""" Reply to config.delete MQ req
Delete all the config items for the given type, name and host
@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:
status = False
reason = "Config request : missing 'type' field : {0}".format(data)
if msg_data['type'] not in ["plugin", "brain", "interface"]:
status = False
reason = "Configuration deletion not available for type={0}".format(msg_data['type'])
示例4: DBConnector
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import set_plugin_config [as 别名]
#.........这里部分代码省略.........
if 'type' not in msg_data:
status = False
reason = "Config set : missing 'type' field : {0}".format(data)
if msg_data['type'] != "plugin":
status = False
reason = "Config set not available for type={0}".format(msg_data['type'])
if 'name' not in msg_data:
status = False
reason = "Config set : missing 'name' field : {0}".format(data)
if 'host' not in msg_data:
status = False
reason = "Config set : missing 'host' field : {0}".format(data)
if 'data' not in msg_data:
status = False
reason = "Config set : missing 'data' field : {0}".format(data)
if status == False:
self.log.error(reason)
else:
reason = ""
type = msg_data['type']
name = msg_data['name']
host = msg_data['host']
data = msg_data['data']
msg.add_data('type', type)
msg.add_data('name', name)
msg.add_data('host', host)
try:
# we add a configured key set to true to tell the UIs and plugins that there are some configuration elements
self._db.set_plugin_config(name, host, "configured", True)
for key in msg_data['data']:
self._db.set_plugin_config(name, host, key, data[key])
self.publish_config_updated(type, name, host)
except:
reason = "Error while setting configuration for '{0} {1} on {2}' : {3}".format(type, name, host, traceback.format_exc())
status = False
self.log.error(reason)
msg.add_data('status', status)
msg.add_data('reason', reason)
self.log.debug(msg.get())
self.reply(msg.get())
def _mdp_reply_config_delete(self, data):
""" Reply to config.delete MQ req
Delete all the config items for the given type, name and host
@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:
status = False
reason = "Config request : missing 'type' field : {0}".format(data)
if msg_data['type'] != "plugin":
status = False
reason = "Config request not available for type={0}".format(msg_data['type'])