From 747517f06782db10da115f3f66f2115cf7e4fa48 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 23 Sep 2011 17:06:42 +0200 Subject: [PATCH] import path information from current cdist Signed-off-by: Nico Schottelius --- module/cdist/path.py | 56 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/module/cdist/path.py b/module/cdist/path.py index 37d92940..ee492cc5 100644 --- a/module/cdist/path.py +++ b/module/cdist/path.py @@ -1,11 +1,59 @@ class Path: """Class that handles path related configurations""" - def __init__(self, home=None): + def __init__(self, target_host, base_dir=None): + # Base and Temp Base if home: - self.base_dir = home + self.base_dir = base_dir else: self.base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) - - print("Base:" + self.base_dir) + self.temp_dir = tempfile.mkdtemp() + + self.conf_dir = os.path.join(self.base_dir, "conf") + self.cache_base_dir = os.path.join(self.base_dir, "cache") + self.cache_dir = os.path.join(self.cache_base_dir, target_host) + self.global_explorer_dir = os.path.join(self.conf_dir, "explorer") + self.lib_dir = os.path.join(self.base_dir, "lib") + self.manifest_dir = os.path.join(self.conf_dir, "manifest") + self.type_base_dir = os.path.join(self.conf_dir, "type") + + self.out_dir = os.path.join(self.temp_dir, "out") + os.mkdir(self.out_dir) + + self.global_explorer_out_dir = os.path.join(self.out_dir, "explorer") + os.mkdir(self.global_explorer_out_dir) + + self.object_base_dir = os.path.join(self.out_dir, "object") + + # Setup binary directory + contents + self.bin_dir = os.path.join(self.out_dir, "bin") + os.mkdir(self.bin_dir) + self.link_type_to_emulator() + + # List of type explorers transferred + self.type_explorers_transferred = {} + + # objects + self.objects_prepared = [] + + self.remote_user = remote_user + + # Mostly static, but can be overwritten on user demand + if initial_manifest: + self.initial_manifest = initial_manifest + else: + self.initial_manifest = os.path.join(self.manifest_dir, "init") + + def cleanup(self): + # Do not use in __del__: + # http://docs.python.org/reference/datamodel.html#customization + # "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) + # Remove previous cache + if os.path.exists(self.cache_dir): + shutil.rmtree(self.cache_dir) + shutil.move(self.temp_dir, self.cache_dir) +