Merge branch 'master' into feature_files_export

This commit is contained in:
Darko Poljak 2016-06-10 21:04:43 +02:00
commit e3636e6ffc
475 changed files with 10788 additions and 3878 deletions

View file

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2016 Darko Poljak (darko.poljak at gmail.com)
#
# This file is part of cdist.
#
@ -53,9 +54,18 @@ class Local(object):
# FIXME: stopped: create base that does not require moving later
if base_path:
self.base_path = base_path
base_path_parent = base_path
else:
self.base_path = tempfile.mkdtemp()
base_path_parent = tempfile.mkdtemp()
import atexit
atexit.register(lambda: shutil.rmtree(base_path_parent))
self.hostdir = self._hostdir()
self.base_path = os.path.join(base_path_parent, self.hostdir)
self._init_log()
self._init_permissions()
self.mkdir(self.base_path)
# FIXME: as well
self._init_cache_dir(None)
@ -65,12 +75,10 @@ class Local(object):
self._add_conf_dirs = add_conf_dirs
self._init_log()
self._init_permissions()
self._init_paths()
self._init_object_marker()
self._init_conf_dirs()
@property
def dist_conf_dir(self):
return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
@ -82,6 +90,13 @@ class Local(object):
else:
return None
def _hostdir(self):
if os.path.isabs(self.target_host):
hostdir = self.target_host[1:]
else:
hostdir = self.target_host
return hostdir
def _init_log(self):
self.log = logging.getLogger(self.target_host)
@ -105,6 +120,12 @@ class Local(object):
self.type_path = os.path.join(self.conf_path, "type")
def _init_object_marker(self):
self.object_marker_file = os.path.join(self.base_path, "object_marker")
# Does not need to be secure - just randomly different from .cdist
self.object_marker_name = tempfile.mktemp(prefix='.cdist-', dir='')
def _init_conf_dirs(self):
self.conf_dirs = []
@ -127,6 +148,7 @@ class Local(object):
def _init_directories(self):
self.mkdir(self.conf_path)
self.mkdir(self.global_explorer_out_path)
self.mkdir(self.object_path)
self.mkdir(self.bin_path)
def create_files_dirs(self):
@ -134,6 +156,13 @@ class Local(object):
self._create_conf_path_and_link_conf_dirs()
self._create_messages()
self._link_types_for_emulator()
self._setup_object_marker_file()
def _setup_object_marker_file(self):
with open(self.object_marker_file, 'w') as fd:
fd.write("%s\n" % self.object_marker_name)
self.log.debug("Object marker %s saved in %s" % (self.object_marker_name, self.object_marker_file))
def _init_cache_dir(self, cache_dir):
@ -168,6 +197,9 @@ class Local(object):
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
# Export for emulator
env['__cdist_object_marker'] = self.object_marker_name
if message_prefix:
message = cdist.message.Message(message_prefix, self.messages_path)
env.update(message.env)
@ -180,7 +212,7 @@ class Local(object):
except subprocess.CalledProcessError:
raise cdist.Error("Command failed: " + " ".join(command))
except OSError as error:
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
raise cdist.Error(" ".join(command) + ": " + error.args[1])
finally:
if message_prefix:
message.merge_messages()
@ -195,13 +227,9 @@ class Local(object):
return self.run(command=command, env=env, return_output=return_output, message_prefix=message_prefix)
def save_cache(self):
if os.path.isabs(self.target_host):
hostdir = self.target_host[1:]
else:
hostdir = self.target_host
destination = os.path.join(self.cache_path, hostdir)
def save_cache(self):
destination = os.path.join(self.cache_path, self.hostdir)
self.log.debug("Saving " + self.base_path + " to " + destination)
try: