Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
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. 7
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. 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'))
            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. 9
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']))
         else:
             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.description(text=arg['metavar'])),
                 nodes.description('', *arg_items)))
     return nodes.option_list('', *items)
Esempio n. 10
0
def test_find_nodes():
    section = nodes.section()
    foo = nodes.Text("foo")
    desc = nodes.description()
    bar = nodes.Text("bar")
    section.children = [foo, desc, bar]
    assert find_nodes(section, "description") == [desc]
    assert find_nodes([section, desc], "description") == [desc, desc]
    assert find_nodes([], "description") == []
    assert find_nodes(section, "unknown") == []
    assert find_nodes(section, "Text") == [foo, bar]
Esempio n. 11
0
File: ext.py Progetto: EVMosaic/BAM
 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']))
         else:
             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.description(text=arg['metavar'])),
                 nodes.description('', *arg_items)))
     return nodes.option_list('', *items)
Esempio n. 12
0
def test_find_nodes():
    section = nodes.section()
    foo = nodes.Text('foo')
    desc = nodes.description()
    bar = nodes.Text('bar')
    section.children = [foo, desc, bar]
    assert(find_nodes(section, 'description') == [desc])
    assert(find_nodes([section, desc], 'description') == [desc, desc])
    assert(find_nodes([], 'description') == [])
    assert(find_nodes(section, 'unknown') == [])
    assert(find_nodes(section, 'Text') == [foo, bar])
Esempio n. 13
0
def test_find_nodes():
    section = nodes.section()
    foo = nodes.Text('foo')
    desc = nodes.description()
    bar = nodes.Text('bar')
    section.children = [foo, desc, bar]
    assert (find_nodes(section, 'description') == [desc])
    assert (find_nodes([section, desc], 'description') == [desc, desc])
    assert (find_nodes([], 'description') == [])
    assert (find_nodes(section, 'unknown') == [])
    assert (find_nodes(section, 'Text') == [foo, bar])
Esempio n. 14
0
    def run(self):
        # Load translation
        langDict = loadTable()
        res = ''

        section_id = self.arguments[0]

        # If a display name is provided, use that for the button text
        # If not, use the section identifier (converted from camelcase to space delimited)
        if 'long_name' in self.options:
            button_text = self.options['long_name']
        else:
            button_text = re.sub("([a-z])([A-Z])", "\g<1> \g<2>", section_id)

        #Set the content to display by default
        display = 'block'

        if 'showhide' in self.options and self.options['showhide'] == 'hide':
            display = 'none'

        anchor_node = anchorsection()
        anchor_node.attributes['ids'] = section_id

        button_node = buttonsection()
        button_node.attributes['type'] = 'button'
        button_node.attributes['ids'] = "%s_showhide_btn" % section_id
        button_node.attributes['class'] = 'showHideLink'

        showhide_node = showhidesection()
        showhide_node.attributes['section_id'] = section_id
        showhide_node.attributes['long_name'] = button_text
        showhide_node.attributes['showhide'] = showhide
        showhide_node.attributes['ids'] = section_id
        showhide_node.attributes['style'] = 'display:%s' % display
        showhide_node.attributes['data-type'] = 'analysis_text'

        super_node = containersection()
        super_node += anchor_node
        if 'showhide' in self.options and self.options['showhide'] == 'show':
            button_node.attributes['value'] = '%s %s' % (langDict['hide'],
                                                         button_text)
            super_node += button_node
        if 'showhide' in self.options and self.options['showhide'] == 'hide':
            button_node.attributes['value'] = '%s %s' % (langDict['show'],
                                                         button_text)
            super_node += button_node

        if self.content:
            node = nodes.Element()  # anonymous container for parsing
            self.state.nested_parse(self.content, self.content_offset, node)
            showhide_node += nodes.description('', *node)
            super_node += showhide_node
        return [super_node]
