How to use the hacking.build_library.build_ansible.change_detection.update_file_if_different function in hacking

To help you get started, we’ve selected a few hacking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / ansible / hacking / build_library / build_ansible / command_plugins / plugin_formatter.py View on Github external
def write_data(text, output_dir, outputname, module=None):
    ''' dumps module output to a file or the screen, as requested '''

    if output_dir is not None:
        if module:
            outputname = outputname % module

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)
        fname = os.path.join(output_dir, outputname)
        fname = fname.replace(".py", "")

        try:
            updated = update_file_if_different(fname, to_bytes(text))
        except Exception as e:
            display.display("while rendering %s, an error occured: %s" % (module, e))
            raise
        if updated:
            display.display("rendering: %s" % module)
    else:
        print(text)
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / collection_meta.py View on Github external
normalize_options(options)

        env = Environment(loader=FileSystemLoader(template_dir),
                          variable_start_string="@{",
                          variable_end_string="}@",
                          trim_blocks=True)
        env.filters['documented_type'] = documented_type
        env.filters['rst_ify'] = rst_ify

        template = env.get_template(template_file)
        output_name = os.path.join(output_dir, template_file.replace('.j2', ''))
        temp_vars = {'options': options}

        data = to_bytes(template.render(temp_vars))
        update_file_if_different(output_name, data)

        return 0
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / generate_man.py View on Github external
# template it!
            env = Environment(loader=FileSystemLoader(template_dir))
            template = env.get_template(template_basename)

            # add rest to vars
            tvars = allvars[cli_name]
            tvars['cli_list'] = cli_list
            tvars['cli_bin_name_list'] = cli_bin_name_list
            tvars['cli'] = cli_name
            if '-i' in tvars['options']:
                print('uses inventory')

            manpage = template.render(tvars)
            filename = os.path.join(output_dir, doc_name_formats[output_format] % tvars['cli_name'])
            update_file_if_different(filename, to_bytes(manpage))
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / dump_keywords.py View on Github external
def main(args):
        keyword_definitions = load_definitions(args.keyword_defs)
        pb_keywords = extract_keywords(keyword_definitions)

        keyword_page = generate_page(pb_keywords, args.template_dir)
        outputname = os.path.join(args.output_dir, TEMPLATE_FILE.replace('.j2', ''))
        update_file_if_different(outputname, to_bytes(keyword_page))

        return 0
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / dump_config.py View on Github external
template_file_full_path = os.path.abspath(os.path.join(args.template_dir, args.template_file))
        template_file = os.path.basename(template_file_full_path)
        template_dir = os.path.dirname(template_file_full_path)

        with open(args.config_defs) as f:
            config_options = yaml.safe_load(f)

        config_options = fix_description(config_options)

        env = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True,)
        template = env.get_template(template_file)
        output_name = os.path.join(output_dir, template_file.replace('.j2', ''))
        temp_vars = {'config_options': config_options}

        data = to_bytes(template.render(temp_vars))
        update_file_if_different(output_name, data)

        return 0