Esempio n. 1
0
def print_opt_list(data, nested_content):
    definitions = map_nested_definitions(nested_content)
    items = []
    if 'options' in data:
        for opt in data['options']:
            names = []
            my_def = [nodes.paragraph(text=opt['help'])] if opt['help'] else []
            for name in opt['name']:
                option_declaration = [nodes.option_string(text=name)]
                if opt['default'] is not None \
                        and opt['default'] != '==SUPPRESS==':
                    option_declaration += nodes.option_argument(
                        '', text='=' + str(opt['default']))
                names.append(nodes.option('', *option_declaration))
                my_def = apply_definition(definitions, my_def, name)
            if len(my_def) == 0:
                my_def.append(nodes.paragraph(text='Undocumented'))
            if 'choices' in opt:
                my_def.append(nodes.paragraph(
                    text=('Possible choices: %s' % ', '.join([str(c) for c in opt['choices']]))))
            items.append(
                nodes.option_list_item(
                    '', nodes.option_group('', *names),
                    nodes.description('', *my_def)))
    return nodes.option_list('', *items) if items else None
Esempio n. 2
0
 def _format_optional_arguments(self, parser_info):
     assert 'options' in parser_info
     items = []
     for opt in parser_info['options']:
         names = []
         opt_items = []
         for name in opt['name']:
             option_declaration = [nodes.option_string(text=name)]
             if opt['default'] is not None \
                     and opt['default'] not in ['"==SUPPRESS=="', '==SUPPRESS==']:
                 option_declaration += nodes.option_argument(
                     '', text='=' + str(opt['default']))
             names.append(nodes.option('', *option_declaration))
         if opt['help']:
             opt_items.append(nodes.paragraph(text=opt['help']))
         elif 'choices' not in opt:
             opt_items.append(nodes.paragraph(text='Undocumented'))
         if 'choices' in opt:
             opt_items.append(
                 nodes.paragraph(text='Possible choices: ' +
                                 ', '.join(opt['choices'])))
         items.append(
             nodes.option_list_item('', nodes.option_group('', *names),
                                    nodes.description('', *opt_items)))
     return nodes.option_list('', *items)
Esempio n. 3
0
File: ext.py Progetto: EVMosaic/BAM
def print_opt_list(data, nested_content):
    definitions = map_nested_definitions(nested_content)
    items = []
    if 'options' in data:
        for opt in data['options']:
            names = []
            my_def = [nodes.paragraph(text=opt['help'])] if opt['help'] else []
            for name in opt['name']:
                option_declaration = [nodes.option_string(text=name)]
                if opt['default'] is not None \
                        and opt['default'] != '==SUPPRESS==':
                    option_declaration += nodes.option_argument(
                        '', text='=' + str(opt['default']))
                names.append(nodes.option('', *option_declaration))
                my_def = apply_definition(definitions, my_def, name)
            if len(my_def) == 0:
                my_def.append(nodes.paragraph(text='Undocumented'))
            if 'choices' in opt:
                my_def.append(
                    nodes.paragraph(
                        text=('Possible choices: %s' %
                              ', '.join([str(c) for c in opt['choices']]))))
            items.append(
                nodes.option_list_item('', nodes.option_group('', *names),
                                       nodes.description('', *my_def)))
    return nodes.option_list('', *items) if items else None
