Update mixed and yaml_git for node name changes introduced with compose_node_name option
This fixes method signatures in mixed and yaml_git to match
the changes in yaml_fs. The mixed storage type just passes on the new
compose_node_name option which will work correctly. However for the
yaml_git storage type the compose_node_name=true option has not been
tested only the old functionality which corresponds to
compose_node_name=false has been tested.
diff --git a/reclass/storage/__init__.py b/reclass/storage/__init__.py
index 3b46a2a..fe873e3 100644
--- a/reclass/storage/__init__.py
+++ b/reclass/storage/__init__.py
@@ -11,6 +11,7 @@
from __future__ import print_function
from __future__ import unicode_literals
+from reclass.storage.common import NameMangler
class NodeStorageBase(object):
@@ -34,3 +35,14 @@
def path_mangler(self):
msg = "Storage class '{0}' does not implement path_mangler."
raise NotImplementedError(msg.format(self.name))
+
+
+class ExternalNodeStorageBase(NodeStorageBase):
+
+ def __init__(self, name, compose_node_name):
+ super(ExternalNodeStorageBase, self).__init__(name)
+ self.class_name_mangler = NameMangler.classes
+ if compose_node_name:
+ self.node_name_mangler = NameMangler.composed_nodes
+ else:
+ self.node_name_mangler = NameMangler.nodes
diff --git a/reclass/storage/mixed/__init__.py b/reclass/storage/mixed/__init__.py
index 6324c74..45262cc 100644
--- a/reclass/storage/mixed/__init__.py
+++ b/reclass/storage/mixed/__init__.py
@@ -14,7 +14,7 @@
import reclass.errors
from reclass import get_storage
-from reclass.storage import NodeStorageBase
+from reclass.storage import ExternalNodeStorageBase
def path_mangler(inventory_base_uri, nodes_uri, classes_uri):
if nodes_uri == classes_uri:
@@ -23,17 +23,17 @@
STORAGE_NAME = 'mixed'
-class ExternalNodeStorage(NodeStorageBase):
+class ExternalNodeStorage(ExternalNodeStorageBase):
MixedUri = collections.namedtuple('MixedURI', 'storage_type options')
- def __init__(self, nodes_uri, classes_uri):
- super(ExternalNodeStorage, self).__init__(STORAGE_NAME)
+ def __init__(self, nodes_uri, classes_uri, compose_node_name):
+ super(ExternalNodeStorage, self).__init__(STORAGE_NAME, compose_node_name)
self._nodes_uri = self._uri(nodes_uri)
- self._nodes_storage = get_storage(self._nodes_uri.storage_type, self._nodes_uri.options, None)
+ self._nodes_storage = get_storage(self._nodes_uri.storage_type, self._nodes_uri.options, None, compose_node_name)
self._classes_default_uri = self._uri(classes_uri)
- self._classes_default_storage = get_storage(self._classes_default_uri.storage_type, None, self._classes_default_uri.options)
+ self._classes_default_storage = get_storage(self._classes_default_uri.storage_type, None, self._classes_default_uri.options, compose_node_name)
self._classes_storage = dict()
if 'env_overrides' in classes_uri:
@@ -42,7 +42,7 @@
uri = copy.deepcopy(classes_uri)
uri.update(options)
uri = self._uri(uri)
- self._classes_storage[env] = get_storage(uri.storage_type, None, uri.options)
+ self._classes_storage[env] = get_storage(uri.storage_type, None, uri.options, compose_node_name)
def _uri(self, uri):
ret = copy.deepcopy(uri)
diff --git a/reclass/storage/yaml_fs/__init__.py b/reclass/storage/yaml_fs/__init__.py
index 7ed3fe4..0ea0b05 100644
--- a/reclass/storage/yaml_fs/__init__.py
+++ b/reclass/storage/yaml_fs/__init__.py
@@ -15,8 +15,7 @@
import fnmatch
import yaml
from reclass.output.yaml_outputter import ExplicitDumper
-from reclass.storage import NodeStorageBase
-from reclass.storage.common import NameMangler
+from reclass.storage import ExternalNodeStorageBase
from reclass.storage.yamldata import YamlData
from .directory import Directory
from reclass.datatypes import Entity
@@ -53,22 +52,18 @@
return n, c
-class ExternalNodeStorage(NodeStorageBase):
+class ExternalNodeStorage(ExternalNodeStorageBase):
def __init__(self, nodes_uri, classes_uri, compose_node_name):
- super(ExternalNodeStorage, self).__init__(STORAGE_NAME)
+ super(ExternalNodeStorage, self).__init__(STORAGE_NAME, compose_node_name)
if nodes_uri is not None:
self._nodes_uri = nodes_uri
- if compose_node_name:
- self._nodes = self._enumerate_inventory(nodes_uri, NameMangler.composed_nodes)
- else:
- self._nodes = self._enumerate_inventory(nodes_uri, NameMangler.nodes)
-
+ self._nodes = self._enumerate_inventory(nodes_uri, self.node_name_mangler)
if classes_uri is not None:
self._classes_uri = classes_uri
- self._classes = self._enumerate_inventory(classes_uri, NameMangler.classes)
+ self._classes = self._enumerate_inventory(classes_uri, self.class_name_mangler)
nodes_uri = property(lambda self: self._nodes_uri)
classes_uri = property(lambda self: self._classes_uri)
diff --git a/reclass/storage/yaml_git/__init__.py b/reclass/storage/yaml_git/__init__.py
index 38de092..45cb6c0 100644
--- a/reclass/storage/yaml_git/__init__.py
+++ b/reclass/storage/yaml_git/__init__.py
@@ -28,8 +28,7 @@
from six import iteritems
import reclass.errors
-from reclass.storage import NodeStorageBase
-from reclass.storage.common import NameMangler
+from reclass.storage import ExternalNodeStorageBase
from reclass.storage.yamldata import YamlData
FILE_EXTENSION = '.yml'
@@ -75,7 +74,7 @@
class GitRepo(object):
- def __init__(self, uri):
+ def __init__(self, uri, node_name_mangler, class_name_mangler):
if pygit2 is None:
raise errors.MissingModuleError('pygit2')
self.transport, _, self.url = uri.repo.partition('://')
@@ -87,6 +86,8 @@
else:
self.cache_dir = '{0}/{1}'.format(uri.cache_dir, self.name)
+ self._node_name_mangler = node_name_mangler
+ self._class_name_mangler = class_name_mangler
self._init_repo(uri)
self._fetch()
self.branches = self.repo.listall_branches()
@@ -184,7 +185,8 @@
if fnmatch.fnmatch(file.name, '*{0}'.format(FILE_EXTENSION)):
name = os.path.splitext(file.name)[0]
relpath = os.path.dirname(file.path)
- relpath, name = NameMangler.classes(relpath, name)
+ if callable(self._class_name_mangler):
+ relpath, name = self._class_name_mangler(relpath, name)
if name in ret:
raise reclass.errors.DuplicateNodeNameError(self.name + ' - ' + bname, name, ret[name], path)
else:
@@ -197,16 +199,19 @@
for (name, file) in iteritems(self.files[branch]):
if subdir is None or name.startswith(subdir):
node_name = os.path.splitext(file.name)[0]
+ relpath = os.path.dirname(file.path)
+ if callable(self._node_name_mangler):
+ relpath, node_name = self._node_name_mangler(relpath, node_name)
if node_name in ret:
raise reclass.errors.DuplicateNodeNameError(self.name, name, files[name], path)
else:
ret[node_name] = file
return ret
-class ExternalNodeStorage(NodeStorageBase):
+class ExternalNodeStorage(ExternalNodeStorageBase):
- def __init__(self, nodes_uri, classes_uri):
- super(ExternalNodeStorage, self).__init__(STORAGE_NAME)
+ def __init__(self, nodes_uri, classes_uri, compose_node_name):
+ super(ExternalNodeStorage, self).__init__(STORAGE_NAME, compose_node_name)
self._repos = dict()
if nodes_uri is not None:
@@ -261,7 +266,7 @@
def _load_repo(self, uri):
if uri.repo not in self._repos:
- self._repos[uri.repo] = GitRepo(uri)
+ self._repos[uri.repo] = GitRepo(uri, self.node_name_mangler, self.class_name_mangler)
def _env_to_uri(self, environment):
ret = None