Esempio n. 1
0
def handle_targets(merged_options, targets):
    list_of_templating_parameters = parse_targets(merged_options, targets)
    list_of_templating_parameters = expand_directories(
        list_of_templating_parameters,
        merged_options[constants.LABEL_TMPL_DIRS],
    )
    jobs_for_each_engine = defaultdict(list)
    for file_list in list_of_templating_parameters:
        _, extension = os.path.splitext(file_list[0])
        template_type = extension[1:]
        primary_template_type = ENGINES.get_primary_key(template_type)
        if primary_template_type is None:
            primary_template_type = merged_options[
                constants.LABEL_TEMPLATE_TYPE]
        jobs_for_each_engine[primary_template_type].append(file_list)

    count = 0
    for template_type in jobs_for_each_engine.keys():
        engine_class = ENGINES.get_engine(template_type)
        engine = engine_class(
            merged_options[constants.LABEL_TMPL_DIRS],
            merged_options[constants.LABEL_CONFIG_DIR],
        )
        engine.render_to_files(jobs_for_each_engine[template_type])
        engine.report()
        count = count + engine.number_of_templated_files()
    return count
Esempio n. 2
0
def handle_command_line(options):
    """
    act upon command options
    """
    options = merge(options, constants.DEFAULT_OPTIONS)
    if options[constants.LABEL_TEMPLATE] is None:
        raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)
    engine_class = ENGINES.get_engine(options[constants.LABEL_TEMPLATE_TYPE])
    engine = engine_class(options[constants.LABEL_TMPL_DIRS],
                          options[constants.LABEL_CONFIG_DIR])
    engine.render_to_file(
        options[constants.LABEL_TEMPLATE],
        options[constants.LABEL_CONFIG],
        options[constants.LABEL_OUTPUT],
    )
    HASH_STORE.save_hashes()
    exit_code = reporter.convert_to_shell_exit_code(
        engine.number_of_templated_files())
    return exit_code
Esempio n. 3
0
def test_unknown_template_type():
    ENGINES.get_engine("unknown_template_type")
Esempio n. 4
0
def test_default_mako_type():  # fake mako
    engine_class = ENGINES.get_engine("mako")
    assert engine_class.__name__ == "MakoEngine"
Esempio n. 5
0
def test_default_template_type():
    engine_class = ENGINES.get_engine("jj2")
    assert engine_class == Engine