Esempio n. 4
0
def print_opt_list(data, nested_content):
    definitions = map_nested_definitions(nested_content)
    items = []
    nodes_list = []  # dictionary to hold the group options, the group title is used as the key
    if 'action_groups' in data:
        for action_group in data['action_groups']:
            if 'options' in action_group:
                for opt in action_group['options']:
                    names = []
                    my_def = [nodes.paragraph(text=opt['help'])] if opt['help'] else []
                    for name in opt['name']:
                        option_declaration = [nodes.option_string(text=name)]
                        if opt['default'] is not None \
                                and opt['default'] != '==SUPPRESS==':
                            option_declaration += nodes.option_argument(
                                '', text='=' + str(opt['default']))
                        names.append(nodes.option('', *option_declaration))
                        my_def = apply_definition(definitions, my_def, name)
                    if len(my_def) == 0 and 'choices' not in opt:
                        my_def.append(nodes.paragraph(text='Undocumented'))
                    if 'choices' in opt:
                        my_def.append(nodes.paragraph(
                            text=('Possible choices: %s' % ', '.join([str(c) for c in opt['choices']]))))
                    items.append(
                        nodes.option_list_item(
                            '', nodes.option_group('', *names),
                            nodes.description('', *my_def)))
            opts = nodes.option_list('', *items) if items else None
            nodes_list.append({'options': opts,
                               'title': action_group['title'],
                               'description': action_group['description']})
    return nodes_list
Esempio n. 5
0
 def _format_optional_arguments(self, parser_info):
     assert 'options' in parser_info
     items = []
     for opt in parser_info['options']:
         names = []
         opt_items = []
         for name in opt['name']:
             option_declaration = [nodes.option_string(text=name)]
             if opt['default'] is not None \
                     and opt['default'] != '==SUPPRESS==':
                 option_declaration += nodes.option_argument(
                     '', text='=' + str(opt['default']))
             names.append(nodes.option('', *option_declaration))
         if opt['help']:
             opt_items.append(nodes.paragraph(text=opt['help']))
         else:
             opt_items.append(nodes.paragraph(text='Undocumented'))
         if 'choices' in opt:
             opt_items.append(
                 nodes.paragraph(
                     text='Possible choices: ' + ', '.join(opt['choices'])))
         items.append(
             nodes.option_list_item(
                 '', nodes.option_group('', *names),
                 nodes.description('', *opt_items)))
     return nodes.option_list('', *items)
Esempio n. 6
0
def print_arg_list(data, nested_content):

    definitions = map_nested_definitions(nested_content)

    items = []

    if 'args' in data:
        for arg in data['args']:
            my_def = [nodes.paragraph(text=arg['help'])] if arg['help'] else []

            name = arg['name']

            my_def = apply_definition(definitions, my_def, name)

            if len(my_def) == 0:
                my_def.append(nodes.paragraph(text='Undocumented'))

            items.append(
                nodes.option_list_item('',
                    nodes.option_group('', nodes.option_string(text=name)),
                    nodes.description('', *my_def)
                )
            )

    return nodes.option_list('', *items) if items else None
Esempio n. 7
0
    def run(self):  # type: () -> List[nodes.Node]
        location = self.state_machine.get_source_and_line(self.lineno)
        cfg_path = self.arguments[0]
        config_cls = self._get_class(cfg_path, location)

        if config_cls is None:
            return []

        config = config_cls('')
        result = []

        if 'no-docstrings' in self.options:
            toml = config.export_toml()
            result.append(self._new_toml_block(toml))
        else:
            for docstring, toml in config.get_docblocks():
                if docstring:
                    rst = StringList(docstring.split('\n'))
                    # Create a node.
                    node = nodes.option_string()
                    node.document = self.state.document

                    # Parse the rst.
                    self.state.nested_parse(rst, 0, node)
                    result.append(node)

                if toml:
                    result.append(self._new_toml_block(toml))

        return result
Esempio n. 8
0
def print_arg_list(data, nested_content):

    definitions = map_nested_definitions(nested_content)

    items = []

    if 'args' in data:
        for arg in data['args']:
            my_def = [nodes.paragraph(text=arg['help'])] if arg['help'] else []

            name = arg['name']

            my_def = apply_definition(definitions, my_def, name)

            if len(my_def) == 0:
                my_def.append(nodes.paragraph(text='Undocumented'))

            items.append(
                nodes.option_list_item('',
                    nodes.option_group('', nodes.option_string(text=name)),
                    nodes.description('', *my_def)
                )
            )

    return nodes.option_list('', *items) if items else None
