本文整理匯總了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}