From cd8b3cf68d3523bf4e732dc761481fcd110d077c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 16 Dec 2012 12:47:13 +0100 Subject: [PATCH] finish rewrite of dependency resolver Signed-off-by: Nico Schottelius --- cdist/config_install.py | 3 -- cdist/core/cdist_object.py | 58 +++++++++++++------------------------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/cdist/config_install.py b/cdist/config_install.py index 6a0d5161..4d6c10f2 100644 --- a/cdist/config_install.py +++ b/cdist/config_install.py @@ -160,9 +160,6 @@ class ConfigInstall(object): evil_objects = [] for cdist_object in objects: if not cdist_object.state == cdist_object.STATE_DONE: -# evil_objects.append({ name: cdist_object.name, -# requirements: cdist_object.requirements, -# autorequire: cdist_object.autorequire }) evil_objects.append("%s (required: %s, autorequired: %s" % (cdist_object.name, cdist_object.requirements, cdist_object.autorequire)) diff --git a/cdist/core/cdist_object.py b/cdist/core/cdist_object.py index fa358937..501c0fb3 100644 --- a/cdist/core/cdist_object.py +++ b/cdist/core/cdist_object.py @@ -211,25 +211,17 @@ class CdistObject(object): raise cdist.Error('Error creating directories for cdist object: %s: %s' % (self, error)) def satisfied_requirements(self): + """Return state whether all of our dependencies have been resolved already""" + satisfied = True - @property - def dependencies(self): - """Build the dependency graph. + for requirement in self.all_requirements(): + if not requirement.state == self.STATE_DONE: + satisfied = False + break + + return satisfied - Returns a dict where the keys are the object names and the values are - lists of all dependencies including the key object itself. - """ - if self._dependencies is None: - log.info("Resolving dependencies...") - self._dependencies = d = {} - self._preprocess_requirements() - for name,cdist_object in self.objects.items(): - resolved = [] - unresolved = [] - self._resolve_object_dependencies(cdist_object, resolved, unresolved) - d[name] = resolved - return self._dependencies def find_requirements_by_name(self, requirements): """Takes a list of requirement patterns and returns a list of matching object instances. @@ -239,7 +231,8 @@ class CdistObject(object): find_requirements_by_name(['__type/object_id', '__other_type/*']) -> [, , ] """ - object_names = self.objects.keys() + + object_names = self.list_object_namess(self.base_path) for pattern in requirements: found = False for requirement in fnmatch.filter(object_names, pattern): @@ -253,28 +246,17 @@ class CdistObject(object): else: raise RequirementNotFoundError(pattern) - def _preprocess_requirements(self): - """Find all autorequire dependencies and merge them to be just requirements - for further processing. + def all_requirements(self): """ - for cdist_object in self.objects.values(): - if cdist_object.autorequire: - # The objects (children) that this cdist_object (parent) defined - # in it's type manifest shall inherit all explicit requirements - # that the parent has so that user defined requirements are - # fullfilled and processed in the expected order. - for auto_requirement in self.find_requirements_by_name(cdist_object.autorequire): - for requirement in cdist_object.requirements: - if requirement not in auto_requirement.requirements: - auto_requirement.requirements.append(requirement) - # On the other hand the parent shall depend on all the children - # it created so that the user can setup dependencies on it as a - # whole without having to know anything about the parents - # internals. - cdist_object.requirements.extend(cdist_object.autorequire) - # As we changed the object on disc, we have to ensure it is not - # preprocessed again if someone would call us multiple times. - cdist_object.autorequire = [] + Return resolved autorequirements and requirements so that + a complete list of requirements is returned + """ + + all_requirements = [] + all_requirements.extend(self.find_requirements_by_name(self.requirements)) + all_requirements.extend(self.find_requirements_by_name(self.autorequire)) + + return unique(all_requirements) class CircularReferenceError(cdist.Error):