本文整理汇总了Python中domogik.common.database.DbHelper.update_scenario方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.update_scenario方法的具体用法?Python DbHelper.update_scenario怎么用?Python DbHelper.update_scenario使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.update_scenario方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import update_scenario [as 别名]
class ScenarioManager:
""" Manage scenarios : create them, evaluate them, etc ...
A scenario instance contains a condition, which is a boolean
combination of many tests,
and a list of actions
Each test can be :
- test on the test of any device
- test on the time
- action triggered by user (click on UI for ex)
The test on devices are managed directly by xpl Listeners
The test on time will be managed by a TimeManager
The actions will be managed by an ActionManager
{
"condition" :
{ "AND" : {
"OR" : {
"one-uuid" : {
"param_name_1" : {
"token1" : "value",
"token2" : "othervalue"
},
"param_name_2" : {
"token3" : "foo"
}
},
"another-uuid" : {
"param_name_1" : {
"token4" : "bar"
}
}
},
"yet-another-uuid" : {
"param_name_1" : {
"url" : "http://google.fr",
"interval" : "5"
}
}
}
},
"actions" : [
"uid-for-action" : {
"param1" : "value1",
"param2" : "value2"
},
"uid-for-action2" : {
"param3" : "value3"
}
]
}
"""
def __init__(self, log):
""" Create ScenarioManager instance
@param log : Logger instance
"""
# Keep list of conditions as name : instance
self._instances = {}
# an instance of the logger
self.log = log
# load all scenarios from the DB
self._db = DbHelper()
self.load_scenarios()
def load_scenarios(self):
""" Loads all scenarios from the db
for each scenario call the create_scenario method
"""
with self._db.session_scope():
for scenario in self._db.list_scenario():
self.create_scenario(scenario.name, scenario.json, int(scenario.id), scenario.disabled, scenario.description)
def shutdown(self):
""" Callback to shut down all parameters
"""
for cond in self._conditions.keys():
self.delete_scenario(cond, db_delete=False)
def get_parsed_condition(self, name):
""" Call cond.get_parsed_condition on the cond with name 'name'
@param name : name of the Condition
@return {'name':name, 'data': parsed_condition} or raise Exception
"""
if name not in self._conditions:
raise KeyError('no key %s in conditions table' % name)
else:
parsed = self._conditions[name].get_parsed_condition()
return {'name': name, 'data': parsed}
def update_scenario(self, cid, name, json_input, dis, desc):
if int(cid) != 0:
self.del_scenario(cid, False)
return self.create_scenario(name, json_input, cid, dis, desc, True)
def del_scenario(self, cid, doDB=True):
try:
if cid == '' or int(cid) not in self._instances.keys():
self.log.info(u"Scenario deletion : id '{0}' doesn't exist".format(cid))
return {'status': 'ERROR', 'msg': u"Scenario {0} doesn't exist".format(cid)}
else:
self._instances[int(cid)]['instance'].destroy()
#.........这里部分代码省略.........