integrate messaging into gencode, manifest

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-11-26 01:17:37 +01:00
commit 2f842d56eb
3 changed files with 19 additions and 11 deletions

View file

@ -30,6 +30,7 @@ import logging
import tempfile
import cdist
import cdist.message
from cdist import core
class Local(object):
@ -44,11 +45,9 @@ class Local(object):
exec_path=sys.argv[0],
initial_manifest=None,
base_path=None,
add_conf_dirs=None,
message_prefix=None):
add_conf_dirs=None):
self.target_host = target_host
self.message_prefix=message_prefix
# FIXME: stopped: create base that does not require moving later
if base_path:
@ -131,6 +130,7 @@ class Local(object):
def create_files_dirs(self):
self._init_directories()
self._create_conf_path_and_link_conf_dirs()
self._create_messages()
self._link_types_for_emulator()
@ -153,7 +153,7 @@ class Local(object):
self.log.debug("Local mkdir: %s", path)
os.makedirs(path, exist_ok=True)
def run(self, command, env=None, return_output=False):
def run(self, command, env=None, return_output=False, message_prefix=None):
"""Run the given command with the given environment.
Return the output as a string.
@ -166,8 +166,8 @@ class Local(object):
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
if self.message_prefix:
message = cdist.Message(self.message_prefix, self.messages_path)
if message_prefix:
message = cdist.message.Message(message_prefix, self.messages_path)
try:
if return_output:
@ -179,10 +179,10 @@ class Local(object):
except OSError as error:
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
finally:
if self.message_prefix:
if message_prefix:
message.merge_messages()
def run_script(self, script, env=None, return_output=False):
def run_script(self, script, env=None, return_output=False, message_prefix=None):
"""Run the given script with the given environment.
Return the output as a string.
@ -190,7 +190,7 @@ class Local(object):
command = ["/bin/sh", "-e"]
command.append(script)
return self.run(command, env, return_output)
return self.run(command=command, env=env, return_output=return_output, message_prefix=message_prefix)
def save_cache(self):
destination = os.path.join(self.cache_path, self.target_host)
@ -199,6 +199,11 @@ class Local(object):
shutil.rmtree(destination)
shutil.move(self.base_path, destination)
def _create_messages(self):
"""Create empty messages"""
with open(self.messages_path, "w"):
pass
def _create_conf_path_and_link_conf_dirs(self):
# Link destination directories
for sub_dir in [ "explorer", "manifest", "type" ]: