Refactor the RequirementTreeNode to put it in the interfaces file.

This commit is contained in:
Mike Auty
2016-02-20 21:35:05 +00:00
parent da7774ee92
commit ba2083fc7c
3 changed files with 17 additions and 14 deletions
+2 -3
View File
@@ -41,7 +41,7 @@ class CommandLine(object):
# Determine the selected plugin
# Resolve the dependencies on that plugin
dldr = depresolver.DependencyResolver()
dependencies = dldr.build_tree(plugin)
deptree = dldr.build_tree(plugin)
# UI fills in the config:
ctx = contexts.Context()
@@ -51,8 +51,7 @@ class CommandLine(object):
# Walk down the tree attempting to fulfil each requirement (recursive) and backtrack when necessary
# Translate the parsed args to a context configuration
config_path = plugin.__name__.lower()
if dldr.validate_dependencies(dependencies, context = ctx, path = config_path):
if dldr.validate_dependencies(deptree, context = ctx, path = config_path):
# Construct and run the plugin
TextRenderer().render(plugin(ctx, config_path).run())
else:
@@ -60,6 +60,9 @@ class DependencyResolver(validity.ValidityRoutines):
# TODO: Improve logging/output of this code to diagnose errors
if path is None:
path = ""
self._check_type(deptree, RequirementTreeList)
for node in deptree.children:
node_path = path + interfaces.configuration.CONFIG_SEPARATOR + node.requirement.name
if isinstance(node, RequirementTreeChoice) and not node.requirement.optional:
@@ -179,18 +182,8 @@ class ValidateDependenciesVisitor(TreeVisitor):
# Requirement tree classes
##########################
class RequirementTreeNode(validity.ValidityRoutines):
@property
def optional(self):
"""Determines whether the elements within this tree are required for proper operation"""
return False
def accept(self, visitor):
"""Takes in a vistor and applies to itself and any child nodes appropriately"""
return visitor.visit(self)
class RequirementTreeReq(RequirementTreeNode):
class RequirementTreeReq(interfaces.configuration.RequirementTreeNode):
def __init__(self, requirement = None):
validity.ValidityRoutines.__init__(self)
self._check_type(requirement, interfaces.configuration.RequirementInterface)
@@ -109,3 +109,14 @@ class ProviderInterface(ConfigurableInterface):
@classmethod
def fulfill(cls, context, requirement, config_path):
"""Fulfills a context's requirement, altering the context appropriately"""
class ConfigurableVisitorInterface(validity.ValidityRoutines):
pass
class RequirementTreeNode(validity.ValidityRoutines):
@property
def optional(self):
"""Determines whether the elements within this tree are required for proper operation"""
return False