def handle_moban_file_v1(moban_file_configurations, command_line_options):
    LOG.info("handling moban file")
    merged_options = None

    targets = moban_file_configurations.get(constants.LABEL_TARGETS, [])
    if constants.LABEL_COPY in moban_file_configurations:
        legacy_copy_targets = handle_copy(
            merged_options, moban_file_configurations[constants.LABEL_COPY])
        targets += legacy_copy_targets

    cli_target = extract_target(command_line_options)
    group_target = command_line_options.get(constants.LABEL_GROUP)
    if group_target:
        # will raise exception when group target not found
        targets = extract_group_targets(group_target, targets)

    if constants.LABEL_CONFIG in moban_file_configurations:
        merged_options = merge(
            command_line_options,
            moban_file_configurations[constants.LABEL_CONFIG],
        )
    merged_options = merge(command_line_options, constants.DEFAULT_OPTIONS)
    plugins_dirs = merged_options.get(constants.LABEL_PLUGIN_DIRS)
    if plugins_dirs:
        handle_plugin_dirs(plugins_dirs)

    # deprecated
    requires = moban_file_configurations.get(constants.LABEL_REQUIRES)
    if requires:
        handle_requires(requires)

    # call expand template directory always after handle require please
    # the penalty is: newly clone repos are not visible
    # one more note: verify_the_existence_of_directories will remove non-exist dirs
    merged_options[
        constants.LABEL_TMPL_DIRS] = verify_the_existence_of_directories(
            list(
                expand_template_directories(
                    merged_options[constants.LABEL_TMPL_DIRS])))
    extensions = moban_file_configurations.get(constants.LABEL_EXTENSIONS)
    if extensions:
        core.ENGINES.register_extensions(extensions)

    template_types = merged_options.get(constants.LABEL_TEMPLATE_TYPES)
    if template_types:
        core.ENGINES.register_options(template_types)

    if cli_target:
        number_of_templated_files = handle_targets(merged_options,
                                                   [cli_target])
    elif targets:
        number_of_templated_files = handle_targets(merged_options, targets)
    else:
        number_of_templated_files = 0

    exit_code = reporter.convert_to_shell_exit_code(number_of_templated_files)
    reporter.report_up_to_date()
    return exit_code
def handle_command_line(options):
    """
    act upon command options
    """
    options = data_loader.merge(options, constants.DEFAULT_OPTIONS)
    engine = ENGINES.get_engine(
        options[constants.LABEL_TEMPLATE_TYPE],
        options[constants.LABEL_TMPL_DIRS],
        options[constants.LABEL_CONFIG_DIR],
    )
    if options[constants.LABEL_TEMPLATE] is None:
        content = options[constants.POSITIONAL_LABEL_TEMPLATE]
        if content is None:
            if not sys.stdin.isatty() and sys.platform != "win32":
                content = sys.stdin.read().strip()
        if content is None:
            raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)

        engine.render_string_to_file(
            content,
            options[constants.LABEL_CONFIG],
            options[constants.LABEL_OUTPUT],
        )
    else:
        engine.render_to_file(
            options[constants.LABEL_TEMPLATE],
            options[constants.LABEL_CONFIG],
            options[constants.LABEL_OUTPUT],
        )
    engine.report()
    hashstore.HASH_STORE.save_hashes()
    exit_code = reporter.convert_to_shell_exit_code(
        engine.number_of_templated_files())
    return exit_code
Ejemplo n.º 3
0
def test_merge_value_as_list_in_yaml():
    yaml = YAML(typ="rt")
    user = yaml.load("""
L1:
  - a
  - b
""")
    default = yaml.load("""
L1:
  - c
  - d
""")
    merged = merge(user, default)
    eq_(merged, {"L1": ["a", "b", "c", "d"]})
Ejemplo n.º 4
0
 def get_data(self, file_name):
     custom_data = copy.deepcopy(OPTIONS[constants.CLI_DICT])
     try:
         data = load_data(self.context_dirs, file_name)
         merge(custom_data, data)
         merge(custom_data, self.__cached_environ_variables)
         return custom_data
     except (IOError, exceptions.IncorrectDataInput) as exception:
         # If data file doesn't exist:
         # 1. Alert the user of their (potential) mistake
         # 2. Attempt to use environment vars as data
         LOG.warn(str(exception))
         LOG.info(MESSAGE_USING_ENV_VARS)
         merge(custom_data, self.__cached_environ_variables)
         return custom_data
Ejemplo n.º 5
0
def test_simple_union():
    user = {"hi": "world"}
    default = {"world": "hi"}
    merged = merge(user, default)
    assert merged == {"hi": "world", "world": "hi"}
Ejemplo n.º 6
0
def test_merge_value_as_list():
    user = {"L1": ["a", "b"]}
    default = {"L1": ["c", "d"]}
    merged = merge(user, default)
    assert merged == {"L1": ["a", "b", "c", "d"]}
Ejemplo n.º 7
0
def test_three_level_conflict():
    user = {"L1": {"L2": {"L3": "World"}}}
    default = {"L1": {"L2": {"L3": "Hi"}}}
    merged = merge(user, default)
    assert merged == {"L1": {"L2": {"L3": "World"}}}
Ejemplo n.º 8
0
def test_two_level_merge():
    user = {"L1": {"L2": "World"}}
    default = {"L1": {"L2.1": "Hi"}}
    merged = merge(user, default)
    assert merged == {"L1": {"L2": "World", "L2.1": "Hi"}}
Ejemplo n.º 9
0
def test_simple_overlapping():
    user = {"hi": "world", "world": "hei"}
    default = {"world": "hi"}
    merged = merge(user, default)
    assert merged == {"hi": "world", "world": "hei"}