Example #1
0
    def run(self):
        prefix = self.arguments and self.arguments.pop() or None
        content = []
        for resource_type, resource_class in _all_resources(prefix):
            self.resource_type = resource_type
            self.resource_class = resource_class
            section = self._section(content, resource_type, '%s')

            self.props_schemata = properties.schemata(
                self.resource_class.properties_schema)

            if resource_class.support_status.status == support.DEPRECATED:
                sstatus = resource_class.support_status.to_dict()
                msg = _('%(status)s')
                if sstatus['message'] is not None:
                    msg = _('%(status)s - %(message)s')
                para = nodes.inline('', msg % sstatus)
                warning = nodes.note('', para)
                section.append(warning)

            cls_doc = pydoc.getdoc(resource_class)
            if cls_doc:
                para = nodes.paragraph('', cls_doc)
                section.append(para)

            self.contribute_properties(section)
            self.contribute_attributes(section)

            self.contribute_hot_syntax(section)
            self.contribute_yaml_syntax(section)
            self.contribute_json_syntax(section)

        return content
Example #2
0
    def contribute_attributes(self, parent):
        if not self.attrs_schemata:
            return
        section = self._section(parent, _('Attributes'), '%s-attrs')
        prop_list = nodes.definition_list()
        section.append(prop_list)
        for prop_key, prop in sorted(self.attrs_schemata.items()):
            description = prop.description
            prop_item = nodes.definition_list_item(
                '', nodes.term('', prop_key))
            prop_list.append(prop_item)

            definition = nodes.definition()
            prop_item.append(definition)

            if prop.support_status.status != support.SUPPORTED:
                sstatus = prop.support_status.to_dict()
                msg = _('%(status)s')
                if sstatus['message'] is not None:
                    msg = _('%(status)s - %(message)s')
                para = nodes.inline('', msg % sstatus)
                warning = nodes.note('', para)
                definition.append(warning)

            if description:
                def_para = nodes.paragraph('', description)
                definition.append(def_para)
Example #3
0
def convert_html(soup):
    if isinstance(soup, str):
        if soup.startswith('NOTE:'):
            return nodes.note('', nodes.inline('', soup[5:]))
        if soup.startswith('TODO:'):
            soup = ''
        return nodes.inline('', soup)
    if soup.name == 'p':
        return nodes.paragraph(
            '', '', *[convert_html(child) for child in soup.childGenerator()])
    elif soup.name == 'i':
        return nodes.emphasis(
            '', '', *[convert_html(child) for child in soup.childGenerator()])
    elif soup.name == 'b':
        return nodes.strong(
            '', '', *[convert_html(child) for child in soup.childGenerator()])
    elif soup.name == 'code':
        return nodes.literal(
            '', '', *[convert_html(child) for child in soup.childGenerator()])
    elif soup.name == 'pre':
        return nodes.literal_block(
            '', '', *[convert_html(child) for child in soup.childGenerator()])
    else:
        return nodes.inline(
            '', '', *[convert_html(child) for child in soup.childGenerator()])
Example #4
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item(
            '', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        if not prop.implemented:
            para = nodes.inline('', _('Not implemented.'))
            warning = nodes.note('', para)
            definition.append(warning)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if prop.update_allowed:
            para = nodes.paragraph('',
                                   _('Can be updated without replacement.'))
            definition.append(para)
        else:
            para = nodes.paragraph('', _('Updates cause replacement.'))
            definition.append(para)

        if prop.required:
            para = nodes.paragraph('', _('Required property.'))
        elif prop.default is not None:
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.default)
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.MAP:
            para = nodes.emphasis('', _('Map properties:'))
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.LIST:
            para = nodes.emphasis(
                '', _('List contents:'))
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key in sorted(sub_schema.keys()):
                sub_prop = sub_schema[sub_prop_key]
                self.contribute_property(sub_prop_list, sub_prop_key, sub_prop)
Example #5
0
    def contribute_attributes(self, parent):
        if not self.attrs_schemata:
            return
        section = self._section(parent, _('Attributes'), '%s-attrs')
        prop_list = nodes.definition_list()
        section.append(prop_list)
        for prop_key, prop in sorted(self.attrs_schemata.items()):
            description = prop.description
            prop_item = nodes.definition_list_item(
                '', nodes.term('', prop_key))
            prop_list.append(prop_item)

            definition = nodes.definition()
            prop_item.append(definition)

            if prop.support_status.status != support.SUPPORTED:
                sstatus = prop.support_status.to_dict()
                msg = _('%(status)s')
                if sstatus['message'] is not None:
                    msg = _('%(status)s - %(message)s')
                para = nodes.inline('', msg % sstatus)
                warning = nodes.note('', para)
                definition.append(warning)

            if description:
                def_para = nodes.paragraph('', description)
                definition.append(def_para)
