Example #1
0
    def test_locate_template_01(self):
        """Locates a template with an invalid path. """
        custom_template_location = "/home/python/test/custom_template"
        t = Templatizer(template_type=custom_template_location)
        template_location = t.locate_template()

        self.assertIsNone(template_location)
Example #2
0
    def test_locate_template_00(self):
        """Locates an existing template."""
        custom_template_location = "/home/python/test/custom_template"
        t = Templatizer(template_type=custom_template_location)
        template_location = t.locate_template()

        self.assertEqual(custom_template_location, template_location)
Example #3
0
    def test_list_templates_00(self):
        """Lists the available templates on the system."""
        custom_template_list = ["project1", "custom-template", "project2"]

        with patch('os.listdir', MagicMock(return_value=custom_template_list)):
            t = Templatizer(template_path_list=["path1"])
            available_templates = t.list_templates()

        self.assertEqual(sorted(custom_template_list), available_templates)
Example #4
0
    def test_copy(self):
        """Copies the template folder hierarchy without any jinja processing."""
        formula_name = "UnitTest"
        template_type = "salt-formula"
        with tempfile.TemporaryDirectory() as tmp_dir:
            output_dir = tmp_dir
            t = Templatizer(template_type=template_type)
            t.copy(formula_name, output_dir)

        self.assertTrue(True)
Example #5
0
def main():
    # Create the parser.
    args = docopt(__doc__, version='Saliere 0.2.0')

    # Create the templatizer object.
    t = Templatizer(template_path_list)

    # List the templates if asked to.
    if args.get('--list'):
        print("Available templates: \n\t" + "\n\t".join(t.list_templates()))
        exit(0)

    # Retrieve the template path.
    template_path = t.locate_template(args.get('<type>'))
    if not template_path:
        print("The template name you specified ('{}') does not exist.".format(args.get('<type>')))
        exit(1)

    # Get the project type.
    t.template_type = args.get('<type>')

    # Load the template variables, if any, from the configuration file.
    config = Config()
    if args.get('-c'):
        config.load_from_file(args.get('-c'))
    template_vars = config.get_value(args.get('<type>'))

    # Load the template variables, if any, from the command line.
    if args.get('--var'):
        # Load the variables and override the values from the config file with the values from the CLI.
        template_vars.update(load_variables(args.get('--var')))

    # Call the copy function.
    t.copy(args.get('<name>'), os.path.expanduser(args.get('--output')), template_vars)
Example #6
0
def main():
    # Create the parser.
    args = docopt(__doc__, version='Saliere 0.2.0')

    # Create the templatizer object.
    t = Templatizer(template_path_list)

    # List the templates if asked to.
    if args.get('--list'):
        print("Available templates: \n\t" + "\n\t".join(t.list_templates()))
        exit(0)

    # Ensure the project name and project type are specified.
    if not args.get('--name') or not args.get('--type'):
        print("The template type and project name are required: -t type -n name.")
        exit(1)

    # Retrieve the template path.
    template_path = t.locate_template(args.get('--type'))
    if not template_path:
        print("The template name you specified does not exist.")
        exit(1)

    # Get the project type.
    t.template_type = args.get('--type')

    # Load the template variables, if any, from the configuration file.
    config = Config()
    if args.get('-c'):
        config.load_from_file(args.get('-c'))
    template_vars = config.get_value(args.get('--type'))

    # Load the template variables, if any, from the command line.
    if args.get('--var'):
        vars_split = args.get('--var').split('|')
        vars_list = [v.split('=', 1) for v in vars_split if '=' in v]
        cli_template_vars = dict(vars_list)

        # And override the values from the config file with the values from the CLI.
        template_vars.update(cli_template_vars)

    # Call the copy function.
    t.copy(args.get('--name'), args.get('--output'), template_vars)