Esempio n. 9
0
def print_arg_list(data, nested_content):
    definitions = map_nested_definitions(nested_content)
    items = []
    if 'args' in data:
        for arg in data['args']:
            my_def = [nodes.paragraph(text=arg['help'])] if arg['help'] else []
            name = arg['name']
            my_def = apply_definition(definitions, my_def, name)
            if len(my_def) == 0:
                my_def.append(nodes.paragraph(text='Undocumented'))
            if 'choices' in arg:
                my_def.append(
                    nodes.paragraph(
                        text=('Possible choices: %s' %
                              ', '.join([str(c) for c in arg['choices']]))))
            argname = name

            if arg['metavar']:
                argname = arg['metavar']

            items.append(
                nodes.option_list_item(
                    '',
                    nodes.option_group(
                        '', nodes.option('',
                                         nodes.option_string(text=argname))),
                    nodes.description('', *my_def)))
    return nodes.option_list('', *items) if items else None
Esempio n. 10
0
    def __add_option(self, option):
        if option.action not in ('callback','store_const','store_true',
                'store_false','count','version','help'):
            optnodes = [ nodes.option('', nodes.option_string('',o),
                nodes.option_argument('', option.metavar or 'ARG'))
                for o in option._short_opts + option._long_opts ]
        else:                
            optnodes = [ nodes.option('', nodes.option_string('',o),)
                for o in option._short_opts + option._long_opts ]

        help =  u''                
        if option.help != optparse.SUPPRESS_HELP:
            if option.default != optparse.NO_DEFAULT:
                help = option.help.replace('%default', str(option.default))
            else:                
                help = option.help
        item = nodes.option_list_item('',
                nodes.option_group('', *optnodes))
        if help:
            item += nodes.description('',nodes.paragraph('',help))
        return item
Esempio n. 11
0
 def _format_positional_arguments(self, parser_info):
     assert 'args' in parser_info
     items = []
     for arg in parser_info['args']:
         arg_items = []
         if arg['help']:
             arg_items.append(nodes.paragraph(text=arg['help']))
         elif 'choices' not in arg:
             arg_items.append(nodes.paragraph(text='Undocumented'))
         if 'choices' in arg:
             arg_items.append(
                 nodes.paragraph(text='Possible choices: ' +
                                 ', '.join(arg['choices'])))
         items.append(
             nodes.option_list_item(
                 '',
                 nodes.option_group(
                     '',
                     nodes.option(
                         '', nodes.option_string(text=arg['metavar']))),
                 nodes.description('', *arg_items)))
     return nodes.option_list('', *items)
Esempio n. 12
0
def print_opt_list(data, nested_content):
    definitions = map_nested_definitions(nested_content)
    nodes_list = [
    ]  # dictionary to hold the group options, the group title is used as the key
    if 'action_groups' in data:
        for action_group in data['action_groups']:
            items = []
            if 'options' in action_group:
                for opt in action_group['options']:
                    names = []
                    my_def = [nodes.paragraph(
                        text=opt['help'])] if opt['help'] else []
                    for name in opt['name']:
                        option_declaration = [nodes.option_string(text=name)]
                        if opt['default'] is not None \
                                and opt['default'] != '==SUPPRESS==':
                            option_declaration += nodes.option_argument(
                                '', text='=' + str(opt['default']))
                        names.append(nodes.option('', *option_declaration))
                        my_def = apply_definition(definitions, my_def, name)
                    if len(my_def) == 0 and 'choices' not in opt:
                        my_def.append(nodes.paragraph(text='Undocumented'))
                    if 'choices' in opt:
                        my_def.append(
                            nodes.paragraph(text=(
                                'Possible choices: %s' %
                                ', '.join([str(c) for c in opt['choices']]))))
                    items.append(
                        nodes.option_list_item('',
                                               nodes.option_group('', *names),
                                               nodes.description('', *my_def)))
            opts = nodes.option_list('', *items) if items else None
            nodes_list.append({
                'options': opts,
                'title': action_group['title'],
                'description': action_group['description']
            })
    return nodes_list