Example #6
0
    def run(self):
        prefix = self.arguments and self.arguments.pop() or None
        content = []
        for resource_type, resource_class in _all_resources(prefix):
            self.resource_type = resource_type
            self.resource_class = resource_class
            section = self._section(content, resource_type, '%s')

            self.props_schemata = properties.schemata(
                self.resource_class.properties_schema)
            self.attrs_schemata = attributes.schemata(
                self.resource_class.attributes_schema)

            if resource_class.support_status.status == support.DEPRECATED:
                sstatus = resource_class.support_status.to_dict()
                msg = _('%(status)s')
                if sstatus['message'] is not None:
                    msg = _('%(status)s - %(message)s')
                para = nodes.inline('', msg % sstatus)
                warning = nodes.note('', para)
                section.append(warning)

            cls_doc = pydoc.getdoc(resource_class)
            if cls_doc:
                para = nodes.paragraph('', cls_doc)
                section.append(para)

            self.contribute_properties(section)
            self.contribute_attributes(section)

            self.contribute_hot_syntax(section)
            self.contribute_yaml_syntax(section)
            self.contribute_json_syntax(section)

        return content
Example #7
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item('', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        if not prop.implemented:
            para = nodes.inline('', _('Not implemented.'))
            warning = nodes.note('', para)
            definition.append(warning)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if prop.update_allowed:
            para = nodes.paragraph('',
                                   _('Can be updated without replacement.'))
            definition.append(para)
        else:
            para = nodes.paragraph('', _('Updates cause replacement.'))
            definition.append(para)

        if prop.required:
            para = nodes.paragraph('', _('Required property.'))
        elif prop.default is not None:
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.default)
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.MAP:
            para = nodes.emphasis('', _('Map properties:'))
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.LIST:
            para = nodes.emphasis('', _('List contents:'))
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key in sorted(sub_schema.keys()):
                sub_prop = sub_schema[sub_prop_key]
                self.contribute_property(sub_prop_list, sub_prop_key, sub_prop)
Example #8
0
 def default_container(self, token, message):
     """Report a warning and use the default note admonition."""
     self.current_node.append(
         self.reporter.warning(
             f"{message}, defaulting to note: {token.info}",
             line=token.map[0],
         ))
     admonition = nodes.note("")
     self.add_line_and_source_path(admonition, token)
     with self.current_node_context(admonition, append=True):
         self.render_children(token)
Example #9
0
def getErrorString(state):
    (nm, ne, nw) = omc.sendExpression("countMessages()")
    s = fixPaths(omc.sendExpression("OpenModelica.Scripting.getErrorString()"))
    if nm == 0:
        return []
    node = nodes.paragraph()
    for x in s.split("\n"):
        node += nodes.paragraph(text=x)
    if ne > 0:
        return [nodes.error(None, node)]
    elif nw > 0:
        return [nodes.warning(None, node)]
    else:
        return [nodes.note(None, node)]
def getErrorString(state):
  (nm,ne,nw) = omc.sendExpression("countMessages()")
  s = fixPaths(omc.sendExpression("OpenModelica.Scripting.getErrorString()"))
  if nm==0:
    return []
  node = nodes.paragraph()
  for x in s.split("\n"):
    node += nodes.paragraph(text = x)
  if ne>0:
    return [nodes.error(None, node)]
  elif nw>0:
    return [nodes.warning(None, node)]
  else:
    return [nodes.note(None, node)]
Example #11
0
 def render_container_admonition_open(self, token):
     match = REGEX_ADMONTION.match(token.info.strip())
     if not match:
         self.current_node.append(
             self.reporter.warning(
                 "admonition argument did not match required regex, "
                 f"defaulting to note: {token.info}",
                 line=token.map[0],
             ))
         admonition = nodes.note("")
     else:
         admonition = self.get_admonition(token, **match.groupdict())
     self.add_line_and_source_path(admonition, token)
     with self.current_node_context(admonition, append=True):
         self.render_children(token)
 def build_content(self):
     """Return the main content (docstring, inputs, outputs) of the documentation."""
     note = """
     If arguments are bold, they are required, otherwise they are optional. The required type is in between square
     brackets []. If the argument only accepts a certain number of values, they are listed in between angular
     brackets <>.
     """
     content = addnodes.desc_content()
     content += nodes.paragraph(text=self.process.__doc__)
     content += nodes.note('', nodes.paragraph(text=note))
     content += self.build_doctree(
         title='Keyword arguments:',
         port_namespace=self.process_spec.inputs,
     )
     return content
Example #13
0
 def _status_str(self, support_status, section):
     sstatus = support_status.to_dict()
     if sstatus['status'] is support.SUPPORTED:
         msg = _('Available')
     else:
         msg = sstatus['status']
     if sstatus['version'] is not None:
         msg = _('%s since %s') % (msg,
                                   self._version_str(sstatus['version']))
     if sstatus['message'] is not None:
         msg = _('%s - %s') % (msg, sstatus['message'])
     if not (sstatus['status'] is support.SUPPORTED and
             sstatus['version'] is None):
         para = nodes.paragraph(_(''), msg)
         note = nodes.note(_(''), para)
         section.append(note)
