def output_features(): """ provides a list of features """ from bungeni.capi import capi from zope.dottedname.resolve import resolve from bungeni.alchemist.catalyst import MODEL_MODULE from bungeni.utils import naming from bungeni.feature.feature import get_feature_cls # get a list of available types in a list li_available_types = [] for type_key, ti in capi.iter_type_info(): li_available_types.append(type_key) li_features = [] li_features.append("<features>") li_unique_features = [] for type_key, ti in capi.iter_type_info(): obj = resolve("%s.%s" % (MODEL_MODULE.__name__, naming.model_name(type_key))) if len(obj.available_dynamic_features) > 0: for dyn_feature in obj.available_dynamic_features: # check if feature is a type li_unique_features.append('%s' % dyn_feature) li_unique_features = list(set(li_unique_features)) for f in li_unique_features: fcls = get_feature_cls(f) li_features.append(' <feature name="%s" >' % f) if fcls.depends_on: li_features.append(' <depends>') for depends in fcls.depends_on: li_features.append(' <depend>%s</depend>' % depends) li_features.append(' </depends>') if fcls.feature_parameters is not None: if len(fcls.feature_parameters) > 0: li_features.append(' <params>') for key, val in fcls.feature_parameters.iteritems(): li_features.append(' <param name="%s">' % key) for key2, val2 in val.iteritems(): li_features.append(' <%(name)s>%(value)s</%(name)s>' % { "name": key2, "value": val2 }) li_features.append(' </param>') li_features.append(' </params>') li_features.append(' </feature>') li_features.append("</features>") print "\n".join(li_features).encode("utf-8") return "\n".join(li_features).encode("utf-8")
def output_features(): """ provides a list of features """ from bungeni.capi import capi from zope.dottedname.resolve import resolve from bungeni.alchemist.catalyst import MODEL_MODULE from bungeni.utils import naming from bungeni.feature.feature import get_feature_cls # get a list of available types in a list li_available_types = [] for type_key, ti in capi.iter_type_info(): li_available_types.append(type_key) li_features = [] li_features.append("<features>") li_unique_features = [] for type_key, ti in capi.iter_type_info(): obj = resolve("%s.%s" % (MODEL_MODULE.__name__, naming.model_name(type_key))) if len(obj.available_dynamic_features) > 0: for dyn_feature in obj.available_dynamic_features: # check if feature is a type li_unique_features.append('%s' % dyn_feature) li_unique_features = list(set(li_unique_features)) for f in li_unique_features: fcls = get_feature_cls(f) li_features.append(' <feature name="%s" >' % f) if fcls.depends_on: li_features.append(' <depends>') for depends in fcls.depends_on: li_features.append(' <depend>%s</depend>' % depends) li_features.append(' </depends>') if fcls.feature_parameters is not None: if len(fcls.feature_parameters) > 0 : li_features.append(' <params>') for key, val in fcls.feature_parameters.iteritems(): li_features.append(' <param name="%s">' % key) for key2, val2 in val.iteritems(): li_features.append(' <%(name)s>%(value)s</%(name)s>' % {"name": key2, "value": val2 } ) li_features.append(' </param>') li_features.append(' </params>') li_features.append(' </feature>') li_features.append("</features>") print "\n".join(li_features).encode("utf-8") return "\n".join(li_features).encode("utf-8")
def load_features(workflow_name, workflow_elem): # all workflow features (enabled AND disabled) workflow_features = [] for f in workflow_elem.iterchildren("feature"): feature_name = xas(f, "name") feature_enabled = xab(f, "enabled") # !+FEATURE_DEPENDENCIES archetype/feature inter-dep; should be part of feature descriptor if feature_enabled and feature_name == "version": assert "audit" in [ fe.name for fe in workflow_features if fe.enabled ], \ "Workflow [%s] has version but no audit feature" % (workflow_name) # !+ if not feature_enabled, we still load the feature... whens = {} default_params = load_params(feature_name, f) whens[(None, None)] = feature._When(None, None, None, None, default_params) for w in f.iterchildren("when"): if not xab(w, "enabled"): continue subtype = xas(w, "subtype") condition = xas(w, "condition") assert (subtype, condition) not in whens, \ "Repeated <when> (%r, %r) discriminators in feature %r" % ( subtype, condition, feature_name) # condition is a python resolvable condition_wrapped_callable = None if condition is not None: condition_wrapped_callable = capi.get_workflow_condition( condition) whens[(subtype, condition)] = feature._When(subtype, condition, condition_wrapped_callable, xas(w, "note"), load_params(feature_name, w)) # !+ param in Feature.feature_parameters for param in whens[(subtype, condition)].params: assert param in default_params, "<when> (%r, %r) parameter %r " \ "not included in feature %r default parameters." % ( subtype, condition, param, feature_name) workflow_features.append( feature.get_feature_cls(feature_name)(feature_enabled, xas(f, "note"), whens)) return workflow_features
def load_features(workflow_name, workflow_elem): # all workflow features (enabled AND disabled) workflow_features = [] for f in workflow_elem.iterchildren("feature"): feature_name = xas(f, "name") feature_enabled = xab(f, "enabled") # !+FEATURE_DEPENDENCIES archetype/feature inter-dep; should be part of feature descriptor if feature_enabled and feature_name == "version": assert "audit" in [ fe.name for fe in workflow_features if fe.enabled ], \ "Workflow [%s] has version but no audit feature" % (workflow_name) # !+ if not feature_enabled, we still load the feature... whens = {} default_params = load_params(feature_name, f) whens[(None, None)] = feature._When(None, None, None, None, default_params) for w in f.iterchildren("when"): if not xab(w, "enabled"): continue subtype = xas(w, "subtype") condition = xas(w, "condition") assert (subtype, condition) not in whens, \ "Repeated <when> (%r, %r) discriminators in feature %r" % ( subtype, condition, feature_name) # condition is a python resolvable condition_wrapped_callable = None if condition is not None: condition_wrapped_callable = capi.get_workflow_condition(condition) whens[(subtype, condition)] = feature._When( subtype, condition, condition_wrapped_callable, xas(w, "note"), load_params(feature_name, w)) # !+ param in Feature.feature_parameters for param in whens[(subtype, condition)].params: assert param in default_params, "<when> (%r, %r) parameter %r " \ "not included in feature %r default parameters." % ( subtype, condition, param, feature_name) workflow_features.append( feature.get_feature_cls(feature_name)( feature_enabled, xas(f, "note"), whens)) return workflow_features