text
stringlengths
0
828
281,"def formula_sections(self):
""""""
Return all sections related to a formula, re-ordered according to the ""depends"" section.
""""""
if self.dtree is not None:
return self.dtree.order
else:
return [s for s in self.manifest.sections() if s != ""config""]"
282,"def is_affirmative(self, section, option):
""""""
Return true if the section option combo exists and it is set
to a truthy value.
""""""
return self.has_option(section, option) and \
lib.is_affirmative(self.get(section, option))"
283,"def write(self, file_handle):
"""""" write the current state to a file manifest """"""
for k, v in self.inputs.write_values().items():
self.set('config', k, v)
self.set('config', 'namespace', self.namespace)
self.manifest.write(file_handle)"
284,"def get_context_dict(self):
"""""" return a context dict of the desired state """"""
context_dict = {}
for s in self.sections():
for k, v in self.manifest.items(s):
context_dict[""%s:%s"" % (s, k)] = v
for k, v in self.inputs.values().items():
context_dict[""config:{0}"".format(k)] = v
context_dict.update(self.additional_context_variables.items())
context_dict.update(dict([(""%s|escaped"" % k, re.escape(str(v) or """")) for k, v in context_dict.items()]))
return context_dict"
285,"def get(self, section, key, default=MANIFEST_NULL_KEY):
"""""" Returns the value if it exist, or default if default is set """"""
if not self.manifest.has_option(section, key) and default is not MANIFEST_NULL_KEY:
return default
return self.manifest.get(section, key)"
286,"def __parse_namespace(self):
""""""
Parse the namespace from various sources
""""""
if self.manifest.has_option('config', 'namespace'):
return self.manifest.get('config', 'namespace')
elif self.manifest.has_option('config', 'source'):
return NAMESPACE_REGEX.search(self.manifest.get('config', 'source')).groups()[0]
else:
logger.warn('Could not parse namespace implicitely')
return None"
287,"def __generate_dependency_tree(self):
""""""
Generate the dependency tree object
""""""
dependency_dict = {}
for s in self.manifest.sections():
if s != ""config"":
if self.manifest.has_option(s, 'depends'):
dependency_list = [d.strip() for d in re.split('\n|,', self.manifest.get(s, 'depends'))]
dependency_dict[s] = dependency_list
else:
dependency_dict[s] = []
try:
return DependencyTree(dependency_dict)
except DependencyTreeException:
dte = sys.exc_info()[1]
raise ManifestException(""Dependency tree for manifest is invalid! %s"" % str(dte))"
288,"def __substitute_objects(self, value, context_dict):
""""""
recursively substitute value with the context_dict
""""""
if type(value) == dict:
return dict([(k, self.__substitute_objects(v, context_dict)) for k, v in value.items()])
elif type(value) == str:
try:
return value % context_dict
except KeyError:
e = sys.exc_info()[1]
logger.warn(""Could not specialize %s! Error: %s"" % (value, e))
return value
else:
return value"
289,"def __setup_inputs(self):
"""""" Setup the inputs object """"""
input_object = Inputs()
# populate input schemas
for s in self.manifest.sections():
if self.has_option(s, 'inputs'):
input_object.add_inputs_from_inputstring(self.get(s, 'inputs'))
# add in values
for k, v in self.items('config'):
if input_object.is_input(s):
input_object.set_input(k, v)
return input_object"
290,"def validate(self):
""""""
validates the feature configuration, and returns a list of errors (empty list if no error)
validate should:
* required variables
* warn on unused variables