Example #14
0
 def _status_str(self, support_status, section):
     while support_status is not None:
         sstatus = support_status.to_dict()
         if sstatus["status"] is support.SUPPORTED:
             msg = _("Available")
         else:
             msg = sstatus["status"]
         if sstatus["version"] is not None:
             msg = _("%(msg)s since %(version)s") % {"msg": msg, "version": self._version_str(sstatus["version"])}
         if sstatus["message"] is not None:
             msg = _("%(msg)s - %(status_msg)s") % {"msg": msg, "status_msg": sstatus["message"]}
         if not (sstatus["status"] == support.SUPPORTED and sstatus["version"] is None):
             para = nodes.paragraph("", msg)
             note = nodes.note("", para)
             section.append(note)
         support_status = support_status.previous_status
Example #15
0
 def _status_str(self, support_status, section):
     sstatus = support_status.to_dict()
     if sstatus['status'] is support.SUPPORTED:
         msg = _('Available')
     else:
         msg = sstatus['status']
     if sstatus['version'] is not None:
         msg = _('%s since %s') % (msg,
                                   self._version_str(sstatus['version']))
     if sstatus['message'] is not None:
         msg = _('%s - %s') % (msg, sstatus['message'])
     if not (sstatus['status'] is support.SUPPORTED and
             sstatus['version'] is None):
         para = nodes.paragraph(_(''), msg)
         note = nodes.note(_(''), para)
         section.append(note)
Example #16
0
    def run(self):
        module_name = self.options['module']

        # FIXME Check for nested modules? Currently caught in
        # ComponentTranslator below but we should probably do it here.

        env = self.state.document.settings.env
        if not hasattr(env, 'litmodel_components'):
            env.litmodel_components = {}
        env.litmodel_components[env.docname] = module_name

        note_node = note()
        paragraph_node = paragraph('', '',
                                   Text('This section defines the component '),
                                   literal('', module_name), Text('.'))
        note_node += paragraph_node

        return [note_node]
Example #17
0
    def run(self):
        module_name = self.options['module']

        # FIXME Check for nested modules? Currently caught in
        # ComponentTranslator below but we should probably do it here.

        env = self.state.document.settings.env
        if not hasattr(env, 'litmodel_components'):
            env.litmodel_components = {}
        env.litmodel_components[env.docname] = module_name

        note_node = note()
        paragraph_node = paragraph('', '',
                                   Text('This section defines the component '),
                                   literal('', module_name),
                                   Text('.'))
        note_node += paragraph_node

        return [note_node]
Example #18
0
 def _status_str(self, support_status, section):
     while support_status is not None:
         sstatus = support_status.to_dict()
         if sstatus['status'] is support.SUPPORTED:
             msg = _('Available')
         else:
             msg = sstatus['status']
         if sstatus['version'] is not None:
             msg = _('%(msg)s since %(version)s') % {
                 'msg': msg,
                 'version': self._version_str(sstatus['version'])}
         if sstatus['message'] is not None:
             msg = _('%(msg)s - %(status_msg)s') % {
                 'msg': msg,
                 'status_msg': sstatus['message']}
         if not (sstatus['status'] == support.SUPPORTED and
                 sstatus['version'] is None):
             para = nodes.paragraph('', msg)
             note = nodes.note('', para)
             section.append(note)
         support_status = support_status.previous_status
Example #19
0
 def run(self):
     has_fname, text, fname = split_explicit_title(self.text)
     if has_fname:
         raise ExtensionError('Page role cannot have explicit title')
     nb_url = f'{UCB_NC_NB_URL}/{text}.ipynb'
     license_url = f'{self.env.config.html_baseurl}/license'
     node = nodes.note(
         text,
         nodes.paragraph(
             text, '', nodes.Text('This page has content from the '),
             nodes.reference(nb_url, text, refuri=nb_url),
             nodes.Text(' notebook of an older version of the '),
             nodes.reference(UCB_URL,
                             'UC Berkeley data science course',
                             refuri=UCB_URL),
             nodes.Text('. See the Berkeley course section of the '),
             nodes.reference(license_url,
                             'license file',
                             refuri=license_url), nodes.Text('.')))
     set_role_source_info(self.inliner, self.lineno, node)
     return [node], []
Example #20
0
 def _status_str(self, support_status, section):
     while support_status is not None:
         sstatus = support_status.to_dict()
         if sstatus['status'] is support.SUPPORTED:
             msg = _('Available')
         else:
             msg = sstatus['status']
         if sstatus['version'] is not None:
             msg = _('%(msg)s since %(version)s') % {
                 'msg': msg,
                 'version': self._version_str(sstatus['version'])}
         if sstatus['message'] is not None:
             msg = _('%(msg)s - %(status_msg)s') % {
                 'msg': msg,
                 'status_msg': sstatus['message']}
         if not (sstatus['status'] == support.SUPPORTED and
                 sstatus['version'] is None):
             para = nodes.paragraph('', msg)
             note = nodes.note('', para)
             section.append(note)
         support_status = support_status.previous_status
