forked from ungleich-public/cdist
		
	integrate messaging into gencode, manifest
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								edec2abb1d
							
						
					
				
			
			
				commit
				
					
						2f842d56eb
					
				
			
		
					 3 changed files with 19 additions and 11 deletions
				
			
		| 
						 | 
					@ -104,7 +104,8 @@ class Code(object):
 | 
				
			||||||
                '__object_id': cdist_object.object_id,
 | 
					                '__object_id': cdist_object.object_id,
 | 
				
			||||||
                '__object_name': cdist_object.name,
 | 
					                '__object_name': cdist_object.name,
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            return self.local.run_script(script, env=env, return_output=True)
 | 
					            message_prefix=cdist_object.name
 | 
				
			||||||
 | 
					            return self.local.run_script(script, env=env, return_output=True, message_prefix=message_prefix)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run_gencode_local(self, cdist_object):
 | 
					    def run_gencode_local(self, cdist_object):
 | 
				
			||||||
        """Run the gencode-local script for the given cdist object."""
 | 
					        """Run the gencode-local script for the given cdist object."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,7 +122,8 @@ class Manifest(object):
 | 
				
			||||||
        if not os.path.isfile(initial_manifest):
 | 
					        if not os.path.isfile(initial_manifest):
 | 
				
			||||||
            raise NoInitialManifestError(initial_manifest, user_supplied)
 | 
					            raise NoInitialManifestError(initial_manifest, user_supplied)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest))
 | 
					        message_prefix="initialmanifest"
 | 
				
			||||||
 | 
					        self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest), message_prefix=message_prefix)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def env_type_manifest(self, cdist_object):
 | 
					    def env_type_manifest(self, cdist_object):
 | 
				
			||||||
        type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
 | 
					        type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
 | 
				
			||||||
| 
						 | 
					@ -141,5 +142,6 @@ class Manifest(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run_type_manifest(self, cdist_object):
 | 
					    def run_type_manifest(self, cdist_object):
 | 
				
			||||||
        type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
 | 
					        type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
 | 
				
			||||||
 | 
					        message_prefix = cdist_object.name
 | 
				
			||||||
        if os.path.isfile(type_manifest):
 | 
					        if os.path.isfile(type_manifest):
 | 
				
			||||||
           self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object))
 | 
					           self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@ import logging
 | 
				
			||||||
import tempfile
 | 
					import tempfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import cdist
 | 
					import cdist
 | 
				
			||||||
 | 
					import cdist.message
 | 
				
			||||||
from cdist import core
 | 
					from cdist import core
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Local(object):
 | 
					class Local(object):
 | 
				
			||||||
| 
						 | 
					@ -44,11 +45,9 @@ class Local(object):
 | 
				
			||||||
                 exec_path=sys.argv[0],
 | 
					                 exec_path=sys.argv[0],
 | 
				
			||||||
                 initial_manifest=None,
 | 
					                 initial_manifest=None,
 | 
				
			||||||
                 base_path=None,
 | 
					                 base_path=None,
 | 
				
			||||||
                 add_conf_dirs=None,
 | 
					                 add_conf_dirs=None):
 | 
				
			||||||
                 message_prefix=None):
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.target_host = target_host
 | 
					        self.target_host = target_host
 | 
				
			||||||
        self.message_prefix=message_prefix
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # FIXME: stopped: create base that does not require moving later
 | 
					        # FIXME: stopped: create base that does not require moving later
 | 
				
			||||||
        if base_path:
 | 
					        if base_path:
 | 
				
			||||||
| 
						 | 
					@ -131,6 +130,7 @@ class Local(object):
 | 
				
			||||||
    def create_files_dirs(self):
 | 
					    def create_files_dirs(self):
 | 
				
			||||||
        self._init_directories()
 | 
					        self._init_directories()
 | 
				
			||||||
        self._create_conf_path_and_link_conf_dirs()
 | 
					        self._create_conf_path_and_link_conf_dirs()
 | 
				
			||||||
 | 
					        self._create_messages()
 | 
				
			||||||
        self._link_types_for_emulator()
 | 
					        self._link_types_for_emulator()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,7 +153,7 @@ class Local(object):
 | 
				
			||||||
        self.log.debug("Local mkdir: %s", path)
 | 
					        self.log.debug("Local mkdir: %s", path)
 | 
				
			||||||
        os.makedirs(path, exist_ok=True)
 | 
					        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.
 | 
					        """Run the given command with the given environment.
 | 
				
			||||||
        Return the output as a string.
 | 
					        Return the output as a string.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,8 +166,8 @@ class Local(object):
 | 
				
			||||||
        # Export __target_host for use in __remote_{copy,exec} scripts
 | 
					        # Export __target_host for use in __remote_{copy,exec} scripts
 | 
				
			||||||
        env['__target_host'] = self.target_host
 | 
					        env['__target_host'] = self.target_host
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.message_prefix:
 | 
					        if message_prefix:
 | 
				
			||||||
            message = cdist.Message(self.message_prefix, self.messages_path)
 | 
					            message = cdist.message.Message(message_prefix, self.messages_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            if return_output:
 | 
					            if return_output:
 | 
				
			||||||
| 
						 | 
					@ -179,10 +179,10 @@ class Local(object):
 | 
				
			||||||
        except OSError as error:
 | 
					        except OSError as error:
 | 
				
			||||||
            raise cdist.Error(" ".join(*args) + ": " + error.args[1])
 | 
					            raise cdist.Error(" ".join(*args) + ": " + error.args[1])
 | 
				
			||||||
        finally:
 | 
					        finally:
 | 
				
			||||||
            if self.message_prefix:
 | 
					            if message_prefix:
 | 
				
			||||||
                message.merge_messages()
 | 
					                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.
 | 
					        """Run the given script with the given environment.
 | 
				
			||||||
        Return the output as a string.
 | 
					        Return the output as a string.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -190,7 +190,7 @@ class Local(object):
 | 
				
			||||||
        command = ["/bin/sh", "-e"]
 | 
					        command = ["/bin/sh", "-e"]
 | 
				
			||||||
        command.append(script)
 | 
					        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):
 | 
					    def save_cache(self):
 | 
				
			||||||
        destination = os.path.join(self.cache_path, self.target_host)
 | 
					        destination = os.path.join(self.cache_path, self.target_host)
 | 
				
			||||||
| 
						 | 
					@ -199,6 +199,11 @@ class Local(object):
 | 
				
			||||||
            shutil.rmtree(destination)
 | 
					            shutil.rmtree(destination)
 | 
				
			||||||
        shutil.move(self.base_path, 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):
 | 
					    def _create_conf_path_and_link_conf_dirs(self):
 | 
				
			||||||
        # Link destination directories
 | 
					        # Link destination directories
 | 
				
			||||||
        for sub_dir in [ "explorer", "manifest", "type" ]:
 | 
					        for sub_dir in [ "explorer", "manifest", "type" ]:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue