From f39418a7b5f9d71c7ec49b1ffa1f5bbd1126ade0 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 7 Oct 2011 13:50:17 +0200 Subject: [PATCH 1/5] implement remote_code_remote :-( Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 42 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index c47fc905..b4469e61 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -31,7 +31,8 @@ log = logging.getLogger(__name__) DOT_CDIST = '.cdist' - +# FIXME: i should not have to care about prefix directory, local, remote and such. +# I know what my internals look like, the outside is none of my business. class Object(object): """Represents a cdist object. @@ -63,6 +64,21 @@ class Object(object): return base_dir @classmethod + def remote_base_dir(): + """Return the absolute path to the top level directory where objects + are kept on the remote/target host. + + Requires the environment variable '__cdist_remote_out_dir' to be set. + + """ + try: + return os.path.join( + os.environ['__cdist_remote_out_dir'], + 'object', + ) + except KeyError as e: + raise cdist.MissingEnvironmentVariableError(e.args[0]) + def list_objects(cls): """Return a list of object instances""" for object_name in cls.list_object_names(): @@ -123,6 +139,19 @@ class Object(object): os.mkdir(path) return path + # FIXME: prefix directory should not leak into me + @property + def remote_path(self): + return os.path.join( + self.remote_base_dir(), + self.name, + DOT_CDIST + ) + @property + def remote_code_remote(self): + return os.path.join(self.remote_path, "code-remote") + + ### requirements @property def requirements(self): @@ -175,18 +204,7 @@ class Object(object): pass ### /changed - # 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): From 1992c9a1751b0bc5c3143224ed8c46693fc87e46 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 7 Oct 2011 13:52:55 +0200 Subject: [PATCH 2/5] --legacy code Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 44 ---------------------------------------- 1 file changed, 44 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index b4469e61..b922701d 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -95,7 +95,6 @@ class Object(object): def list_object_names(cls): """Return a list of object names""" for path, dirs, files in os.walk(cls.base_dir()): - # FIXME: use constant instead of string if DOT_CDIST in dirs: yield os.path.relpath(path, cls.base_dir()) @@ -206,11 +205,6 @@ class Object(object): - # 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""" @@ -227,41 +221,3 @@ 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 - From c56d17d674cbaac17cf175713465cee95f6847c5 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 7 Oct 2011 15:07:57 +0200 Subject: [PATCH 3/5] relative paths Signed-off-by: Steven Armstrong --- lib/cdist/core/type.py | 98 +++++++++--------------------------------- 1 file changed, 20 insertions(+), 78 deletions(-) diff --git a/lib/cdist/core/type.py b/lib/cdist/core/type.py index 8439464e..4493be18 100644 --- a/lib/cdist/core/type.py +++ b/lib/cdist/core/type.py @@ -25,8 +25,6 @@ import os import cdist -# FIXME: i should not have to care about prefix directory, local, remote and such. -# I know what my internals look like, the outside is none of my business. class Type(object): """Represents a cdist type. @@ -36,93 +34,37 @@ class Type(object): """ - @staticmethod - def base_dir(): - """Return the absolute path to the top level directory where types - are defined. - - Requires the environment variable '__cdist_base_dir' to be set. - - """ - try: - return os.path.join( - os.environ['__cdist_base_dir'], - 'conf', - 'type' - ) - except KeyError as e: - raise cdist.MissingEnvironmentVariableError(e.args[0]) - - @staticmethod - def remote_base_dir(): - """Return the absolute path to the top level directory where types - are kept on the remote/target host. - - Requires the environment variable '__cdist_remote_base_dir' to be set. - - """ - try: - return os.path.join( - os.environ['__cdist_remote_base_dir'], - 'conf', - 'type' - ) - except KeyError as e: - raise cdist.MissingEnvironmentVariableError(e.args[0]) - @classmethod - def list_types(cls): + def list_types(cls, base_path): """Return a list of type instances""" - for type_name in cls.list_type_names(): - yield cls(type_name) + for name in cls.list_type_names(base_path): + yield cls(base_path, name) @classmethod - def list_type_names(cls): + def list_type_names(cls, base_path): """Return a list of type names""" - return os.listdir(cls.base_dir()) + return os.listdir(base_path) - def __init__(self, name): + def __init__(self, base_path, name): + self._base_path = base_path self.name = name + self.manifest_path = os.path.join(self.name, "manifest") + self.explorer_path = os.path.join(self.name, "explorer") + self.manifest_path = os.path.join(self.name, "manifest") + self.gencode_local_path = os.path.join(self.name, "gencode-local") + self.gencode_remote_path = os.path.join(self.name, "gencode-remote") + self.manifest_path = os.path.join(self.name, "manifest") + + self.transferred_explorers = False + self.__explorers = None self.__required_parameters = None self.__optional_parameters = None - self.transferred_explorers = False def __repr__(self): - return '' % self.name - - @property - def path(self): - return os.path.join( - self.base_dir(), - self.name - ) - # FIXME: prefix directory should not leak into me - @property - def remote_path(self): - return os.path.join( - self.remote_base_dir(), - self.name - ) - - # FIXME: probably wrong place for this - @property - def remote_explorer_dir(self): - return os.path.join(self.remote_path, "explorer") - - @property - def manifest_path(self): - return os.path.join(self.path, "manifest") - - @property - def gencode_local(self): - return os.path.join(self.path, "gencode-local") - - @property - def gencode_remote(self): - return os.path.join(self.path, "gencode-remote") + return '' % self.name @property def is_singleton(self): @@ -140,7 +82,7 @@ class Type(object): if not self.__explorers: try: self.__explorers = os.listdir(os.path.join(self.path, "explorer")) - except EnvironmentError as e: + except EnvironmentError: # error ignored self.__explorers = [] return self.__explorers @@ -154,7 +96,7 @@ class Type(object): with open(os.path.join(self.path, "parameter", "required")) as fd: for line in fd: parameters.append(line.strip()) - except EnvironmentError as e: + except EnvironmentError: # error ignored pass finally: @@ -170,7 +112,7 @@ class Type(object): with open(os.path.join(self.path, "parameter", "optional")) as fd: for line in fd: parameters.append(line.strip()) - except EnvironmentError as e: + except EnvironmentError: # error ignored pass finally: From ffb33189c76e3d53a67e1e3ae28e909aeefa4faa Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 7 Oct 2011 15:18:25 +0200 Subject: [PATCH 4/5] fix path/absolute_path handling Signed-off-by: Steven Armstrong --- lib/cdist/core/type.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/cdist/core/type.py b/lib/cdist/core/type.py index 4493be18..c701bf48 100644 --- a/lib/cdist/core/type.py +++ b/lib/cdist/core/type.py @@ -49,6 +49,8 @@ class Type(object): def __init__(self, base_path, name): self._base_path = base_path self.name = name + self.path = self.name + self.absolute_path = os.path.join(self._base_path, self.path) self.manifest_path = os.path.join(self.name, "manifest") self.explorer_path = os.path.join(self.name, "explorer") self.manifest_path = os.path.join(self.name, "manifest") @@ -66,22 +68,24 @@ class Type(object): def __repr__(self): return '' % self.name + def + @property def is_singleton(self): """Check whether a type is a singleton.""" - return os.path.isfile(os.path.join(self.path, "singleton")) + return os.path.isfile(os.path.join(self.absolute_path, "singleton")) @property 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")) + return os.path.isfile(os.path.join(self.absolute_path, "install")) @property def explorers(self): """Return a list of available explorers""" if not self.__explorers: try: - self.__explorers = os.listdir(os.path.join(self.path, "explorer")) + self.__explorers = os.listdir(os.path.join(self.absolute_path, "explorer")) except EnvironmentError: # error ignored self.__explorers = [] @@ -93,7 +97,7 @@ class Type(object): if not self.__required_parameters: parameters = [] try: - with open(os.path.join(self.path, "parameter", "required")) as fd: + with open(os.path.join(self.absolute_path, "parameter", "required")) as fd: for line in fd: parameters.append(line.strip()) except EnvironmentError: @@ -109,7 +113,7 @@ class Type(object): if not self.__optional_parameters: parameters = [] try: - with open(os.path.join(self.path, "parameter", "optional")) as fd: + with open(os.path.join(self.absolute_path, "parameter", "optional")) as fd: for line in fd: parameters.append(line.strip()) except EnvironmentError: From dd29e86b8163b3a09f42525b2ceed1f63156d0a9 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 7 Oct 2011 15:19:03 +0200 Subject: [PATCH 5/5] -syntax error Signed-off-by: Steven Armstrong --- lib/cdist/core/type.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/cdist/core/type.py b/lib/cdist/core/type.py index c701bf48..309528ef 100644 --- a/lib/cdist/core/type.py +++ b/lib/cdist/core/type.py @@ -68,8 +68,6 @@ class Type(object): def __repr__(self): return '' % self.name - def - @property def is_singleton(self): """Check whether a type is a singleton."""