Example #21
0
    def run(self):
        prefix = self.arguments and self.arguments.pop() or None
        content = []
        for resource_type, resource_class in _all_resources(prefix):
            self.resource_type = resource_type
            self.resource_class = resource_class
            section = self._section(content, resource_type, '%s')

            self.props_schemata = properties.schemata(
                self.resource_class.properties_schema)
            self.attrs_schemata = attributes.schemata(
                self.resource_class.attributes_schema)

            if resource_class.support_status.status == support.DEPRECATED:
                para = nodes.paragraph('', self._status_str(
                                       resource_class.support_status))
                note = nodes.note('', para)
                section.append(note)

            cls_doc = pydoc.getdoc(resource_class)
            if cls_doc:
                # allow for rst in the class comments
                cls_nodes = core.publish_doctree(cls_doc).children
                section.extend(cls_nodes)

            if (resource_class.support_status.status == support.SUPPORTED and
               resource_class.support_status.version is not None):
                tag = resource_class.support_status.version.title()
                message = (_('Available since %s.') % self._version_str(tag))
                para = nodes.paragraph('', message)
                section.append(para)

            self.contribute_properties(section)
            self.contribute_attributes(section)

            self.contribute_hot_syntax(section)
            self.contribute_yaml_syntax(section)
            self.contribute_json_syntax(section)

        return content
Example #22
0
    def run(self):
        prefix = self.arguments and self.arguments.pop() or None
        content = []
        for resource_type, resource_class in _all_resources(prefix):
            self.resource_type = resource_type
            self.resource_class = resource_class
            section = self._section(content, resource_type, '%s')

            self.props_schemata = properties.schemata(
                self.resource_class.properties_schema)
            self.attrs_schemata = attributes.schemata(
                self.resource_class.attributes_schema)

            if resource_class.support_status.status == support.DEPRECATED:
                para = nodes.paragraph('', self._status_str(
                                       resource_class.support_status))
                note = nodes.note('', para)
                section.append(note)

            cls_doc = pydoc.getdoc(resource_class)
            if cls_doc:
                # allow for rst in the class comments
                cls_nodes = core.publish_doctree(cls_doc).children
                section.extend(cls_nodes)

            if (resource_class.support_status.status == support.SUPPORTED and
               resource_class.support_status.version is not None):
                tag = resource_class.support_status.version.title()
                message = (_('Available since %s.') % self._version_str(tag))
                para = nodes.paragraph('', message)
                section.append(para)

            self.contribute_properties(section)
            self.contribute_attributes(section)

            self.contribute_hot_syntax(section)
            self.contribute_yaml_syntax(section)
            self.contribute_json_syntax(section)

        return content
Example #23
0
    def contribute_attributes(self, parent):
        if not self.attrs_schemata:
            return
        section = self._section(parent, _('Attributes'), '%s-attrs')
        prop_list = nodes.definition_list()
        section.append(prop_list)
        for prop_key, prop in sorted(self.attrs_schemata.items()):
            description = prop.description
            prop_item = nodes.definition_list_item(
                '', nodes.term('', prop_key))
            prop_list.append(prop_item)

            definition = nodes.definition()
            prop_item.append(definition)

            if prop.support_status.status != support.SUPPORTED:
                para = nodes.paragraph('',
                                       self._status_str(prop.support_status))
                note = nodes.note('', para)
                definition.append(note)

            if description:
                def_para = nodes.paragraph('', description)
                definition.append(def_para)
Example #24
0
    def contribute_attributes(self, parent):
        if not self.attrs_schemata:
            return
        section = self._section(parent, _('Attributes'), '%s-attrs')
        prop_list = nodes.definition_list()
        section.append(prop_list)
        for prop_key, prop in sorted(self.attrs_schemata.items()):
            description = prop.description
            prop_item = nodes.definition_list_item(
                '', nodes.term('', prop_key))
            prop_list.append(prop_item)

            definition = nodes.definition()
            prop_item.append(definition)

            if prop.support_status.status != support.SUPPORTED:
                para = nodes.paragraph('',
                                       self._status_str(prop.support_status))
                note = nodes.note('', para)
                definition.append(note)

            if description:
                def_para = nodes.paragraph('', description)
                definition.append(def_para)
Example #25
0
def _note(*args, **kwargs):
    note = nodes.note()
    note += nodes.paragraph(*args, **kwargs)
    return note
