Merge remote-tracking branch 'steven/master'
This commit is contained in:
commit
32f1e2efb6
2 changed files with 57 additions and 139 deletions
|
@ -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():
|
||||
|
@ -79,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())
|
||||
|
||||
|
@ -123,6 +138,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,23 +203,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):
|
||||
"""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):
|
||||
|
@ -209,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
|
||||
|
||||
|
|
|
@ -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,111 +34,57 @@ 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.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")
|
||||
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 '<Type name=%s>' % 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 '<Type %s>' % self.name
|
||||
|
||||
@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"))
|
||||
except EnvironmentError as e:
|
||||
self.__explorers = os.listdir(os.path.join(self.absolute_path, "explorer"))
|
||||
except EnvironmentError:
|
||||
# error ignored
|
||||
self.__explorers = []
|
||||
return self.__explorers
|
||||
|
@ -151,10 +95,10 @@ 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 as e:
|
||||
except EnvironmentError:
|
||||
# error ignored
|
||||
pass
|
||||
finally:
|
||||
|
@ -167,10 +111,10 @@ 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 as e:
|
||||
except EnvironmentError:
|
||||
# error ignored
|
||||
pass
|
||||
finally:
|
||||
|
|
Loading…
Reference in a new issue