Merge pull request #446 from darko-poljak/feature_files_export

Feature files export
This commit is contained in:
Darko Poljak 2016-06-22 12:56:35 +02:00 committed by GitHub
commit 24932fe891
11 changed files with 37 additions and 3 deletions

View file

@ -50,6 +50,7 @@ gencode-local
__object_id: the objects id __object_id: the objects id
__object_fq: full qualified object id, iow: $type.name + / + object_id __object_fq: full qualified object id, iow: $type.name + / + object_id
__type: full qualified path to the type's dir __type: full qualified path to the type's dir
__files: full qualified path to the files dir
returns: string containing the generated code or None returns: string containing the generated code or None
@ -63,6 +64,7 @@ gencode-remote
__object_id: the objects id __object_id: the objects id
__object_fq: full qualified object id, iow: $type.name + / + object_id __object_fq: full qualified object id, iow: $type.name + / + object_id
__type: full qualified path to the type's dir __type: full qualified path to the type's dir
__files: full qualified path to the files dir
returns: string containing the generated code or None returns: string containing the generated code or None
@ -91,6 +93,7 @@ class Code(object):
self.env = { self.env = {
'__target_host': self.target_host, '__target_host': self.target_host,
'__global': self.local.base_path, '__global': self.local.base_path,
'__files': self.local.files_path,
} }
def _run_gencode(self, cdist_object, which): def _run_gencode(self, cdist_object, which):

View file

@ -36,6 +36,7 @@ common:
__cdist_manifest: full qualified path of the manifest == script __cdist_manifest: full qualified path of the manifest == script
__cdist_type_base_path: full qualified path to the directory where types are defined for use in type emulator __cdist_type_base_path: full qualified path to the directory where types are defined for use in type emulator
== local.type_path == local.type_path
__files: full qualified path to the files dir
initial manifest is: initial manifest is:
script: full qualified path to the initial manifest script: full qualified path to the initial manifest
@ -96,6 +97,7 @@ class Manifest(object):
'__cdist_type_base_path': self.local.type_path, # for use in type emulator '__cdist_type_base_path': self.local.type_path, # for use in type emulator
'__global': self.local.base_path, '__global': self.local.base_path,
'__target_host': self.target_host, '__target_host': self.target_host,
'__files': self.local.files_path,
} }
if self.log.getEffectiveLevel() == logging.DEBUG: if self.log.getEffectiveLevel() == logging.DEBUG:
self.env.update({'__cdist_debug': "yes" }) self.env.update({'__cdist_debug': "yes" })

View file

@ -35,6 +35,8 @@ import cdist.message
from cdist import core from cdist import core
import cdist.exec.util as exec_util import cdist.exec.util as exec_util
CONF_SUBDIRS_LINKED = [ "explorer", "files", "manifest", "type" ]
class Local(object): class Local(object):
"""Execute commands locally. """Execute commands locally.
@ -110,6 +112,7 @@ class Local(object):
self.global_explorer_out_path = os.path.join(self.base_path, "explorer") self.global_explorer_out_path = os.path.join(self.base_path, "explorer")
self.object_path = os.path.join(self.base_path, "object") self.object_path = os.path.join(self.base_path, "object")
self.messages_path = os.path.join(self.base_path, "messages") self.messages_path = os.path.join(self.base_path, "messages")
self.files_path = os.path.join(self.conf_path, "files")
# Depending on conf_path # Depending on conf_path
self.global_explorer_path = os.path.join(self.conf_path, "explorer") self.global_explorer_path = os.path.join(self.conf_path, "explorer")
@ -247,14 +250,14 @@ class Local(object):
pass pass
def _create_conf_path_and_link_conf_dirs(self): def _create_conf_path_and_link_conf_dirs(self):
# Link destination directories # Create destination directories
for sub_dir in [ "explorer", "manifest", "type" ]: for sub_dir in CONF_SUBDIRS_LINKED:
self.mkdir(os.path.join(self.conf_path, sub_dir)) self.mkdir(os.path.join(self.conf_path, sub_dir))
# Iterate over all directories and link the to the output dir # Iterate over all directories and link the to the output dir
for conf_dir in self.conf_dirs: for conf_dir in self.conf_dirs:
self.log.debug("Checking conf_dir %s ..." % (conf_dir)) self.log.debug("Checking conf_dir %s ..." % (conf_dir))
for sub_dir in [ "explorer", "manifest", "type" ]: for sub_dir in CONF_SUBDIRS_LINKED:
current_dir = os.path.join(conf_dir, sub_dir) current_dir = os.path.join(conf_dir, sub_dir)
# Allow conf dirs to contain only partial content # Allow conf dirs to contain only partial content

View file

@ -60,6 +60,7 @@ class Shell(object):
'__target_host': self.target_host, '__target_host': self.target_host,
'__manifest': self.local.manifest_path, '__manifest': self.local.manifest_path,
'__explorer': self.local.global_explorer_path, '__explorer': self.local.global_explorer_path,
'__files': self.local.files_path,
} }
self.env.update(additional_env) self.env.update(additional_env)

View file