Esempio n. 13
0
 def _format_positional_arguments(self, parser_info):
     assert 'args' in parser_info
     items = []
     for arg in parser_info['args']:
         arg_items = []
         if arg['help']:
             arg_items.append(nodes.paragraph(text=arg['help']))
         elif 'choices' not in arg:
             arg_items.append(nodes.paragraph(text='Undocumented'))
         if 'choices' in arg:
             arg_items.append(
                 nodes.paragraph(
                     text='Possible choices: ' + ', '.join(arg['choices'])))
         items.append(
             nodes.option_list_item(
                 '',
                 nodes.option_group(
                     '', nodes.option(
                         '', nodes.option_string(text=arg['metavar'])
                     )
                 ),
                 nodes.description('', *arg_items)))
     return nodes.option_list('', *items)
Esempio n. 14
0
def print_arg_list(data, nested_content):
    definitions = map_nested_definitions(nested_content)
    items = []
    if 'args' in data:
        for arg in data['args']:
            my_def = [nodes.paragraph(text=arg['help'])] if arg['help'] else []
            name = arg['name']
            my_def = apply_definition(definitions, my_def, name)
            if len(my_def) == 0:
                my_def.append(nodes.paragraph(text='Undocumented'))
            if 'choices' in arg:
                my_def.append(nodes.paragraph(
                    text=('Possible choices: %s' % ', '.join([str(c) for c in arg['choices']]))))
            argname = name

            if arg['metavar']:
                argname = arg['metavar']

            items.append(
                nodes.option_list_item(
                    '', nodes.option_group('',
                          nodes.option('', nodes.option_string(text=argname))),
                    nodes.description('', *my_def)))
    return nodes.option_list('', *items) if items else None
Esempio n. 15
0
def print_action_groups(data,
                        nested_content,
                        markDownHelp=False,
                        settings=None):
    """
    Process all 'action groups', which are also include 'Options' and 'Required
    arguments'. A list of nodes is returned.
    """
    definitions = map_nested_definitions(nested_content)
    nodes_list = []
    if 'action_groups' in data:
        for action_group in data['action_groups']:
            # Every action group is comprised of a section, holding a title, the description, and the option group (members)
            section = nodes.section(ids=[action_group['title']])
            section += nodes.title(action_group['title'],
                                   action_group['title'])

            desc = []
            if action_group['description']:
                desc.append(action_group['description'])
            # Replace/append/prepend content to the description according to nested content
            subContent = []
            if action_group['title'] in definitions:
                classifier, s, subContent = definitions[action_group['title']]
                if classifier == '@replace':
                    desc = [s]
                elif classifier == '@after':
                    desc.append(s)
                elif classifier == '@before':
                    desc.insert(0, s)
                elif classifier == '@skip':
                    continue
                if len(subContent) > 0:
                    for k, v in map_nested_definitions(subContent).items():
                        definitions[k] = v
            # Render appropriately
            for element in renderList(desc, markDownHelp, settings=settings):
                section += element

            localDefinitions = definitions
            if len(subContent) > 0:
                localDefinitions = {k: v for k, v in definitions.items()}
                for k, v in map_nested_definitions(subContent).items():
                    localDefinitions[k] = v

            items = []
            # Iterate over action group members
            for entry in action_group['options']:
                """
                Members will include:
                    default	The default value. This may be ==SUPPRESS==
                    name	A list of option names (e.g., ['-h', '--help']
                    help	The help message string
                There may also be a 'choices' member.
                """
                # Build the help text
                arg = []
                if 'choices' in entry:
                    arg.append('Possible choices: {}\n'.format(", ".join(
                        [str(c) for c in entry['choices']])))
                if 'help' in entry:
                    arg.append(entry['help'])
                if entry['default'] is not None and entry['default'] not in [
                        '"==SUPPRESS=="', '==SUPPRESS=='
                ]:
                    if entry['default'] == '':
                        arg.append('Default: ""')
                    else:
                        arg.append('Default: {}'.format(entry['default']))

                # Handle nested content, the term used in the dict has the comma removed for simplicity
                desc = arg
                term = ' '.join(entry['name'])
                if term in localDefinitions:
                    classifier, s, subContent = localDefinitions[term]
                    if classifier == '@replace':
                        desc = [s]
                    elif classifier == '@after':
                        desc.append(s)
                    elif classifier == '@before':
                        desc.insert(0, s)
                term = ', '.join(entry['name'])

                n = nodes.option_list_item(
                    '', nodes.option_group('', nodes.option_string(text=term)),
                    nodes.description(
                        '', *renderList(desc, markDownHelp, settings)))
                items.append(n)

            section += nodes.option_list('', *items)
            nodes_list.append(section)

    return nodes_list