Esempio n. 15
0
  def run (self):
    # Load translation
    langDict = loadTable()
    res = ''

    section_id = self.arguments[0]

    # If a display name is provided, use that for the button text
    # If not, use the section identifier (converted from camelcase to space delimited)
    if 'long_name' in self.options:
      button_text = self.options['long_name']
    else:
      button_text = re.sub("([a-z])([A-Z])", "\g<1> \g<2>", section_id)

     #Set the content to display by default
    display = 'block'

    if 'showhide' in self.options and self.options['showhide'] == 'hide':
      display = 'none'



    anchor_node = anchorsection()
    anchor_node.attributes['ids'] = section_id
 
    button_node = buttonsection()
    button_node.attributes['type'] ='button'
    button_node.attributes['ids'] = "%s_showhide_btn" %section_id
    button_node.attributes['class'] = 'showHideLink'

    showhide_node = showhidesection()
    showhide_node.attributes['section_id'] = section_id
    showhide_node.attributes['long_name'] = button_text
    showhide_node.attributes['showhide'] = showhide
    showhide_node.attributes['ids'] = section_id
    showhide_node.attributes['style'] = 'display:%s' %display 
    showhide_node.attributes['data-type'] ='analysis_text'

    super_node = containersection()
    super_node += anchor_node
    if 'showhide' in self.options and self.options['showhide'] == 'show':
      button_node.attributes['value'] = '%s %s' %( langDict['hide'], button_text)
      super_node += button_node
    if 'showhide' in self.options and self.options['showhide'] == 'hide':
      button_node.attributes['value'] = '%s %s' %( langDict['show'], button_text)
      super_node += button_node    
    
    if self.content:
      node = nodes.Element()          # anonymous container for parsing
      self.state.nested_parse(self.content, self.content_offset, node)
      showhide_node +=  nodes.description('', *node)
      super_node += showhide_node
    return  [super_node]    
Esempio n. 16
0
def test_find_node():
    section = nodes.section()
    foo = nodes.Text("foo")
    desc = nodes.description()
    bar = nodes.Text("bar")
    section.children = [foo, desc, bar]
    assert find_node(section, "description") == desc
    check_exception(
        lambda: find_node([section, desc], "description"), "the number of nodes description is 2"
    )
    check_exception(lambda: find_node([], "description"), "the number of nodes description is 0")
    check_exception(lambda: find_node([section], "unknown"), "the number of nodes unknown is 0")
    check_exception(lambda: find_node([section], "Text"), "the number of nodes Text is 2")
Esempio n. 17
0
def test_find_node():
    section = nodes.section()
    foo = nodes.Text('foo')
    desc = nodes.description()
    bar = nodes.Text('bar')
    section.children = [foo, desc, bar]
    assert(find_node(section, 'description') == desc)
    check_exception(lambda: find_node([section, desc], 'description'),
                    'the number of nodes description is 2')
    check_exception(lambda: find_node([], 'description'),
                    'the number of nodes description is 0')
    check_exception(lambda: find_node([section], 'unknown'),
                    'the number of nodes unknown is 0')
    check_exception(lambda: find_node([section], 'Text'),
                    'the number of nodes Text is 2')
Esempio n. 18
0
def test_find_node():
    section = nodes.section()
    foo = nodes.Text('foo')
    desc = nodes.description()
    bar = nodes.Text('bar')
    section.children = [foo, desc, bar]
    assert (find_node(section, 'description') == desc)
    check_exception(lambda: find_node([section, desc], 'description'),
                    'the number of nodes description is 2')
    check_exception(lambda: find_node([], 'description'),
                    'the number of nodes description is 0')
    check_exception(lambda: find_node([section], 'unknown'),
                    'the number of nodes unknown is 0')
    check_exception(lambda: find_node([section], 'Text'),
                    'the number of nodes Text is 2')
Esempio n. 19
0
    def run(self):
        self.assert_has_content()

        title = self.arguments[0]
        content = '\n'.join(self.content)
        math_node = self.make_math_node(self.prepare_latex(content))

        tid = nodes.make_id(title)
        target = nodes.target('', '', ids=['inference-' + tid])
        self.state.document.note_explicit_target(target)

        term, desc = nodes.term('', title), nodes.description('', math_node)
        dli = nodes.definition_list_item('', term, desc)
        dl = nodes.definition_list(content, target, dli)
        set_source_info(self, dl)
        return [dl]
Esempio n. 20
0
    def run(self):
        self.assert_has_content()

        title = self.arguments[0]
        content = '\n'.join(self.content)
        math_node = self.make_math_node(self.prepare_latex(content))

        tid = nodes.make_id(title)
        target = nodes.target('', '', ids=['inference-' + tid])
        self.state.document.note_explicit_target(target)

        term, desc = nodes.term('', title), nodes.description('', math_node)
        dli = nodes.definition_list_item('', term, desc)
        dl = nodes.definition_list(content, target, dli)
        set_source_info(self, dl)
        return [dl]
