Save output streams.

Implementation is 99% based on Steven's initial implementation.
This commit is contained in:
Darko Poljak 2018-01-09 09:31:40 +01:00
commit 9703e0f08e
21 changed files with 484 additions and 121 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2017 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
#
@ -80,6 +80,8 @@ class CdistObject(object):
self.code_local_path = os.path.join(self.path, "code-local")
self.code_remote_path = os.path.join(self.path, "code-remote")
self.parameter_path = os.path.join(self.path, "parameter")
self.stdout_path = os.path.join(self.absolute_path, "stdout")
self.stderr_path = os.path.join(self.absolute_path, "stderr")
@classmethod
def list_objects(cls, object_base_path, type_base_path, object_marker):
@ -246,10 +248,11 @@ class CdistObject(object):
"""Create this cdist object on the filesystem.
"""
try:
os.makedirs(self.absolute_path, exist_ok=allow_overwrite)
absolute_parameter_path = os.path.join(self.base_path,
self.parameter_path)
os.makedirs(absolute_parameter_path, exist_ok=allow_overwrite)
for path in (self.absolute_path,
os.path.join(self.base_path, self.parameter_path),
self.stdout_path,
self.stderr_path):
os.makedirs(path, exist_ok=allow_overwrite)
except EnvironmentError as error:
raise cdist.Error(('Error creating directories for cdist object: '
'%s: %s') % (self, error))

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2017 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
#
@ -127,8 +127,13 @@ class Code(object):
'__object_name': cdist_object.name,
})
message_prefix = cdist_object.name
return self.local.run_script(script, env=env, return_output=True,
message_prefix=message_prefix)
stderr_path = os.path.join(cdist_object.stderr_path,
'gencode-' + which)
with open(stderr_path, 'ba+') as stderr:
return self.local.run_script(script, env=env,
return_output=True,
message_prefix=message_prefix,
stderr=stderr)
def run_gencode_local(self, cdist_object):
"""Run the gencode-local script for the given cdist object."""
@ -152,7 +157,12 @@ class Code(object):
which_exec = getattr(self, which)
script = os.path.join(which_exec.object_path,
getattr(cdist_object, 'code_%s_path' % which))
return which_exec.run_script(script, env=env)
stderr_path = os.path.join(cdist_object.stderr_path, 'code-' + which)
stdout_path = os.path.join(cdist_object.stdout_path, 'code-' + which)
with open(stderr_path, 'ba+') as stderr, \
open(stdout_path, 'ba+') as stdout:
return which_exec.run_script(script, env=env, stdout=stdout,
stderr=stderr)
def run_code_local(self, cdist_object):
"""Run the code-local script for the given cdist object."""

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
@ -153,10 +153,16 @@ class Manifest(object):
message_prefix = "initialmanifest"
self.log.verbose("Running initial manifest " + initial_manifest)
self.local.run_script(initial_manifest,
env=self.env_initial_manifest(initial_manifest),
message_prefix=message_prefix,
save_output=False)
which = "init"
stderr_path = os.path.join(self.local.stderr_base_path, which)
stdout_path = os.path.join(self.local.stdout_base_path, which)
with open(stderr_path, 'ba+') as stderr, \
open(stdout_path, 'ba+') as stdout:
self.local.run_script(
initial_manifest,
env=self.env_initial_manifest(initial_manifest),
message_prefix=message_prefix,
stdout=stdout, stderr=stderr)
def env_type_manifest(self, cdist_object):
type_manifest = os.path.join(self.local.type_path,
@ -178,10 +184,16 @@ class Manifest(object):
type_manifest = os.path.join(self.local.type_path,
cdist_object.cdist_type.manifest_path)
message_prefix = cdist_object.name
which = 'manifest'
if os.path.isfile(type_manifest):
self.log.verbose("Running type manifest %s for object %s",
type_manifest, cdist_object.name)
self.local.run_script(type_manifest,
env=self.env_type_manifest(cdist_object),
message_prefix=message_prefix,
save_output=False)
stderr_path = os.path.join(cdist_object.stderr_path, which)
stdout_path = os.path.join(cdist_object.stdout_path, which)
with open(stderr_path, 'ba+') as stderr, \
open(stdout_path, 'ba+') as stdout:
self.local.run_script(
type_manifest,
env=self.env_type_manifest(cdist_object),
message_prefix=message_prefix,
stdout=stdout, stderr=stderr)