finish rewrite of dependency resolver
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
6a8778e595
commit
cd8b3cf68d
2 changed files with 20 additions and 41 deletions
|
@ -160,9 +160,6 @@ class ConfigInstall(object):
|
||||||
evil_objects = []
|
evil_objects = []
|
||||||
for cdist_object in objects:
|
for cdist_object in objects:
|
||||||
if not cdist_object.state == cdist_object.STATE_DONE:
|
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" %
|
evil_objects.append("%s (required: %s, autorequired: %s" %
|
||||||
(cdist_object.name, cdist_object.requirements, cdist_object.autorequire))
|
(cdist_object.name, cdist_object.requirements, cdist_object.autorequire))
|
||||||
|
|
||||||
|
|
|
@ -211,25 +211,17 @@ class CdistObject(object):
|
||||||
raise cdist.Error('Error creating directories for cdist object: %s: %s' % (self, error))
|
raise cdist.Error('Error creating directories for cdist object: %s: %s' % (self, error))
|
||||||
|
|
||||||
def satisfied_requirements(self):
|
def satisfied_requirements(self):
|
||||||
|
"""Return state whether all of our dependencies have been resolved already"""
|
||||||
|
|
||||||
|
satisfied = True
|
||||||
|
|
||||||
@property
|
for requirement in self.all_requirements():
|
||||||
def dependencies(self):
|
if not requirement.state == self.STATE_DONE:
|
||||||
"""Build the dependency graph.
|
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):
|
def find_requirements_by_name(self, requirements):
|
||||||
"""Takes a list of requirement patterns and returns a list of matching object instances.
|
"""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/*']) ->
|
find_requirements_by_name(['__type/object_id', '__other_type/*']) ->
|
||||||
[<Object __type/object_id>, <Object __other_type/any>, <Object __other_type/match>]
|
[<Object __type/object_id>, <Object __other_type/any>, <Object __other_type/match>]
|
||||||
"""
|
"""
|
||||||
object_names = self.objects.keys()
|
|
||||||
|
object_names = self.list_object_namess(self.base_path)
|
||||||
for pattern in requirements:
|
for pattern in requirements:
|
||||||
found = False
|
found = False
|
||||||
for requirement in fnmatch.filter(object_names, pattern):
|
for requirement in fnmatch.filter(object_names, pattern):
|
||||||
|
@ -253,28 +246,17 @@ class CdistObject(object):
|
||||||
else:
|
else:
|
||||||
raise RequirementNotFoundError(pattern)
|
raise RequirementNotFoundError(pattern)
|
||||||
|
|
||||||
def _preprocess_requirements(self):
|
def all_requirements(self):
|
||||||
"""Find all autorequire dependencies and merge them to be just requirements
|
|
||||||
for further processing.
|
|
||||||
"""
|
"""
|
||||||
for cdist_object in self.objects.values():
|
Return resolved autorequirements and requirements so that
|
||||||
if cdist_object.autorequire:
|
a complete list of requirements is returned
|
||||||
# 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
|
all_requirements = []
|
||||||
# fullfilled and processed in the expected order.
|
all_requirements.extend(self.find_requirements_by_name(self.requirements))
|
||||||
for auto_requirement in self.find_requirements_by_name(cdist_object.autorequire):
|
all_requirements.extend(self.find_requirements_by_name(self.autorequire))
|
||||||
for requirement in cdist_object.requirements:
|
|
||||||
if requirement not in auto_requirement.requirements:
|
return unique(all_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 = []
|
|
||||||
|
|
||||||
|
|
||||||
class CircularReferenceError(cdist.Error):
|
class CircularReferenceError(cdist.Error):
|
||||||
|
|
Loading…
Reference in a new issue