Esempio n. 21
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. 22
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. 23
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. 24
0
    def run(self):
        secid = [self.arguments[0].lower().replace(' ', '-')]
        section = nodes.section(ids=secid)
        section.document = self.state.document

        section += nodes.title(text=self.arguments[0])

        # parse the 'text' option into the section, as a paragraph.
        self.state.nested_parse(
            StringList([self.options['text']], parent=self), 0, section)

        node = self.create_progtable()
        section.children[-1] += node

        head = node.children[0].children[-2].children[0]
        body = node.children[0].children[-1]

        comps = collections.OrderedDict()
        cur = ""

        for line in self.content:
            # new list
            nl = re.match(r'^:(?P<component>.+):$', line)
            if nl is not None:
                if cur != "":
                    # finish up shrow
                    self.add_progbar(shrow,
                                     len([c for c in comps[cur] if c is True]),
                                     len(comps[cur]))

                cur = nl.groupdict()['component']

                if cur not in comps:
                    comps[cur] = []

                # shrow is the section header row
                shrow = self.create_headrow(cur, classes=['field-name'])
                body += shrow

                continue

            nl = re.match(
                r'^\s+- (?P<item>[^,]+),\s+(?P<value>(True|False))(, (?P<description>.+)$)?',
                line)
            if nl is not None:
                nl = nl.groupdict()
                comps[cur].append(True if nl['value'] == "True" else False)
                tr = nodes.row()
                tr += nodes.description(
                    '',
                    nodes.inline(text="\u2713" if comps[cur][-1] else " "),
                    classes=['field-name', 'progress-checkbox'])
                text_description = nodes.inline()
                self.state.nested_parse(
                    StringList([
                        '{:s}'.format(nl['description'].lstrip(
                        ) if nl['description'] is not None else ' ')
                    ],
                               parent=self), 0, text_description)

                tr += nodes.description(
                    '',
                    nodes.strong(text='{:s} '.format(nl['item'])),
                    text_description,
                    classes=['field-value'])
                body += tr

        if self.content:
            # finish up the final hrow
            self.add_progbar(shrow, len([c for c in comps[cur] if c == True]),
                             len(comps[cur]))

        # and fill in the end of mrow
        self.add_progbar(
            head, len([c for r in comps.values() for c in r if c == True]),
            len([c for r in comps.values() for c in r]))

        return [section]
Esempio n. 25
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. 26
0
    def run(self):
        secid = [self.arguments[0].lower().replace(' ', '-')]
        section = nodes.section(ids=secid)
        section.document = self.state.document

        section += nodes.title(text=self.arguments[0])

        # parse the 'text' option into the section, as a paragraph.
        self.state.nested_parse(StringList([self.options['text']], parent=self), 0, section)

        node = self.create_progtable()
        section.children[-1] += node

        head = node.children[0].children[-2].children[0]
        body = node.children[0].children[-1]

        comps = collections.OrderedDict()
        cur = ""

        for line in self.content:
            # new list
            nl = re.match(r'^:(?P<component>.+):$', line)
            if nl is not None:
                if cur != "":
                    # finish up shrow
                    self.add_progbar(shrow, len([c for c in comps[cur] if c is True]), len(comps[cur]))

                cur = nl.groupdict()['component']

                if cur not in comps:
                    comps[cur] = []

                # shrow is the section header row
                shrow = self.create_headrow(cur, classes=['field-name'])
                body += shrow

                continue

            nl = re.match(r'^\s+- (?P<item>[^,]+),\s+(?P<value>(True|False))(, (?P<description>.+)$)?', line)
            if nl is not None:
                nl = nl.groupdict()
                comps[cur].append(True if nl['value'] == "True" else False)
                tr = nodes.row()
                tr += nodes.description('',
                                        nodes.inline(text="\u2713" if comps[cur][-1] else " "),
                                        classes=['field-name', 'progress-checkbox'])
                tr += nodes.description('',
                                        nodes.strong(text='{:s} '.format(nl['item'])),
                                        nodes.inline(text='{:s}'.format(nl['description'] if nl['description'] is not None else ' ')),
                                        classes=['field-value'])
                body += tr

        # finish up the final hrow
        self.add_progbar(shrow, len([c for c in comps[cur] if c == True]), len(comps[cur]))


        # and fill in the end of mrow
        self.add_progbar(head, len([c for r in comps.values() for c in r if c == True]), len([c for r in comps.values() for c in r]))


        return [section]
Esempio n. 27
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