예제 #1
0
파일: test_jingen.py 프로젝트: nir0s/jingen
 def test_generate_data_no_file(self):
     i = Jingen(
         template_file=MOCK_TEMPLATE_FILE,
         vars_source=MOCK_VARS_FILE,
         output_file=TEST_OUTPUT_FILE,
         template_dir=TEST_RESOURCES_DIR,
         make_file=False)
     output = i.generate()
     self.assertIn('vars_file_test_value', output)
     self.assertFalse(os.path.isfile(TEST_OUTPUT_FILE))
예제 #2
0
파일: test_jingen.py 프로젝트: nir0s/jingen
 def test_file_creation_from_vars_file(self):
     i = Jingen(
         template_file=MOCK_TEMPLATE_FILE,
         vars_source=MOCK_VARS_FILE,
         output_file=TEST_OUTPUT_FILE,
         template_dir=TEST_RESOURCES_DIR,
         make_file=True)
     i.generate()
     with open(TEST_OUTPUT_FILE, 'r') as f:
         self.assertIn('vars_file_test_value', f.read())
     os.remove(TEST_OUTPUT_FILE)
예제 #3
0
파일: jocker.py 프로젝트: nir0s/jocker
    def generate(self):

        jocker_lgr.debug("template file: {0}".format(self.template_file))
        jocker_lgr.debug("vars source: {0}".format(self.varsfile))
        jocker_lgr.debug("template dir: {0}".format(self.template_dir))

        if not self.is_dryrun:
            jocker_lgr.info("generating Dockerfile: {0}".format(os.path.abspath(self.outputfile)))
        i = Jingen(
            template_file=self.template_file,
            vars_source=self.varsfile,
            output_file=self.outputfile,
            template_dir=self.template_dir,
            make_file=not self.is_dryrun,
        )
        formatted_text = i.generate()
        if not self.is_dryrun:
            jocker_lgr.info("Dockerfile generated")
        jocker_lgr.debug("Output content: \n{0}".format(formatted_text))
        return formatted_text
예제 #4
0
def _generate_includes_file(modules, venv):
    """generates the included_plugins file for `cloudify-agent` to use
    :param dict modules: dict containing a list of modules and a list
     of plugins. The plugins list will be used to populate the file.
    :param string venv: path of virtualenv to install in.
    """
    lgr.debug('Generating includes file')

    process = utils.run('{0}/bin/python -c "import cloudify_agent;'
                        ' print cloudify_agent.__file__"'.format(venv))
    cloudify_agent_module_path = os.path.dirname(process.stdout)
    included_plugins_py = os.path.join(
        cloudify_agent_module_path, INCLUDES_FILE)
    included_plugins_pyc = '{0}c'.format(included_plugins_py)

    try:
        previous_included = imp.load_source('included_plugins',
                                            included_plugins_py)
        plugins_list = previous_included.included_plugins
        for plugin in plugins_list:
            if plugin not in modules['plugins']:
                modules['plugins'].append(plugin)
    except IOError:
        lgr.debug('Included Plugins file could not be found in agent '
                  'module. A new file will be generated.')

    lgr.debug('Writing includes file to: {0}'.format(included_plugins_py))
    i = Jingen(
        template_file=TEMPLATE_FILE,
        vars_source=modules,
        output_file=included_plugins_py,
        template_dir=os.path.join(os.path.dirname(__file__), TEMPLATE_DIR),
        make_file=True
    )
    i.generate()

    if os.path.isfile(included_plugins_pyc):
        os.remove(included_plugins_pyc)
    return included_plugins_py