Beispiel #1
0
def handle_command_line(options):
    """
    act upon command options
    """
    options = merge(options, constants.DEFAULT_OPTIONS)
    engine = plugins.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:
        if options[constants.POSITIONAL_LABEL_TEMPLATE] is None:
            raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)
        else:
            engine.render_string_to_file(
                options[constants.POSITIONAL_LABEL_TEMPLATE],
                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()
    HASH_STORE.save_hashes()
    exit_code = reporter.convert_to_shell_exit_code(
        engine.number_of_templated_files())
    return exit_code
Beispiel #2
0
def handle_moban_file(moban_file, options):
    """
    act upon default moban file
    """
    moban_file_configurations = open_yaml(None, moban_file)
    if moban_file_configurations is None:
        raise exceptions.MobanfileGrammarException(
            constants.ERROR_INVALID_MOBAN_FILE % moban_file
        )
    if (
        constants.LABEL_TARGETS not in moban_file_configurations
        and constants.LABEL_COPY not in moban_file_configurations
    ):
        raise exceptions.MobanfileGrammarException(
            constants.ERROR_NO_TARGETS % moban_file
        )
    version = moban_file_configurations.get(
        constants.MOBAN_VERSION, constants.DEFAULT_MOBAN_VERSION
    )
    if version == constants.DEFAULT_MOBAN_VERSION:
        mobanfile.handle_moban_file_v1(moban_file_configurations, options)
    else:
        raise exceptions.MobanfileGrammarException(
            constants.MESSAGE_FILE_VERSION_NOT_SUPPORTED % version
        )
    HASH_STORE.save_hashes()
Beispiel #3
0
 def _apply_template(self, template, data, output):
     rendered_content = template.render(**data)
     rendered_content = utils.strip_off_trailing_new_lines(rendered_content)
     rendered_content = rendered_content.encode("utf-8")
     flag = HASH_STORE.is_file_changed(output, rendered_content,
                                       template.filename)
     if flag:
         utils.write_file_out(output,
                              rendered_content,
                              strip=False,
                              encode=False)
         utils.file_permissions_copy(template.filename, output)
     return flag
Beispiel #4
0
 def apply_template(self, template_abs_path, template, data, output_file):
     rendered_content = self.engine.apply_template(template, data,
                                                   output_file)
     rendered_content = utils.strip_off_trailing_new_lines(rendered_content)
     rendered_content = rendered_content.encode("utf-8")
     flag = HASH_STORE.is_file_changed(output_file, rendered_content,
                                       template_abs_path)
     if flag:
         utils.write_file_out(output_file,
                              rendered_content,
                              strip=False,
                              encode=False)
         utils.file_permissions_copy(template_abs_path, output_file)
     return flag
Beispiel #5
0
    def apply_template(self, template_abs_path, template, data, output_file):
        rendered_content = self.engine.apply_template(template, data,
                                                      output_file)
        if PY3_ABOVE:
            if not isinstance(rendered_content, bytes):
                rendered_content = rendered_content.encode("utf-8")

        try:
            flag = HASH_STORE.is_file_changed(output_file, rendered_content,
                                              template_abs_path)
            if flag:
                utils.write_file_out(output_file, rendered_content)
                utils.file_permissions_copy(template_abs_path, output_file)
            return flag
        except exceptions.FileNotFound:
            utils.write_file_out(output_file, rendered_content)
            return True
Beispiel #6
0
 def copy_files(self, file_list):
     for dest, src in _iterate_list_of_dicts(file_list):
         src_path = self._get_src_file(src)
         if src_path is None:
             if src.endswith("**"):
                 source_dir = src[:-3]
                 src_path = self._get_src_file(source_dir)
                 if src_path:
                     self._copy_dir_recursively(src[:-3], src_path, dest)
                 else:
                     reporter.report_error_message(
                         "{0} cannot be found".format(source_dir))
             else:
                 reporter.report_error_message(
                     "{0} cannot be found".format(src))
         elif os.path.isdir(src_path):
             self._copy_dir(src, src_path, dest)
         elif HASH_STORE.are_two_file_different(src_path, dest):
             self._increment_file_count()
             self._copy(src_path, dest)