mangle paths inside config module already
Signed-off-by: martin f. krafft <madduck@madduck.net>
diff --git a/reclass/__init__.py b/reclass/__init__.py
index 8c6d625..2a794e8 100644
--- a/reclass/__init__.py
+++ b/reclass/__init__.py
@@ -9,7 +9,6 @@
from output import OutputLoader
from storage import StorageBackendLoader
-from config import path_mangler
def get_storage(storage_type, nodes_uri, classes_uri, class_mappings):
storage_class = StorageBackendLoader(storage_type).load()
@@ -18,8 +17,6 @@
def get_nodeinfo(storage_type, inventory_base_uri, nodes_uri, classes_uri,
nodename, class_mappings):
- nodes_uri, classes_uri = path_mangler(inventory_base_uri, nodes_uri,
- classes_uri)
storage = get_storage(storage_type, nodes_uri, classes_uri,
class_mappings)
# TODO: template interpolation
@@ -28,8 +25,6 @@
def get_inventory(storage_type, inventory_base_uri, nodes_uri, classes_uri,
class_mappings):
- nodes_uri, classes_uri = path_mangler(inventory_base_uri, nodes_uri,
- classes_uri)
storage = get_storage(storage_type, nodes_uri, classes_uri,
class_mappings)
return storage.inventory()
diff --git a/reclass/config.py b/reclass/config.py
index 3f2d683..17d0dc6 100644
--- a/reclass/config.py
+++ b/reclass/config.py
@@ -128,6 +128,30 @@
return parser, option_checker
+def path_mangler(inventory_base_uri, nodes_uri, classes_uri):
+
+ if inventory_base_uri is None:
+ # if inventory_base is not given, default to current directory
+ inventory_base_uri = os.getcwd()
+
+ nodes_uri = nodes_uri or 'nodes'
+ classes_uri = classes_uri or 'classes'
+
+ def _path_mangler_inner(path):
+ ret = os.path.join(inventory_base_uri, path)
+ ret = os.path.expanduser(ret)
+ return os.path.abspath(ret)
+
+ n, c = map(_path_mangler_inner, (nodes_uri, classes_uri))
+ if n == c:
+ raise errors.DuplicateUriError(n, c)
+ common = os.path.commonprefix((n, c))
+ if common == n or common == c:
+ raise errors.UriOverlapError(n, c)
+
+ return n, c
+
+
def get_options(name, version, description,
inventory_shortopt='-i',
inventory_longopt='--inventory',
@@ -151,6 +175,10 @@
options, args = parser.parse_args()
checker(options, args)
+ options.nodes_uri, options.classes_uri = \
+ path_mangler(options.inventory_base_uri, options.nodes_uri,
+ options.classes_uri)
+
return options
@@ -169,27 +197,3 @@
elif os.path.isfile(f):
raise PermissionsError('cannot read %s' % f)
return {}
-
-
-def path_mangler(inventory_base_uri, nodes_uri, classes_uri):
-
- if inventory_base_uri is None:
- # if inventory_base is not given, default to current directory
- inventory_base_uri = os.getcwd()
-
- nodes_uri = nodes_uri or 'nodes'
- classes_uri = classes_uri or 'classes'
-
- def _path_mangler_inner(path):
- ret = os.path.join(inventory_base_uri, path)
- ret = os.path.expanduser(ret)
- return os.path.abspath(ret)
-
- n, c = map(_path_mangler_inner, (nodes_uri, classes_uri))
- if n == c:
- raise errors.DuplicateUriError(n, c)
- common = os.path.commonprefix((n, c))
- if common == n or common == c:
- raise errors.UriOverlapError(n, c)
-
- return n, c