예제 #1
0
def main(args):

    parser = generate_parser()
    (options, args) = parser.parse_args()

    output_dir = os.path.abspath(options.output_dir)
    template_file_full_path = os.path.abspath(options.template_file)
    template_file = os.path.basename(template_file_full_path)
    template_dir = os.path.dirname(os.path.abspath(template_file_full_path))

    if options.docs:
        with open(options.docs) as f:
            docs = yaml.safe_load(f)
    else:
        docs = {}

    config_options = docs
    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
예제 #2
0
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", "")

        update_file_if_different(fname, to_bytes(text))
    else:
        print(text)
예제 #3
0
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)
예제 #4
0
            cli_class_name = "%sCLI" % cli_name.capitalize()
            output[cli_name] = 'ansible-%s.1.rst.in' % cli_name
            cli_bin_name = 'ansible-%s' % cli_name

        # FIXME:
        allvars[cli_name] = opts_docs(cli_class_name, cli_name)
        cli_bin_name_list.append(cli_bin_name)

    cli_list = allvars.keys()

    doc_name_formats = {'man': '%s.1.rst.in',
                        'rst': '%s.rst'}

    for cli_name in cli_list:

        # 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))
예제 #5
0
            if alias and alias in docs:
                oblist[name][alias] = docs[alias]
                del oblist[name][a]
            else:
                oblist[name][a] = ' UNDOCUMENTED!! '

    # loop is really with_ for users
    if name == 'Task':
        oblist[name]['with_<lookup_plugin>'] = 'The same as ``loop`` but magically adds the output of any lookup plugin to generate the item list.'

    # local_action is implicit with action
    if 'action' in oblist[name]:
        oblist[name]['local_action'] = 'Same as action but also implies ``delegate_to: localhost``'

    # remove unusable (used to be private?)
    for nouse in ('loop_args', 'loop_with'):
        if nouse in oblist[name]:
            del oblist[name][nouse]

env = Environment(loader=FileSystemLoader(options.template_dir), trim_blocks=True,)
template = env.get_template(template_file)
outputname = options.output_dir + template_file.replace('.j2', '')
tempvars = {'oblist': oblist, 'clist': clist}

keyword_page = template.render(tempvars)
if LooseVersion(jinja2.__version__) < LooseVersion('2.10'):
    # jinja2 < 2.10's indent filter indents blank lines.  Cleanup
    keyword_page = re.sub(' +\n', '\n', keyword_page)

update_file_if_different(outputname, to_bytes(keyword_page))