Example #26
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item(
            '', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        self._status_str(prop.support_status, definition)

        if not prop.implemented:
            para = nodes.paragraph('', _('Not implemented.'))
            note = nodes.note('', para)
            definition.append(note)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if prop.update_allowed:
            para = nodes.paragraph('',
                                   _('Can be updated without replacement.'))
            definition.append(para)
        elif prop.immutable:
            para = nodes.paragraph('', _('Updates are not supported. '
                                         'Resource update will fail on any '
                                         'attempt to update this property.'))
            definition.append(para)
        else:
            para = nodes.paragraph('', _('Updates cause replacement.'))
            definition.append(para)

        if prop.required:
            para = nodes.paragraph('', _('Required property.'))
        elif prop.default is not None:
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.default)
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('Map properties:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('List contents:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key, sub_prop in sorted(sub_schema.items(),
                                                 self.cmp_prop):
                self.contribute_property(
                    sub_prop_list, sub_prop_key, sub_prop)
Example #27
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item(
            '', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        if prop.support_status.status != support.SUPPORTED:
            para = nodes.paragraph('', self._status_str(prop.support_status))
            note = nodes.note('', para)
            definition.append(note)

        if (prop.support_status.status == support.SUPPORTED and
            prop.support_status.version is not None):
            tag = prop.support_status.version.title()
            message = (_('Available since %s.') % self._version_str(tag))
            para = nodes.paragraph('', message)
            note = nodes.note('', para)
            definition.append(note)

        if not prop.implemented:
            para = nodes.paragraph('', _('Not implemented.'))
            note = nodes.note('', para)
            definition.append(note)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if prop.update_allowed:
            para = nodes.paragraph('',
                                   _('Can be updated without replacement.'))
            definition.append(para)
        elif prop.immutable:
            para = nodes.paragraph('', _('Updates are not supported. '
                                         'Resource update will fail on any '
                                         'attempt to update this property.'))
            definition.append(para)
        else:
            para = nodes.paragraph('', _('Updates cause replacement.'))
            definition.append(para)

        if prop.required:
            para = nodes.paragraph('', _('Required property.'))
        elif prop.default is not None:
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.default)
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('Map properties:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('List contents:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key, sub_prop in sorted(sub_schema.items(),
                                                 self.cmp_prop):
                self.contribute_property(
                    sub_prop_list, sub_prop_key, sub_prop)
Example #28
0
def _note(*args, **kwargs):
    note = nodes.note()
    note += nodes.paragraph(*args, **kwargs)
    return note
Example #29
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item("", nodes.term("", prop_key))
        prop_list.append(prop_item)

        prop_type = prop.get("Type")
        classifier = prop_type
        if prop.get("MinValue"):
            classifier += _(" from %s") % prop.get("MinValue")
        if prop.get("MaxValue"):
            classifier += _(" up to %s") % prop.get("MaxValue")
        if prop.get("MinLength"):
            classifier += _(" from length %s") % prop.get("MinLength")
        if prop.get("MaxLength"):
            classifier += _(" up to length %s") % prop.get("MaxLength")
        prop_item.append(nodes.classifier("", classifier))

        definition = nodes.definition()
        prop_item.append(definition)

        if not prop.get("Implemented", True):
            para = nodes.inline("", _("Not implemented."))
            warning = nodes.note("", para)
            definition.append(warning)
            return

        description = prop.get("Description")
        if description:
            para = nodes.paragraph("", description)
            definition.append(para)

        if prop.get("Required"):
            para = nodes.paragraph("", _("Required property."))
        elif prop.get("Default"):
            para = nodes.paragraph("", _('Optional property, defaults to "%s".') % prop.get("Default"))
        else:
            para = nodes.paragraph("", _("Optional property."))
        definition.append(para)

        if prop.get("AllowedPattern"):
            para = nodes.paragraph("", _("Value must match pattern: %s") % prop.get("AllowedPattern"))
            definition.append(para)

        if prop.get("AllowedValues"):
            allowed = [str(a) for a in prop.get("AllowedValues") if a is not None]
            para = nodes.paragraph("", _("Allowed values: %s") % ", ".join(allowed))
            definition.append(para)

        sub_schema = None
        if prop.get("Schema") and prop_type == "Map":
            para = nodes.emphasis("", _("Map properties:"))
            definition.append(para)
            sub_schema = prop.get("Schema")

        elif prop_type == "List" and prop.get("Schema", {}).get("Schema"):
            para = nodes.emphasis("", _("List contains maps with the properties:"))
            definition.append(para)
            sub_schema = prop.get("Schema").get("Schema")

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key in sorted(sub_schema.keys()):
                sub_prop = sub_schema[sub_prop_key]
                self.contribute_property(sub_prop_list, sub_prop_key, sub_prop)
Example #30
0
from docutils import utils
import string

import six


def parse_text(text):
    parser = rst.Parser()
    settings = frontend.OptionParser(
        components=(rst.Parser,)).get_default_values()
    document = utils.new_document(text, settings)
    parser.parse(text, document)
    return document.children

paragraph = lambda text: parse_text(text)[0]
note = lambda msg: nodes.note("", paragraph(msg))
hint = lambda msg: nodes.hint("", *parse_text(msg))
warning = lambda msg: nodes.warning("", paragraph(msg))
category = lambda title: parse_text("%s\n%s" % (title, "-" * len(title)))[0]
subcategory = lambda title: parse_text("%s\n%s" % (title, "~" * len(title)))[0]
section = lambda title: parse_text("%s\n%s" % (title, "\"" * len(title)))[0]


def make_definition(term, ref, descriptions):
    """Constructs definition with reference to it."""
    ref = ref.replace("_", "-").replace(" ", "-")
    definition = parse_text(
        ".. _%(ref)s:\n\n* *%(term)s* [ref__]\n\n__ #%(ref)s" %
        {"ref": ref, "term": term})
    for descr in descriptions:
        if descr:
Example #31
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item(
            '', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        if prop.support_status.status != support.SUPPORTED:
            sstatus = prop.support_status.to_dict()
            msg = _('%(status)s')
            if sstatus['message'] is not None:
                msg = _('%(status)s - %(message)s')
            para = nodes.inline('', msg % sstatus)
            warning = nodes.note('', para)
            definition.append(warning)

        if not prop.implemented:
            para = nodes.inline('', _('Not implemented.'))
            warning = nodes.note('', para)
            definition.append(warning)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if prop.update_allowed:
            para = nodes.paragraph('',
                                   _('Can be updated without replacement.'))
            definition.append(para)
        else:
            para = nodes.paragraph('', _('Updates cause replacement.'))
            definition.append(para)

        if prop.required:
            para = nodes.paragraph('', _('Required property.'))
        elif prop.default is not None:
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.default)
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('Map properties:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('List contents:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key, sub_prop in sorted(sub_schema.items(),
                                                 self.cmp_prop):
                self.contribute_property(
                    sub_prop_list, sub_prop_key, sub_prop)
Example #32
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item(
            '',nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_type = prop.get('Type')
        classifier = prop_type
        if prop.get('MinValue'):
            classifier += _(' from %s') % prop.get('MinValue')
        if prop.get('MaxValue'):
            classifier += _(' up to %s') % prop.get('MaxValue')
        if prop.get('MinLength'):
            classifier += _(' from length %s') % prop.get('MinLength')
        if prop.get('MaxLength'):
            classifier += _(' up to length %s') % prop.get('MaxLength')
        prop_item.append(nodes.classifier('', classifier))

        definition = nodes.definition()
        prop_item.append(definition)

        if not prop.get('Implemented', True):
            para = nodes.inline('', _('Not implemented.'))
            warning = nodes.note('', para)
            definition.append(warning)
            return

        description = prop.get('Description')
        if description:
            para = nodes.paragraph('', description)
            definition.append(para)

        if prop.get('Required'):
            para = nodes.paragraph('', _('Required property.'))
        elif prop.get('Default'):
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.get('Default'))
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        if prop.get('AllowedPattern'):
            para = nodes.paragraph('', _(
                'Value must match pattern: %s') % prop.get('AllowedPattern'))
            definition.append(para)

        if prop.get('AllowedValues'):
            allowed = [str(a) for a in prop.get('AllowedValues') if a is not None]
            para = nodes.paragraph('', _(
                'Allowed values: %s') % ', '.join(allowed))
            definition.append(para)

        sub_schema = None
        if prop.get('Schema') and prop_type == 'Map':
            para = nodes.emphasis('', _('Map properties:'))
            definition.append(para)
            sub_schema = prop.get('Schema')

        elif prop_type == 'List' and prop.get('Schema', {}).get('Schema'):
            para = nodes.emphasis(
                '', _('List contains maps with the properties:'))
            definition.append(para)
            sub_schema = prop.get('Schema').get('Schema')

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key in sorted(sub_schema.keys()):
                sub_prop = sub_schema[sub_prop_key]
                self.contribute_property(sub_prop_list, sub_prop_key, sub_prop)
Example #33
0
    def contribute_property(self, parent, prop_key, prop, upd_para=None,
                            id_pattern_prefix=None):
        if not id_pattern_prefix:
            id_pattern_prefix = '%s-prop'
        id_pattern = id_pattern_prefix + '-' + prop_key

        definition = self._section(parent, prop_key, id_pattern)

        self._status_str(prop.support_status, definition)

        if not prop.implemented:
            para = nodes.paragraph('', _('Not implemented.'))
            note = nodes.note('', para)
            definition.append(note)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        type = nodes.paragraph('', _('%s value expected.') % prop.type)
        definition.append(type)

        if upd_para is not None:
            definition.append(upd_para)
        else:
            if prop.update_allowed:
                upd_para = nodes.paragraph(
                    '', _('Can be updated without replacement.'))
                definition.append(upd_para)
            elif prop.immutable:
                upd_para = nodes.paragraph('', _('Updates are not supported. '
                                                 'Resource update will fail on'
                                                 ' any attempt to update this '
                                                 'property.'))
                definition.append(upd_para)
            else:
                upd_para = nodes.paragraph('', _('Updates cause replacement.'))
                definition.append(upd_para)

        if prop.default is not None:
            para = nodes.paragraph('', _('Defaults to "%s".') % prop.default)
            definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('Map properties:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('List contents:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            for sub_prop_key, sub_prop in sorted(sub_schema.items(),
                                                 self.cmp_prop):
                if sub_prop.support_status.status != support.HIDDEN:
                    indent = nodes.block_quote()
                    definition.append(indent)
                    self.contribute_property(
                        indent, sub_prop_key, sub_prop, upd_para, id_pattern)
Example #34
0
    def contribute_property(self, prop_list, prop_key, prop, upd_para=None):
        prop_item = nodes.definition_list_item(
            '', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        self._status_str(prop.support_status, definition)

        if not prop.implemented:
            para = nodes.paragraph('', _('Not implemented.'))
            note = nodes.note('', para)
            definition.append(note)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if upd_para is not None:
            definition.append(upd_para)
        else:
            if prop.update_allowed:
                upd_para = nodes.paragraph(
                    '', _('Can be updated without replacement.'))
                definition.append(upd_para)
            elif prop.immutable:
                upd_para = nodes.paragraph('', _('Updates are not supported. '
                                                 'Resource update will fail on'
                                                 ' any attempt to update this '
                                                 'property.'))
                definition.append(upd_para)
            else:
                upd_para = nodes.paragraph('', _('Updates cause replacement.'))
                definition.append(upd_para)

        if prop.default is not None:
            para = nodes.paragraph('', _('Defaults to "%s".') % prop.default)
            definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('Map properties:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.paragraph()
            emph = nodes.emphasis('', _('List contents:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key, sub_prop in sorted(sub_schema.items(),
                                                 self.cmp_prop):
                if sub_prop.support_status.status != support.HIDDEN:
                    self.contribute_property(
                        sub_prop_list, sub_prop_key, sub_prop, upd_para)
Example #35
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item(
            '', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_item.append(nodes.classifier('', prop.type))

        definition = nodes.definition()
        prop_item.append(definition)

        if prop.support_status.status != support.SUPPORTED:
            sstatus = prop.support_status.to_dict()
            msg = _('%(status)s')
            if sstatus['message'] is not None:
                msg = _('%(status)s - %(message)s')
            para = nodes.inline('', msg % sstatus)
            warning = nodes.note('', para)
            definition.append(warning)

        if not prop.implemented:
            para = nodes.inline('', _('Not implemented.'))
            warning = nodes.note('', para)
            definition.append(warning)
            return

        if prop.description:
            para = nodes.paragraph('', prop.description)
            definition.append(para)

        if prop.update_allowed:
            para = nodes.paragraph('',
                                   _('Can be updated without replacement.'))
            definition.append(para)
        else:
            para = nodes.paragraph('', _('Updates cause replacement.'))
            definition.append(para)

        if prop.required:
            para = nodes.paragraph('', _('Required property.'))
        elif prop.default is not None:
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') % prop.default)
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        for constraint in prop.constraints:
            para = nodes.paragraph('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.emphasis('', _('Map properties:'))
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.emphasis(
                '', _('List contents:'))
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key, sub_prop in sorted(sub_schema.items(),
                                                 self.cmp_prop):
                self.contribute_property(
                    sub_prop_list, sub_prop_key, sub_prop)
Example #36
0
import string

import six


def parse_text(text):
    parser = rst.Parser()
    settings = frontend.OptionParser(
        components=(rst.Parser, )).get_default_values()
    document = utils.new_document(text, settings)
    parser.parse(text, document)
    return document.children


paragraph = lambda text: parse_text(text)[0]
note = lambda msg: nodes.note("", paragraph(msg))
hint = lambda msg: nodes.hint("", *parse_text(msg))
warning = lambda msg: nodes.warning("", paragraph(msg))
category = lambda title: parse_text("%s\n%s" % (title, "-" * len(title)))[0]
subcategory = lambda title: parse_text("%s\n%s" % (title, "~" * len(title)))[0]
section = lambda title: parse_text("%s\n%s" % (title, "\"" * len(title)))[0]


def make_definition(term, ref, descriptions):
    """Constructs definition with reference to it"""
    ref = ref.replace("_", "-").replace(" ", "-")
    definition = parse_text(
        ".. _%(ref)s:\n\n* *%(term)s* [ref__]\n\n__ #%(ref)s" % {
            "ref": ref,
            "term": term
        })
Example #37
0
    def contribute_property(self, parent, prop_key, prop, upd_para=None,
                            id_pattern_prefix=None, sub_prop=False):
        if not id_pattern_prefix:
            id_pattern_prefix = '%s-prop'
        id_pattern = id_pattern_prefix + '-' + prop_key

        definition = self._prop_section(parent, prop_key, id_pattern)

        self._status_str(prop.support_status, definition)

        if not prop.implemented:
            para = nodes.line('', _('Not implemented.'))
            note = nodes.note('', para)
            definition.append(note)
            return

        if sub_prop and prop.type not in (properties.Schema.LIST,
                                          properties.Schema.MAP):
            if prop.required:
                para = nodes.line('', _('Required.'))
                definition.append(para)
            else:
                para = nodes.line('', _('Optional.'))
                definition.append(para)

        if prop.description:
            para = nodes.line('', prop.description)
            definition.append(para)

        type = nodes.line('', _('%s value expected.') % prop.type)
        definition.append(type)

        if upd_para is not None:
            definition.append(upd_para)
        else:
            if prop.update_allowed:
                upd_para = nodes.line(
                    '', _('Can be updated without replacement.'))
                definition.append(upd_para)
            elif prop.immutable:
                upd_para = nodes.line('', _('Updates are not supported. '
                                            'Resource update will fail on '
                                            'any attempt to update this '
                                            'property.'))
                definition.append(upd_para)
            else:
                upd_para = nodes.line('', _('Updates cause replacement.'))
                definition.append(upd_para)

        if prop.default is not None:
            para = nodes.line('', _('Defaults to '))
            default = nodes.literal('', json.dumps(prop.default))
            para.append(default)
            definition.append(para)

        for constraint in prop.constraints:
            para = nodes.line('', str(constraint))
            definition.append(para)

        sub_schema = None
        if prop.schema and prop.type == properties.Schema.MAP:
            para = nodes.line()
            emph = nodes.emphasis('', _('Map properties:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        elif prop.schema and prop.type == properties.Schema.LIST:
            para = nodes.line()
            emph = nodes.emphasis('', _('List contents:'))
            para.append(emph)
            definition.append(para)
            sub_schema = prop.schema

        if sub_schema:
            indent = nodes.definition_list()
            definition.append(indent)
            for _key, _prop in sorted(sub_schema.items(),
                                      key=cmp_to_key(self.cmp_prop)):
                if _prop.support_status.status != support.HIDDEN:
                    self.contribute_property(
                        indent, _key, _prop, upd_para, id_pattern,
                        sub_prop=True)
Example #38
0
    def contribute_property(self, prop_list, prop_key, prop):
        prop_item = nodes.definition_list_item('', nodes.term('', prop_key))
        prop_list.append(prop_item)

        prop_type = prop.get('Type')
        classifier = prop_type
        if prop.get('MinValue'):
            classifier += _(' from %s') % prop.get('MinValue')
        if prop.get('MaxValue'):
            classifier += _(' up to %s') % prop.get('MaxValue')
        if prop.get('MinLength'):
            classifier += _(' from length %s') % prop.get('MinLength')
        if prop.get('MaxLength'):
            classifier += _(' up to length %s') % prop.get('MaxLength')
        prop_item.append(nodes.classifier('', classifier))

        definition = nodes.definition()
        prop_item.append(definition)

        if not prop.get('Implemented', True):
            para = nodes.inline('', _('Not implemented.'))
            warning = nodes.note('', para)
            definition.append(warning)
            return

        description = prop.get('Description')
        if description:
            para = nodes.paragraph('', description)
            definition.append(para)

        if prop.get('Required'):
            para = nodes.paragraph('', _('Required property.'))
        elif prop.get('Default'):
            para = nodes.paragraph(
                '',
                _('Optional property, defaults to "%s".') %
                prop.get('Default'))
        else:
            para = nodes.paragraph('', _('Optional property.'))
        definition.append(para)

        if prop.get('AllowedPattern'):
            para = nodes.paragraph(
                '',
                _('Value must match pattern: %s') % prop.get('AllowedPattern'))
            definition.append(para)

        if prop.get('AllowedValues'):
            allowed = [
                str(a) for a in prop.get('AllowedValues') if a is not None
            ]
            para = nodes.paragraph(
                '',
                _('Allowed values: %s') % ', '.join(allowed))
            definition.append(para)

        sub_schema = None
        if prop.get('Schema') and prop_type == 'Map':
            para = nodes.emphasis('', _('Map properties:'))
            definition.append(para)
            sub_schema = prop.get('Schema')

        elif prop_type == 'List' and prop.get('Schema', {}).get('Schema'):
            para = nodes.emphasis('',
                                  _('List contains maps with the properties:'))
            definition.append(para)
            sub_schema = prop.get('Schema').get('Schema')

        if sub_schema:
            sub_prop_list = nodes.definition_list()
            definition.append(sub_prop_list)
            for sub_prop_key in sorted(sub_schema.keys()):
                sub_prop = sub_schema[sub_prop_key]
                self.contribute_property(sub_prop_list, sub_prop_key, sub_prop)