@ -82,6 +82,7 @@ class CodeTestCase(test.CdistTestCase):
self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path) self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id) self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id)
self.assertEqual(output_dict['__object_name'], self.cdist_object.name) self.assertEqual(output_dict['__object_name'], self.cdist_object.name)
self.assertEqual(output_dict['__files'], self.local.files_path)
def test_run_gencode_remote_environment(self): def test_run_gencode_remote_environment(self):
output_string = self.code.run_gencode_remote(self.cdist_object) output_string = self.code.run_gencode_remote(self.cdist_object)
@ -97,6 +98,7 @@ class CodeTestCase(test.CdistTestCase):
self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path) self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id) self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id)
self.assertEqual(output_dict['__object_name'], self.cdist_object.name) self.assertEqual(output_dict['__object_name'], self.cdist_object.name)
self.assertEqual(output_dict['__files'], self.local.files_path)
def test_transfer_code_remote(self): def test_transfer_code_remote(self):
self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object) self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object)
@ -112,3 +114,7 @@ class CodeTestCase(test.CdistTestCase):
self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object) self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object)
self.code.transfer_code_remote(self.cdist_object) self.code.transfer_code_remote(self.cdist_object)
self.code.run_code_remote(self.cdist_object) self.code.run_code_remote(self.cdist_object)
if __name__ == '__main__':
import unittest
unittest.main()

View file

@ -6,3 +6,4 @@ echo "echo __type: $__type"
echo "echo __object: $__object" echo "echo __object: $__object"
echo "echo __object_id: $__object_id" echo "echo __object_id: $__object_id"
echo "echo __object_name: $__object_name" echo "echo __object_name: $__object_name"
echo "echo __files: $__files"

View file

@ -81,6 +81,7 @@ class ManifestTestCase(test.CdistTestCase):
self.assertEqual(output_dict['__global'], self.local.base_path) self.assertEqual(output_dict['__global'], self.local.base_path)
self.assertEqual(output_dict['__cdist_type_base_path'], self.local.type_path) self.assertEqual(output_dict['__cdist_type_base_path'], self.local.type_path)
self.assertEqual(output_dict['__manifest'], self.local.manifest_path) self.assertEqual(output_dict['__manifest'], self.local.manifest_path)
self.assertEqual(output_dict['__files'], self.local.files_path)
def test_type_manifest_environment(self): def test_type_manifest_environment(self):
cdist_type = core.CdistType(self.local.type_path, '__dump_environment') cdist_type = core.CdistType(self.local.type_path, '__dump_environment')
@ -105,6 +106,7 @@ class ManifestTestCase(test.CdistTestCase):
self.assertEqual(output_dict['__object'], cdist_object.absolute_path) self.assertEqual(output_dict['__object'], cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'], cdist_object.object_id) self.assertEqual(output_dict['__object_id'], cdist_object.object_id)
self.assertEqual(output_dict['__object_name'], cdist_object.name) self.assertEqual(output_dict['__object_name'], cdist_object.name)
self.assertEqual(output_dict['__files'], self.local.files_path)
def test_debug_env_setup(self): def test_debug_env_setup(self):
current_level = self.log.getEffectiveLevel() current_level = self.log.getEffectiveLevel()
@ -112,3 +114,8 @@ class ManifestTestCase(test.CdistTestCase):
manifest = cdist.core.manifest.Manifest(self.target_host, self.local) manifest = cdist.core.manifest.Manifest(self.target_host, self.local)
self.assertTrue("__cdist_debug" in manifest.env) self.assertTrue("__cdist_debug" in manifest.env)
self.log.setLevel(current_level) self.log.setLevel(current_level)
if __name__ == '__main__':
import unittest
unittest.main()

View file

@ -6,4 +6,5 @@ __target_host: $__target_host
__global: $__global __global: $__global
__cdist_type_base_path: $__cdist_type_base_path __cdist_type_base_path: $__cdist_type_base_path
__manifest: $__manifest __manifest: $__manifest
__files: $__files
DONE DONE

View file

@ -10,4 +10,5 @@ __self: $__self
__object: $__object __object: $__object
__object_id: $__object_id __object_id: $__object_id
__object_name: $__object_name __object_name: $__object_name
__files: $__files
DONE DONE

View file

@ -2,6 +2,7 @@ Changelog
--------- ---------
next: next:
* Core: Add files directory for static files (Darko Poljak)
* Core: Fix conflicting requirements (Darko Poljak) * Core: Fix conflicting requirements (Darko Poljak)
* Custom: Add bash and zsh completions (Darko Poljak) * Custom: Add bash and zsh completions (Darko Poljak)
* Core: Improve error reporting for local and remote run command (Darko Poljak) * Core: Improve error reporting for local and remote run command (Darko Poljak)

View file

@ -73,6 +73,10 @@ confdir
By default it consists of everything in \$HOME/.cdist and cdist/conf/. By default it consists of everything in \$HOME/.cdist and cdist/conf/.
For more details see cdist(1) For more details see cdist(1)
confdir/files/
Cdist does not care about this directory besides providing access to it.
It is thought to be a general file storage area.
confdir/manifest/init confdir/manifest/init
This is the central entry point. This is the central entry point.
It is an executable (+x bit set) shell script that can use It is an executable (+x bit set) shell script that can use
@ -195,6 +199,10 @@ The following environment variables are exported by cdist:
__explorer __explorer
Directory that contains all global explorers. Directory that contains all global explorers.
Available for: initial manifest, explorer, type explorer, shell Available for: initial manifest, explorer, type explorer, shell
__files
Directory that contains content from the "files" subdirectories
from the configuration directories.
Available for: initial manifest, type manifest, type gencode, shell
__manifest __manifest
Directory that contains the initial manifest. Directory that contains the initial manifest.
Available for: initial manifest, type manifest, shell Available for: initial manifest, type manifest, shell