From 2b1c4df8d97686a6c80e1e55c4139b6b2f6bffd6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:01:47 +0200 Subject: [PATCH 01/14] have explorers been transferred? (type) Signed-off-by: Nico Schottelius --- lib/cdist/core/type.py | 5 ++++- lib/cdist/path.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cdist/core/type.py b/lib/cdist/core/type.py index 126b4d16..7492659e 100644 --- a/lib/cdist/core/type.py +++ b/lib/cdist/core/type.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # -# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -68,6 +69,8 @@ class Type(object): self.__required_parameters = None self.__optional_parameters = None + self.transferred_explorers = False + def __repr__(self): return '' % self.name diff --git a/lib/cdist/path.py b/lib/cdist/path.py index f7d2a8ae..e2d319ef 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -255,12 +255,12 @@ class Path: # Stays here - FIXME: adjust to type code, loop over types! def transfer_type_explorers(self, type): """Transfer explorers of a type, but only once""" - if type.transferred: + if type.transferred_explorers: log.debug("Skipping retransfer for explorers of %s", type) return else: # Do not retransfer - type.transferred = True + type.transferred_explorers = True # FIXME: Can be explorer_path or explorer_dir, I don't care. src = type.explorer_path() From 6be542d9bb5ed50aa7a71e2a6d57b4a3eac940f6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:05:26 +0200 Subject: [PATCH 02/14] missing functionality in oo Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index e69de29b..0ff17f6a 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -0,0 +1,8 @@ +Object: + code_remote + code_local + gencode_local + gencode_remote + +Type: + explorer_path From 1810462989c6ad6e81137ad2168907a14effe364 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:05:42 +0200 Subject: [PATCH 03/14] move stuff over from path to object to be fixed Signed-off-by: Nico Schottelius --- lib/cdist/core/object.py | 36 +++++++++++++++++++++++++++++++++++- lib/cdist/path.py | 31 ------------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index dbb6542d..e75c06c8 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -161,4 +161,38 @@ class Object(object): pass ### /changed - # FIXME: implement other properties/methods + # FIXME: implement other properties/methods + + # FIXME: check following methods: implement or revoke / delete + # FIXME: Object + def get_object_id_from_object(self, cdist_object): + """Returns everything but the first part (i.e. object_id) of an object""" + return os.sep.join(cdist_object.split(os.sep)[1:]) + + # FIXME: Object + def object_dir(self, cdist_object): + """Returns the full path to the object (including .cdist)""" + return os.path.join(self.object_base_dir, cdist_object, DOT_CDIST) + + # FIXME: Object + def remote_object_dir(self, cdist_object): + """Returns the remote full path to the object (including .cdist)""" + return os.path.join(REMOTE_OBJECT_DIR, cdist_object, DOT_CDIST) + + # FIXME: Object + def object_parameter_dir(self, cdist_object): + """Returns the dir to the object parameter""" + return os.path.join(self.object_dir(cdist_object), "parameter") + + # FIXME: object + def remote_object_parameter_dir(self, cdist_object): + """Returns the remote dir to the object parameter""" + return os.path.join(self.remote_object_dir(cdist_object), "parameter") + + # FIXME: object + def object_code_paths(self, cdist_object): + """Return paths to code scripts of object""" + return [os.path.join(self.object_dir(cdist_object), "code-local"), + os.path.join(self.object_dir(cdist_object), "code-remote")] + + diff --git a/lib/cdist/path.py b/lib/cdist/path.py index e2d319ef..99adfe99 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -192,37 +192,6 @@ class Path: return object_paths - # FIXME: Object - def get_object_id_from_object(self, cdist_object): - """Returns everything but the first part (i.e. object_id) of an object""" - return os.sep.join(cdist_object.split(os.sep)[1:]) - - # FIXME: Object - def object_dir(self, cdist_object): - """Returns the full path to the object (including .cdist)""" - return os.path.join(self.object_base_dir, cdist_object, DOT_CDIST) - - # FIXME: Object - def remote_object_dir(self, cdist_object): - """Returns the remote full path to the object (including .cdist)""" - return os.path.join(REMOTE_OBJECT_DIR, cdist_object, DOT_CDIST) - - # FIXME: Object - def object_parameter_dir(self, cdist_object): - """Returns the dir to the object parameter""" - return os.path.join(self.object_dir(cdist_object), "parameter") - - # FIXME: object - def remote_object_parameter_dir(self, cdist_object): - """Returns the remote dir to the object parameter""" - return os.path.join(self.remote_object_dir(cdist_object), "parameter") - - # FIXME: object - def object_code_paths(self, cdist_object): - """Return paths to code scripts of object""" - return [os.path.join(self.object_dir(cdist_object), "code-local"), - os.path.join(self.object_dir(cdist_object), "code-remote")] - # Stays here def list_objects(self): """Return list of existing objects""" From cf97fd9837c4253613ba809b9d87763197741d51 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:27:46 +0200 Subject: [PATCH 04/14] remove type_explorer information from path Signed-off-by: Nico Schottelius --- lib/cdist/path.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 99adfe99..4c36bfa5 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -92,7 +92,6 @@ class Path: self.object_base_dir = os.path.join(self.out_dir, "object") self.bin_dir = os.path.join(self.out_dir, "bin") - os.environ['__cdist_out_dir'] = self.out_dir # List of type explorers transferred self.type_explorers_transferred = {} @@ -116,6 +115,10 @@ class Path: shutil.move(self.temp_dir, self.cache_dir) + def __init_env(self): + """Setup environment""" + os.environ['__cdist_out_dir'] = self.out_dir + def __init_out_dirs(self): """Initialise output directory structure""" os.mkdir(self.out_dir) From e26f6120123c142fcbb949eaa69c1d20aa089f18 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:29:22 +0200 Subject: [PATCH 05/14] move file_to_list to cdist Signed-off-by: Nico Schottelius --- lib/cdist/__init__.py | 14 ++++++++++++++ lib/cdist/emulator.py | 4 ++-- lib/cdist/path.py | 21 --------------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/cdist/__init__.py b/lib/cdist/__init__.py index fcfa3693..3a1b94e3 100644 --- a/lib/cdist/__init__.py +++ b/lib/cdist/__init__.py @@ -34,3 +34,17 @@ class MissingEnvironmentVariableError(Error): def __str__(self): return 'Missing required environment variable: ' + str(self.name) + +def file_to_list(filename): + """Return list from \n seperated file""" + if os.path.isfile(filename): + file_fd = open(filename, "r") + lines = file_fd.readlines() + file_fd.close() + + # Remove \n from all lines + lines = map(lambda s: s.strip(), lines) + else: + lines = [] + + return lines diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index 51b2ecc1..f3e9ac30 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -43,10 +43,10 @@ def run(argv): parser = argparse.ArgumentParser(add_help=False) - for parameter in cdist.path.file_to_list(os.path.join(param_dir, "optional")): + for parameter in cdist.file_to_list(os.path.join(param_dir, "optional")): argument = "--" + parameter parser.add_argument(argument, action='store', required=False) - for parameter in cdist.path.file_to_list(os.path.join(param_dir, "required")): + for parameter in cdist.file_to_list(os.path.join(param_dir, "required")): argument = "--" + parameter parser.add_argument(argument, action='store', required=True) diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 4c36bfa5..50977afd 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -38,20 +38,6 @@ log = logging.getLogger(__name__) import cdist.exec -def file_to_list(filename): - """Return list from \n seperated file""" - if os.path.isfile(filename): - file_fd = open(filename, "r") - lines = file_fd.readlines() - file_fd.close() - - # Remove \n from all lines - lines = map(lambda s: s.strip(), lines) - else: - lines = [] - - return lines - class Path: """Class that handles path related configurations""" @@ -92,13 +78,6 @@ class Path: self.object_base_dir = os.path.join(self.out_dir, "object") self.bin_dir = os.path.join(self.out_dir, "bin") - - # List of type explorers transferred - self.type_explorers_transferred = {} - - # objects prepared - self.objects_prepared = [] - # Create directories self.__init_out_dirs() From ee69971465a61874e65eebc2665ed23a2d8c9082 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:38:52 +0200 Subject: [PATCH 06/14] make temp_dir unecessary / only implementation detail Signed-off-by: Nico Schottelius --- lib/cdist/path.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 50977afd..b9d0b6bf 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -41,22 +41,16 @@ import cdist.exec class Path: """Class that handles path related configurations""" - def __init__(self, - target_host, - initial_manifest=False, - base_dir=None, - debug=False): - - # Base and Temp Base - if base_dir: - self.base_dir = base_dir - else: - self.base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) - - self.temp_dir = tempfile.mkdtemp() + def __init__(self, target_host, initial_manifest=False, debug=False): self.target_host = target_host + # Base and Temp Base + if "__cdist_base_dir" in os.environ: + self.base_dir = os.environ['__cdist_base_dir'] + else: + self.base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + # Input directories self.conf_dir = os.path.join(self.base_dir, "conf") self.cache_base_dir = os.path.join(self.base_dir, "cache") @@ -73,7 +67,11 @@ class Path: self.initial_manifest = os.path.join(self.manifest_dir, "init") # Output directories - self.out_dir = os.path.join(self.temp_dir, "out") + if "__cdist_out_dir" in os.environ: + self.out_dir = os.environ['__cdist_out_dir'] + else: + self.out_dir = os.path.join(tempfile.mkdtemp(), "out") + self.global_explorer_out_dir = os.path.join(self.out_dir, "explorer") self.object_base_dir = os.path.join(self.out_dir, "object") self.bin_dir = os.path.join(self.out_dir, "bin") @@ -87,12 +85,11 @@ class Path: # "other globals referenced by the __del__() method may already have been deleted # or in the process of being torn down (e.g. the import machinery shutting down)" # - log.debug("Saving" + self.temp_dir + "to " + self.cache_dir) + log.debug("Saving" + self.base_dir + "to " + self.cache_dir) # Remove previous cache if os.path.exists(self.cache_dir): shutil.rmtree(self.cache_dir) - shutil.move(self.temp_dir, self.cache_dir) - + shutil.move(self.base_dir, self.cache_dir) def __init_env(self): """Setup environment""" @@ -100,6 +97,11 @@ class Path: def __init_out_dirs(self): """Initialise output directory structure""" + + # Create base dir, if user supplied and not existing + if not os.isdir(self.base_dir): + os.mkdir(self.base_dir) + os.mkdir(self.out_dir) os.mkdir(self.global_explorer_out_dir) os.mkdir(self.bin_dir) From 06f438f824afc0ae5d9a28b78f65ee090e5d0174 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:46:06 +0200 Subject: [PATCH 07/14] move stuff from path to object, remove if already existent Signed-off-by: Nico Schottelius --- lib/cdist/core/object.py | 37 ++++++++++++++++++++ lib/cdist/path.py | 73 +++------------------------------------- 2 files changed, 42 insertions(+), 68 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index e75c06c8..85822a24 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -195,4 +195,41 @@ class Object(object): return [os.path.join(self.object_dir(cdist_object), "code-local"), os.path.join(self.object_dir(cdist_object), "code-remote")] + # Stays here + def list_object_paths(self, starting_point): + """Return list of paths of existing objects""" + object_paths = [] + + for content in os.listdir(starting_point): + full_path = os.path.join(starting_point, content) + if os.path.isdir(full_path): + object_paths.extend(self.list_object_paths(starting_point = full_path)) + + # Directory contains .cdist -> is an object + if content == DOT_CDIST: + object_paths.append(starting_point) + + return object_paths + + # Stays here + def list_objects(self): + """Return list of existing objects""" + + objects = [] + if os.path.isdir(self.object_base_dir): + object_paths = self.list_object_paths(self.object_base_dir) + + for path in object_paths: + objects.append(os.path.relpath(path, self.object_base_dir)) + + return objects + + # FIXME: object + def type_explorer_output_dir(self, cdist_object): + """Returns and creates dir of the output for a type explorer""" + dir = os.path.join(self.object_dir(cdist_object), "explorer") + if not os.path.isdir(dir): + os.mkdir(dir) + + return dir diff --git a/lib/cdist/path.py b/lib/cdist/path.py index b9d0b6bf..448fc918 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -106,90 +106,27 @@ class Path: os.mkdir(self.global_explorer_out_dir) os.mkdir(self.bin_dir) - - # Stays here - def list_types(self): - """Retuns list of types""" - return os.listdir(self.type_base_dir) - - ###################################################################### - - # FIXME: belongs to here - clearify remote* def remote_mkdir(self, directory): """Create directory on remote side""" cdist.exec.run_or_fail(["mkdir", "-p", directory], remote_prefix=True) - # FIXME: belongs to here - clearify remote* def remove_remote_dir(self, destination): cdist.exec.run_or_fail(["rm", "-rf", destination], remote_prefix=True) - # FIXME: belongs to here - clearify remote* + # FIXME: To Copy def transfer_dir(self, source, destination): """Transfer directory and previously delete the remote destination""" self.remove_remote_dir(destination) cdist.exec.run_or_fail(os.environ['__remote_copy'].split() + ["-r", source, self.target_host + ":" + destination]) - # FIXME: belongs to here - clearify remote* + # FIXME: To Copy def transfer_file(self, source, destination): """Transfer file""" cdist.exec.run_or_fail(os.environ['__remote_copy'].split() + [source, self.target_host + ":" + destination]) - # FIXME: Explorer or stays - def global_explorer_output_path(self, explorer): - """Returns path of the output for a global explorer""" - return os.path.join(self.global_explorer_out_dir, explorer) - - # FIXME: object - def type_explorer_output_dir(self, cdist_object): - """Returns and creates dir of the output for a type explorer""" - dir = os.path.join(self.object_dir(cdist_object), "explorer") - if not os.path.isdir(dir): - os.mkdir(dir) - - return dir - - # FIXME Stays here / Explorer? - def remote_global_explorer_path(self, explorer): - """Returns path to the remote explorer""" - return os.path.join(REMOTE_GLOBAL_EXPLORER_DIR, explorer) - - # FIXME: stays here - def list_global_explorers(self): - """Return list of available explorers""" - return os.listdir(self.global_explorer_dir) - - # Stays here - def list_object_paths(self, starting_point): - """Return list of paths of existing objects""" - object_paths = [] - - for content in os.listdir(starting_point): - full_path = os.path.join(starting_point, content) - if os.path.isdir(full_path): - object_paths.extend(self.list_object_paths(starting_point = full_path)) - - # Directory contains .cdist -> is an object - if content == DOT_CDIST: - object_paths.append(starting_point) - - return object_paths - - # Stays here - def list_objects(self): - """Return list of existing objects""" - - objects = [] - if os.path.isdir(self.object_base_dir): - object_paths = self.list_object_paths(self.object_base_dir) - - for path in object_paths: - objects.append(os.path.relpath(path, self.object_base_dir)) - - return objects - - # Stays here + # FIXME Move into configinstall def transfer_object_parameter(self, cdist_object): """Transfer the object parameter to the remote destination""" # Create base path before using mkdir -p @@ -199,13 +136,13 @@ class Path: self.transfer_dir(self.object_parameter_dir(cdist_object), self.remote_object_parameter_dir(cdist_object)) - # Stays here + # FIXME Move into configinstall def transfer_global_explorers(self): """Transfer the global explorers""" self.remote_mkdir(REMOTE_GLOBAL_EXPLORER_DIR) self.transfer_dir(self.global_explorer_dir, REMOTE_GLOBAL_EXPLORER_DIR) - # Stays here - FIXME: adjust to type code, loop over types! + # FIXME Move into configinstall def transfer_type_explorers(self, type): """Transfer explorers of a type, but only once""" if type.transferred_explorers: From 0b63919cdd3b8f74b11a66016098e2d213de908c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:46:48 +0200 Subject: [PATCH 08/14] path -> copy Signed-off-by: Nico Schottelius --- lib/cdist/copy.py | 13 +++++++++++++ lib/cdist/path.py | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 lib/cdist/copy.py diff --git a/lib/cdist/copy.py b/lib/cdist/copy.py new file mode 100644 index 00000000..b0eae54e --- /dev/null +++ b/lib/cdist/copy.py @@ -0,0 +1,13 @@ + # FIXME: To Copy + def transfer_dir(self, source, destination): + """Transfer directory and previously delete the remote destination""" + self.remove_remote_dir(destination) + cdist.exec.run_or_fail(os.environ['__remote_copy'].split() + + ["-r", source, self.target_host + ":" + destination]) + + # FIXME: To Copy + def transfer_file(self, source, destination): + """Transfer file""" + cdist.exec.run_or_fail(os.environ['__remote_copy'].split() + + [source, self.target_host + ":" + destination]) + diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 448fc918..2f6670e8 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -113,19 +113,6 @@ class Path: def remove_remote_dir(self, destination): cdist.exec.run_or_fail(["rm", "-rf", destination], remote_prefix=True) - # FIXME: To Copy - def transfer_dir(self, source, destination): - """Transfer directory and previously delete the remote destination""" - self.remove_remote_dir(destination) - cdist.exec.run_or_fail(os.environ['__remote_copy'].split() + - ["-r", source, self.target_host + ":" + destination]) - - # FIXME: To Copy - def transfer_file(self, source, destination): - """Transfer file""" - cdist.exec.run_or_fail(os.environ['__remote_copy'].split() + - [source, self.target_host + ":" + destination]) - # FIXME Move into configinstall def transfer_object_parameter(self, cdist_object): """Transfer the object parameter to the remote destination""" From 08975c4d2f2f78fa13fc0ed1fa07c96d557670da Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:47:29 +0200 Subject: [PATCH 09/14] path -> config_install Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 36 ++++++++++++++++++++++++++++++++++++ lib/cdist/path.py | 35 ----------------------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index 2071a0e9..9e2b5edc 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -278,3 +278,39 @@ class ConfigInstall: self.run_type_manifest(cdist_object) cdist_object.prepared = True new_objects_created = True + + # FIXME Move into configinstall + def transfer_object_parameter(self, cdist_object): + """Transfer the object parameter to the remote destination""" + # Create base path before using mkdir -p + self.remote_mkdir(self.remote_object_parameter_dir(cdist_object)) + + # Synchronise parameter dir afterwards + self.transfer_dir(self.object_parameter_dir(cdist_object), + self.remote_object_parameter_dir(cdist_object)) + + # FIXME Move into configinstall + def transfer_global_explorers(self): + """Transfer the global explorers""" + self.remote_mkdir(REMOTE_GLOBAL_EXPLORER_DIR) + self.transfer_dir(self.global_explorer_dir, REMOTE_GLOBAL_EXPLORER_DIR) + + # FIXME Move into configinstall + def transfer_type_explorers(self, type): + """Transfer explorers of a type, but only once""" + if type.transferred_explorers: + log.debug("Skipping retransfer for explorers of %s", type) + return + else: + # Do not retransfer + type.transferred_explorers = True + + # FIXME: Can be explorer_path or explorer_dir, I don't care. + src = type.explorer_path() + dst = type.remote_explorer_path() + + # Transfer if there is at least one explorer + if len(type.explorers) > 0: + # Ensure that the path exists + self.remote_mkdir(dst) + self.transfer_dir(src, dst) diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 2f6670e8..2dc06ceb 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -113,38 +113,3 @@ class Path: def remove_remote_dir(self, destination): cdist.exec.run_or_fail(["rm", "-rf", destination], remote_prefix=True) - # FIXME Move into configinstall - def transfer_object_parameter(self, cdist_object): - """Transfer the object parameter to the remote destination""" - # Create base path before using mkdir -p - self.remote_mkdir(self.remote_object_parameter_dir(cdist_object)) - - # Synchronise parameter dir afterwards - self.transfer_dir(self.object_parameter_dir(cdist_object), - self.remote_object_parameter_dir(cdist_object)) - - # FIXME Move into configinstall - def transfer_global_explorers(self): - """Transfer the global explorers""" - self.remote_mkdir(REMOTE_GLOBAL_EXPLORER_DIR) - self.transfer_dir(self.global_explorer_dir, REMOTE_GLOBAL_EXPLORER_DIR) - - # FIXME Move into configinstall - def transfer_type_explorers(self, type): - """Transfer explorers of a type, but only once""" - if type.transferred_explorers: - log.debug("Skipping retransfer for explorers of %s", type) - return - else: - # Do not retransfer - type.transferred_explorers = True - - # FIXME: Can be explorer_path or explorer_dir, I don't care. - src = type.explorer_path() - dst = type.remote_explorer_path() - - # Transfer if there is at least one explorer - if len(type.explorers) > 0: - # Ensure that the path exists - self.remote_mkdir(dst) - self.transfer_dir(src, dst) From 886c1d32acfa31ec156eccdb3e3169af1053437a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:48:43 +0200 Subject: [PATCH 10/14] DOT_CDIST -> cdist Signed-off-by: Nico Schottelius --- lib/cdist/__init__.py | 1 + lib/cdist/path.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cdist/__init__.py b/lib/cdist/__init__.py index 3a1b94e3..6ce0c788 100644 --- a/lib/cdist/__init__.py +++ b/lib/cdist/__init__.py @@ -20,6 +20,7 @@ # VERSION = "2.0.3" +DOT_CDIST = ".cdist" class Error(Exception): """Base exception class for this project""" diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 2dc06ceb..9921dd0f 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -32,8 +32,6 @@ REMOTE_OBJECT_DIR = os.path.join(REMOTE_BASE_DIR, "object") REMOTE_TYPE_DIR = os.path.join(REMOTE_CONF_DIR, "type") REMOTE_GLOBAL_EXPLORER_DIR = os.path.join(REMOTE_CONF_DIR, "explorer") -DOT_CDIST = ".cdist" - log = logging.getLogger(__name__) import cdist.exec From 359e5156e27c7f1b397062b07bbe3dbc438c8e43 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:52:37 +0200 Subject: [PATCH 11/14] +globalexplorer start Signed-off-by: Nico Schottelius --- lib/cdist/core/globalexplorer.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/cdist/core/globalexplorer.py diff --git a/lib/cdist/core/globalexplorer.py b/lib/cdist/core/globalexplorer.py new file mode 100644 index 00000000..1af466e0 --- /dev/null +++ b/lib/cdist/core/globalexplorer.py @@ -0,0 +1,15 @@ + # FIXME: Explorer or stays + def global_explorer_output_path(self, explorer): + """Returns path of the output for a global explorer""" + return os.path.join(self.global_explorer_out_dir, explorer) + + # FIXME Stays here / Explorer? + def remote_global_explorer_path(self, explorer): + """Returns path to the remote explorer""" + return os.path.join(REMOTE_GLOBAL_EXPLORER_DIR, explorer) + + # FIXME: stays here + def list_global_explorers(self): + """Return list of available explorers""" + return os.listdir(self.global_explorer_dir) + From 4b306e45f946ad3f01118ef59fdf512b4563fbe7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:53:09 +0200 Subject: [PATCH 12/14] more ideas for globalexplorer Signed-off-by: Nico Schottelius --- lib/cdist/core/globalexplorer.py | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/cdist/core/globalexplorer.py b/lib/cdist/core/globalexplorer.py index 1af466e0..49052d53 100644 --- a/lib/cdist/core/globalexplorer.py +++ b/lib/cdist/core/globalexplorer.py @@ -13,3 +13,54 @@ """Return list of available explorers""" return os.listdir(self.global_explorer_dir) +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +import logging +import os +log = logging.getLogger(__name__) + +class Explorer(object): + + def __init__(self, src_dir, dst_dir): + self.src_dir = src_dir + self.dst_dir = dst_dir + + def list_explorers(self): + """Return list of available explorers""" + dir = os.path.join(self.path, "explorer") + if os.path.isdir(dir): + list = os.listdir(dir) + else: + list = [] + + log.debug("Explorers for %s in %s: %s", type, dir, list) + + return list + + def is_install(self): + """Check whether a type is used for installation (if not: for configuration)""" + return os.path.isfile(os.path.join(self.path, "install")) + + def remote_explorer_dir(self): + """Return remote directory that holds the explorers of a type""" + return os.path.join(self.remote_path, "explorer") From 9540d529d687699fc2da7b03626fd6318965aa9a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 09:53:24 +0200 Subject: [PATCH 13/14] also allow to overwrite remote_base_dir Signed-off-by: Nico Schottelius --- lib/cdist/path.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/cdist/path.py b/lib/cdist/path.py index 9921dd0f..44b121df 100644 --- a/lib/cdist/path.py +++ b/lib/cdist/path.py @@ -25,12 +25,6 @@ import shutil import sys import tempfile -# Hardcoded paths usually not changable -REMOTE_BASE_DIR = "/var/lib/cdist" -REMOTE_CONF_DIR = os.path.join(REMOTE_BASE_DIR, "conf") -REMOTE_OBJECT_DIR = os.path.join(REMOTE_BASE_DIR, "object") -REMOTE_TYPE_DIR = os.path.join(REMOTE_CONF_DIR, "type") -REMOTE_GLOBAL_EXPLORER_DIR = os.path.join(REMOTE_CONF_DIR, "explorer") log = logging.getLogger(__name__) @@ -74,6 +68,17 @@ class Path: self.object_base_dir = os.path.join(self.out_dir, "object") self.bin_dir = os.path.join(self.out_dir, "bin") + # Remote directories + if "__cdist_remote_base_dir" in os.environ: + self.remote_base_dir = os.environ['__cdist_remote_base_dir'] + else: + self.remote_base_dir = "/var/lib/cdist" + + self.remote_conf_dir = os.path.join(self.remote_base_dir, "conf") + self.remote_object_dir = os.path.join(self.remote_base_dir, "object") + self.remote_type_dir = os.path.join(self.remote_conf_dir, "type") + self.remote_global_explorer_dir = os.path.join(self.remote_conf_dir, "explorer") + # Create directories self.__init_out_dirs() From 73fa0e1ab7ac34b1f621060332e7c72e69a6d0a2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 11:51:21 +0200 Subject: [PATCH 14/14] path becomes context (+1 happy developer) Signed-off-by: Nico Schottelius --- lib/cdist/{path.py => context.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/cdist/{path.py => context.py} (100%) diff --git a/lib/cdist/path.py b/lib/cdist/context.py similarity index 100% rename from lib/cdist/path.py rename to lib/cdist/context.py