本文整理汇总了Python中domogik.common.database.DbHelper.get_scenario_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python DbHelper.get_scenario_by_name方法的具体用法?Python DbHelper.get_scenario_by_name怎么用?Python DbHelper.get_scenario_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.common.database.DbHelper
的用法示例。
在下文中一共展示了DbHelper.get_scenario_by_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user
# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import get_scenario_by_name [as 别名]
#.........这里部分代码省略.........
raise KeyError('no key %s in conditions table' % name)
else:
parsed = self._conditions[name].get_parsed_condition()
return {'name': name, 'data': parsed}
def get_uuid(self):
""" Return some random uuid
Needs to verify that the uuid is not already used
Does this in the mappings (for actions and tests)
"""
_uuid = str(uuid.uuid4())
while _uuid in self._tests_mapping.keys() \
or uuid in self._actions_mapping.keys():
_uuid = str(uuid.uuid4())
return _uuid
def delete_scenario(self, name, db_delete=True):
if name not in self._conditions:
self.log.info(u"Scenario {0} doesn't exist".format(name))
return {'status': 'ERROR', 'msg': u"Scenario {0} doesn't exist".format(name)}
else:
# the condition and the tests
cond = self._conditions[name]
for tuuid in cond.destroy():
del self._tests_mapping[tuuid]
cond = None
del self._conditions[name]
# the actions
for action in self._conditions_actions[name]:
self._actions_mapping[action].destroy()
del self._conditions_actions[name]
# delete from the db
with self._db.session_scope():
scen = self._db.get_scenario_by_name(name)
print scen
if scen:
self._db.del_scenario(scen.id)
self.log.info(u"Scenario {0} deleted".format(name))
def create_scenario(self, name, json_input, store=True):
""" Create a Scenario from the provided json.
@param name : A name for the condition instance
@param json_input : JSON representation of the condition
The JSON will be parsed to get all the uuids, and test instances will be created.
The json needs to have 2 keys:
- condition => the json that will be used to create the condition instance
- actions => the json that will be used for creating the actions instances
@Return {'name': name} or raise exception
"""
if name in self._conditions.keys():
self.log.error(u"A scenario with name '{0}' already exists.".format(name))
return {'status': 'NOK', 'msg': 'a scenario with this name already exists'}
try:
payload = json.loads(json_input) # quick test to check if json is valid
except Exception as e:
self.log.error(u"Creation of a scenario failed, invallid json: {0}".format(json_input))
self.log.debug(e)
return {'status': 'NOK', 'msg': 'invallid json'}
if 'condition' not in payload.keys() \
or 'actions' not in payload.keys():
msg = u"the json for the scenario does not contain condition or actions for scenario {0}".format(name)
self.log.error(msg)
return {'status': 'NOK', 'msg': msg}