def set_parameter(session, param_holder, feature, model, interface_name, path, value, compel=False, preclude=False): """ Handles add parameter as well as update parameter. Parmeters for features will be stored as part of personality as features/<feature_name>/<path> """ dbparameter = Parameter.get_unique(session, holder=param_holder, compel=compel) ## create dbparameter if doesnt exist if not dbparameter: if compel: raise NotFoundException("No parameter of path=%s defined." % path) dbparameter = Parameter(holder=param_holder, value={}) dblink = None if feature: dblink = get_feature_link(session, feature, model, interface_name, param_holder.personality) retval, param_def = validate_parameter(session, path, value, param_holder, dblink) if feature: path = Parameter.feature_path(dblink, path) dbparameter.set_path(path, retval, compel, preclude) dbparameter.param_def = param_def return dbparameter
def del_all_feature_parameter(session, dblink): if not dblink: return paramdef_holder = None param_definitions = None if dblink: paramdef_holder = dblink.feature.paramdef_holder if paramdef_holder: param_definitions = paramdef_holder.param_definitions if not param_definitions: return dbparams = get_parameters(session, archetype=None, personality=dblink.personality) if not dbparams: return for paramdef in param_definitions: for dbparam in dbparams: if paramdef.rebuild_required: validate_rebuild_required(session, paramdef.path, dbparam.holder) dbparam.del_path(Parameter.feature_path(dblink, paramdef.path), compel=False) return
def search_path_in_personas(session, path, paramdef_holder): q = session.query(PersonalityParameter) q = q.join(Personality) if isinstance(paramdef_holder, ArchetypeParamDef): q = q.filter_by(archetype=paramdef_holder.archetype) else: q = q.join(FeatureLink) q = q.filter_by(feature=paramdef_holder.feature) holder = {} trypath = [] if isinstance(paramdef_holder, ArchetypeParamDef): trypath.append(path) for param_holder in q.all(): try: if not isinstance(paramdef_holder, ArchetypeParamDef): trypath = [] q = session.query(FeatureLink) q = q.filter_by(feature=paramdef_holder.feature, personality=param_holder.personality) for link in q.all(): trypath.append(Parameter.feature_path(link, path)) for tpath in trypath: for param in param_holder.parameters: value = param.get_path(tpath) if value: holder[param_holder] = {path: value} except NotFoundException: pass return holder
def del_parameter(session, path, param_holder, feature=None, model=None, interface_name=None): dbparameter = Parameter.get_unique(session, holder=param_holder, compel=True) dblink = None if feature: dblink = get_feature_link(session, feature, model, interface_name, param_holder.personality) match = get_paramdef_for_parameter(session, path, param_holder, dblink) if match and match.rebuild_required: validate_rebuild_required(session, path, param_holder) if dblink: path = Parameter.feature_path(dblink, path) dbparameter.del_path(path) return dbparameter
def format_proto(self, param, skeleton=None): container = skeleton if not container: container = self.loaded_protocols[self.protocol].ParameterList() param_definitions = None paramdef_holder = None dbpersonality = param.holder.personality paramdef_holder = dbpersonality.archetype.paramdef_holder if paramdef_holder: param_definitions = paramdef_holder.param_definitions for param_def in param_definitions: value = param.get_path(param_def.path, compel=False) if value: skeleton = container.parameters.add() skeleton.path = str(param_def.path) if param_def.value_type == 'json': skeleton.value = json.dumps(value) else: skeleton.value = str(value) for link in dbpersonality.features: if not link.feature.paramdef_holder: continue param_definitions = link.feature.paramdef_holder.param_definitions for param_def in param_definitions: value = param.get_feature_path(link, param_def.path, compel=False) if value: skeleton = container.parameters.add() skeleton.path = str( Parameter.feature_path(link, param_def.path)) if param_def.value_type == 'json': skeleton.value = json.dumps(value) else: skeleton.value = str(value) return container
def format_proto(self, param, skeleton=None): container = skeleton if not container: container = self.loaded_protocols[self.protocol].ParameterList() param_definitions = None paramdef_holder = None dbpersonality = param.holder.personality paramdef_holder = dbpersonality.archetype.paramdef_holder if paramdef_holder: param_definitions = paramdef_holder.param_definitions for param_def in param_definitions: value = param.get_path(param_def.path, compel=False) if value: skeleton = container.parameters.add() skeleton.path = str(param_def.path) if param_def.value_type == 'json': skeleton.value = json.dumps(value) else: skeleton.value = str(value) for link in dbpersonality.features: if not link.feature.paramdef_holder: continue param_definitions = link.feature.paramdef_holder.param_definitions for param_def in param_definitions: value = param.get_feature_path(link, param_def.path, compel=False) if value: skeleton = container.parameters.add() skeleton.path = str(Parameter.feature_path(link, param_def.path)) if param_def.value_type == 'json': skeleton.value = json.dumps(value) else: skeleton.value = str(value) return container