Esempio n. 16
0
def print_action_groups(data, nested_content, markDownHelp=False, settings=None):
    """
    Process all 'action groups', which are also include 'Options' and 'Required
    arguments'. A list of nodes is returned.
    """
    definitions = map_nested_definitions(nested_content)
    nodes_list = []
    if 'action_groups' in data:
        for action_group in data['action_groups']:
            # Every action group is comprised of a section, holding a title, the description, and the option group (members)
            section = nodes.section(ids=[action_group['title']])
            section += nodes.title(action_group['title'], action_group['title'])

            desc = []
            if action_group['description']:
                desc.append(action_group['description'])
            # Replace/append/prepend content to the description according to nested content
            subContent = []
            if action_group['title'] in definitions:
                classifier, s, subContent = definitions[action_group['title']]
                if classifier == '@replace':
                    desc = [s]
                elif classifier == '@after':
                    desc.append(s)
                elif classifier == '@before':
                    desc.insert(0, s)
                elif classifier == '@skip':
                    continue
                if len(subContent) > 0:
                    for k, v in map_nested_definitions(subContent).items():
                        definitions[k] = v
            # Render appropriately
            for element in renderList(desc, markDownHelp):
                section += element

            localDefinitions = definitions
            if len(subContent) > 0:
                localDefinitions = {k: v for k, v in definitions.items()}
                for k, v in map_nested_definitions(subContent).items():
                    localDefinitions[k] = v

            items = []
            # Iterate over action group members
            for entry in action_group['options']:
                """
                Members will include:
                    default	The default value. This may be ==SUPPRESS==
                    name	A list of option names (e.g., ['-h', '--help']
                    help	The help message string
                There may also be a 'choices' member.
                """
                # Build the help text
                arg = []
                if 'choices' in entry:
                    arg.append('Possible choices: {}\n'.format(", ".join([str(c) for c in entry['choices']])))
                if 'help' in entry:
                    arg.append(entry['help'])
                if entry['default'] is not None and entry['default'] not in ['"==SUPPRESS=="', '==SUPPRESS==']:
                    if entry['default'] == '':
                        arg.append('Default: ""')
                    else:
                        arg.append('Default: {}'.format(entry['default']))

                # Handle nested content, the term used in the dict has the comma removed for simplicity
                desc = arg
                term = ' '.join(entry['name'])
                if term in localDefinitions:
                    classifier, s, subContent = localDefinitions[term]
                    if classifier == '@replace':
                        desc = [s]
                    elif classifier == '@after':
                        desc.append(s)
                    elif classifier == '@before':
                        desc.insert(0, s)
                term = ', '.join(entry['name'])

                n = nodes.option_list_item('',
                                           nodes.option_group('', nodes.option_string(text=term)),
                                           nodes.description('', *renderList(desc, markDownHelp, settings)))
                items.append(n)

            section += nodes.option_list('', *items)
            nodes_list.append(section)

    return nodes_list