Esempio n. 1
0
def get_class_docstring(clazz):
    class_description = ''
    if clazz.comment is not None:
        class_description = clazz.comment

    properties_description = []
    for prop in clazz.properties():
        prop_comment = ''
        if prop.comment is not None:
            prop_comment = prop.comment.replace('\n', ' ')
            if prop_comment.endswith('.'):
                prop_comment = prop_comment[:-1]
        meta_info_data = get_meta_info_data(
            prop, prop.property_type, prop.stmt.search_one('type'))
        if meta_info_data is None:
            continue

        keys = clazz.get_key_props()
        attribute_title = prop.name
        if prop in keys:
            attribute_title = '%s  <key>' % attribute_title
        properties_description.append('.. attribute:: %s\n\n' % (attribute_title))

        properties_description.append('\t%s\n' % (
            convert_to_reStructuredText(prop_comment)))

        properties_description.extend(get_type_doc(meta_info_data, type_depth=1))

        if clazz.stmt.search_one('presence'):
            properties_description.append(add_presence_property_docstring(clazz))

    return convert_to_reStructuredText(class_description) + '\n\n' + ''.join(properties_description)
Esempio n. 2
0
def get_class_docstring(clazz, language, identity_subclasses=None):
    class_description = ''
    if clazz.comment is not None:
        class_description = clazz.comment

    properties_description = []

    for prop in clazz.properties():
        prop_comment = ''
        if prop.comment is not None:
            prop_comment = prop.comment.replace('\n', ' ')
            if prop_comment.endswith('.'):
                prop_comment = prop_comment[:-1]

        id_subclasses = None
        if (hasattr(prop.property_type, 'is_identity') and
            prop.property_type.is_identity() and identity_subclasses is not None):
            id_subclasses = identity_subclasses

        meta_info_data = get_meta_info_data(
            prop, prop.property_type, prop.stmt.search_one('type'), language,
            identity_subclasses=id_subclasses)

        if meta_info_data is None:
            continue

        keys = clazz.get_key_props()
        attribute_title = prop.name
        if language == 'go':
            attribute_title = prop.go_name()
        if prop in keys:
            attribute_title = '%s  (key)' % attribute_title
        properties_description.append('.. attribute:: %s\n\n' % (attribute_title))

        properties_description.append('\t%s\n' % (
            convert_to_reStructuredText(prop_comment)))

        properties_description.extend(get_type_doc(meta_info_data, 1, ''))
        if len(meta_info_data.target_of_leafref) > 0:
            properties_description.append('\t**refers to**\: %s\n\n' % (meta_info_data.target_of_leafref))
        if meta_info_data.mandatory:
            properties_description.append('\t**mandatory**\: True\n\n')
        if meta_info_data.is_presence:
            properties_description.append('\t**presence node**\: True\n\n')
        if not meta_info_data.is_config:
            properties_description.append('\t**config**\: False\n\n')
        if len(meta_info_data.units) > 0:
            properties_description.append('\t**units**\: %s\n\n' % meta_info_data.units)
        if len(meta_info_data.default_value) > 0:
            properties_description.append('\t**default value**\: %s\n\n' % meta_info_data.default_value)
        if len(meta_info_data.status) > 0:
            properties_description.append('\t**status**\: %s\n\n' % meta_info_data.status)

    return convert_to_reStructuredText(class_description) + '\n\n' + ''.join(properties_description)
Esempio n. 3
0
 def _print_bits_docstring(self, bits):
     self.ctx.writeln('"""')
     self.ctx.writeln('%s' % bits.name)
     self.ctx.bline()
     if bits.comment is not None:
         for line in bits.comment.split("\n"):
             self.ctx.writeln(convert_to_reStructuredText(line))
     self.ctx.writeln(
         'Keys are:- %s' % convert_to_reStructuredText(" , ".join(bits._dictionary)))
     self.ctx.bline()
     self.ctx.writeln('"""')
     self.ctx.bline()
Esempio n. 4
0
 def _print_bits_docstring(self, bits):
     self.ctx.writeln('"""')
     self.ctx.writeln('%s' % bits.name)
     self.ctx.bline()
     if bits.comment is not None:
         for line in bits.comment.split("\n"):
             self.ctx.writeln(convert_to_reStructuredText(line))
     self.ctx.writeln(
         'Keys are:- %s' % convert_to_reStructuredText(" , ".join(bits._dictionary)))
     self.ctx.bline()
     self.ctx.writeln('"""')
     self.ctx.bline()
Esempio n. 5
0
def get_property_restriction(meta_info_data):
    prop_restriction = ''

    if len(meta_info_data.pattern) > 0:
        prop_restriction = '**pattern:** {0}'.format(
            convert_to_reStructuredText(meta_info_data.pattern[0]))
    else:
        if len(meta_info_data.prange) > 0:
            prop_restriction = '**range:** {0}'. \
                format(convert_to_reStructuredText(
                    format_range_string(meta_info_data.prange)))

    return prop_restriction
Esempio n. 6
0
def get_property_restriction(meta_info_data):
    prop_restriction = ''

    if len(meta_info_data.pattern) > 0:
        prop_restriction = '**pattern:** {0}'.format(
            convert_to_reStructuredText(meta_info_data.pattern[0]))
    else:
        if len(meta_info_data.prange) > 0:
            prop_restriction = '**range:** {0}'. \
                format(convert_to_reStructuredText(
                    format_range_string(meta_info_data.prange)))

    return prop_restriction
Esempio n. 7
0
def get_class_docstring(clazz, language, identity_subclasses=None):
    class_description = ''
    if clazz.comment is not None:
        class_description = clazz.comment

    properties_description = []

    for prop in clazz.properties():
        prop_comment = ''
        if prop.comment is not None:
            prop_comment = prop.comment.replace('\n', ' ')
            if prop_comment.endswith('.'):
                prop_comment = prop_comment[:-1]

        id_subclasses = None
        if (hasattr(prop.property_type, 'is_identity')
                and prop.property_type.is_identity()
                and identity_subclasses is not None):
            id_subclasses = identity_subclasses

        meta_info_data = get_meta_info_data(prop,
                                            prop.property_type,
                                            prop.stmt.search_one('type'),
                                            language,
                                            False,
                                            identity_subclasses=id_subclasses)

        if meta_info_data is None:
            continue

        keys = clazz.get_key_props()
        attribute_title = prop.name
        if prop in keys:
            attribute_title = '%s  <key>' % attribute_title
        properties_description.append('.. attribute:: %s\n\n' %
                                      (attribute_title))

        properties_description.append(
            '\t%s\n' % (convert_to_reStructuredText(prop_comment)))

        properties_description.extend(
            get_type_doc(meta_info_data, type_depth=1))

    if clazz.stmt.search_one('presence') and language == 'py':
        properties_description.append(add_presence_property_docstring(clazz))

    return convert_to_reStructuredText(class_description) + '\n\n' + ''.join(
        properties_description)
Esempio n. 8
0
def get_bits_class_docstring(bitz):
    bitz_description = []
    if bitz.comment is not None:
        for line in bitz.comment.split('\n'):
            bitz_description.append(convert_to_reStructuredText(line))
    bitz_description.append('\n\t**Bits positions\:**\n')
    for pos, name in enumerate(bitz._dictionary):
        bitz_description.append("\t\t%s\: %s\n" % (name, pos))

    return ''.join(bitz_description)
Esempio n. 9
0
def get_bits_class_docstring(bitz):
    bitz_description = []
    if bitz.comment is not None:
        for line in bitz.comment.split('\n'):
            bitz_description.append(convert_to_reStructuredText(line))
    bitz_description.append('\n\t**Bits positions\:**\n')
    for pos, name in enumerate(bitz._dictionary):
        bitz_description.append("\t\t%s\: %s\n" % (name, pos))

    return ''.join(bitz_description)
Esempio n. 10
0
    def _print_module_description(self, package):
        comment = package.stmt.search_one('description')
        self.ctx.writeln('""" %s ' % package.name)
        self.ctx.bline()

        if comment is not None:
            comment = comment.arg
            for line in comment.split('\n'):
                self.ctx.writeln(convert_to_reStructuredText(line))
        self.ctx.bline()
        self.ctx.writeln('"""')
Esempio n. 11
0
    def _print_module_description(self, package):
        comment = package.stmt.search_one('description')
        self.ctx.writeln('""" %s ' % package.name)
        self.ctx.bline()

        if comment is not None:
            comment = comment.arg
            for line in comment.split('\n'):
                self.ctx.writeln(convert_to_reStructuredText(line))
        self.ctx.bline()
        self.ctx.writeln('"""')
Esempio n. 12
0
def get_class_docstring(clazz):
    class_description = ''
    if clazz.comment is not None:
        class_description = clazz.comment

    properties_description = []
    for prop in clazz.properties():
        prop_comment = ''
        if prop.comment is not None:
            prop_comment = prop.comment.replace('\n', ' ')
            if prop_comment.endswith('.'):
                prop_comment = prop_comment[:-1]
        meta_info_data = get_meta_info_data(
            prop, prop.property_type, prop.stmt.search_one('type'))
        if meta_info_data is None:
            continue
        doc_link = meta_info_data.doc_link

        prop_restriction = get_property_restriction(meta_info_data)

        attribute_title = prop.name

        keys = clazz.get_key_props()
        if prop in keys:
            attribute_title = '%s  <key>' % attribute_title
        properties_description.append('.. attribute:: %s\n\n' % (attribute_title))

        properties_description.append('\t%s\n' % (
            convert_to_reStructuredText(prop_comment)))

        properties_description.append('\t**type**\: %s\n\n' % doc_link)

        if prop_restriction is not None and len(prop_restriction) > 0:
            properties_description.append('\t%s\n\n' % prop_restriction)

        if clazz.stmt.search_one('presence'):
            properties_description.append(add_presence_property_docstring(clazz))

    return convert_to_reStructuredText(class_description) + '\n\n' + ''.join(properties_description)
Esempio n. 13
0
def emit_module_header(ctx, package, mheader=None, is_meta=False):
    # ::::::::::::::::::::::::::::::::::::::::
    # Print the header
    # ::::::::::::::::::::::::::::::::::::::::
    s = package.stmt
    if is_meta:
        rpcs = [
            idx for idx in package.owned_elements
            if isinstance(idx, Class) and idx.is_rpc()
        ]
        anyxml_import = ''
        if len(rpcs) > 0:
            anyxml_import = ', ANYXML_CLASS'
        ctx.printer.meta_header(anyxml_import)
    else:
        comment = s.search_one('description')
        ctx.writeln('""" %s ' % package.name)
        ctx.bline()

        if comment is not None and not is_meta:
            ctx.comment = comment.arg
            for line in ctx.comment.split('\n'):
                ctx.writeln(convert_to_reStructuredText(line))
        ctx.bline()
        ctx.writeln('"""')
        ctx.printer.header(mheader)
        ctx.printer.imports(package)
    ctx.root = s
    ctx.augment_path = ''
    ctx.aug_stmt = None
    ctx.module_name = yang_id(s)
    ctx.module = s
    # get the yang meta information.
    prefix = s.search_one('prefix')
    if prefix is not None:
        ctx.prefix = yang_id(prefix)
    namespace = s.search_one('namespace')
    if namespace is not None:
        ctx.namespace = yang_id(namespace)
    org = s.search_one('organization')
    if org is not None:
        ctx.organization = yang_id(org)
    contact = s.search_one('contact')
    if contact is not None:
        ctx.contact = yang_id(contact)
    revision = s.search_one('revision')
    if revision is not None:
        ctx.revision = yang_id(revision)

    ctx.ns += [(yang_id(s), ctx.namespace)]
Esempio n. 14
0
def get_enum_class_docstring(enumz):
    enumz_description = ''
    if enumz.comment is not None:
        enumz_description = enumz.comment

    enumz_description = "%s\n\n\n" % (enumz.name) + enumz_description

    literals_description = []
    for enum_literal in enumz.literals:
        literals_description.append(".. data:: %s = %s\n" % (enum_literal.name, enum_literal.value))
        if enum_literal.comment is not None:
            for line in enum_literal.comment.split("\n"):
                literals_description.append("\t%s\n\n" % line)

    return ''.join([convert_to_reStructuredText(enumz_description)] + ['\n\n'] + literals_description)
Esempio n. 15
0
def emit_module_header(ctx, package, mheader=None, is_meta=False):
    # ::::::::::::::::::::::::::::::::::::::::
    # Print the header
    # ::::::::::::::::::::::::::::::::::::::::
    s = package.stmt
    if is_meta:
        rpcs = [idx for idx in package.owned_elements if isinstance(idx, Class) and idx.is_rpc()]
        anyxml_import = ''
        if len(rpcs) > 0:
            anyxml_import = ', ANYXML_CLASS'
        ctx.printer.meta_header(anyxml_import)
    else:
        comment = s.search_one('description')
        ctx.writeln('""" %s ' % package.name)
        ctx.bline()

        if comment is not None and not is_meta:
            ctx.comment = comment.arg
            for line in ctx.comment.split('\n'):
                ctx.writeln(convert_to_reStructuredText(line))
        ctx.bline()
        ctx.writeln('"""')
        ctx.printer.header(mheader)
        ctx.printer.imports(package)
    ctx.root = s
    ctx.augment_path = ''
    ctx.aug_stmt = None
    ctx.module_name = yang_id(s)
    ctx.module = s
    # get the yang meta information.
    prefix = s.search_one('prefix')
    if prefix is not None:
        ctx.prefix = yang_id(prefix)
    namespace = s.search_one('namespace')
    if namespace is not None:
        ctx.namespace = yang_id(namespace)
    org = s.search_one('organization')
    if org is not None:
        ctx.organization = yang_id(org)
    contact = s.search_one('contact')
    if contact is not None:
        ctx.contact = yang_id(contact)
    revision = s.search_one('revision')
    if revision is not None:
        ctx.revision = yang_id(revision)

    ctx.ns += [(yang_id(s), ctx.namespace)]
Esempio n. 16
0
def get_enum_class_docstring(enumz, language):
    enumz_description = ''
    if enumz.comment is not None:
        enumz_description = enumz.comment

    enumz_description = "%s (Enum Class)\n\n\n" % (enumz.name) + enumz_description

    literals_description = []
    for enum_literal in enumz.literals:
        if language == 'go':
            literals_description.append('.. data:: %s_%s\n' % (
                enumz.qualified_go_name(),
                enum_literal.name))
        else:
            literals_description.append(".. data:: %s = %s\n" % (enum_literal.name, enum_literal.value))
        if enum_literal.comment is not None:
            for line in enum_literal.comment.split("\n"):
                literals_description.append("\t%s\n\n" % line)

    return ''.join([convert_to_reStructuredText(enumz_description)] + ['\n\n'] + literals_description)
Esempio n. 17
0
def get_enum_class_docstring(enumz, language):
    enumz_description = ''
    if enumz.comment is not None:
        enumz_description = enumz.comment

    enumz_description = "%s (Enum Class)\n\n\n" % (
        enumz.name) + enumz_description

    literals_description = []
    for enum_literal in enumz.literals:
        if language == 'go':
            literals_description.append(
                '.. data:: %s_%s\n' %
                (enumz.qualified_go_name(), enum_literal.name))
        else:
            literals_description.append(
                ".. data:: %s = %s\n" %
                (enum_literal.name, enum_literal.value))
        if enum_literal.comment is not None:
            for line in enum_literal.comment.split("\n"):
                literals_description.append("\t%s\n\n" % line)

    return ''.join([convert_to_reStructuredText(enumz_description)] +
                   ['\n\n'] + literals_description)
Esempio n. 18
0
def get_class_docstring(clazz, language, identity_subclasses=None):
    class_description = ''
    if clazz.comment is not None:
        class_description = clazz.comment

    properties_description = []

    for prop in clazz.properties():
        prop_comment = ''
        if prop.comment is not None:
            prop_comment = prop.comment.replace('\n', ' ')
            if prop_comment.endswith('.'):
                prop_comment = prop_comment[:-1]

        id_subclasses = None
        if (hasattr(prop.property_type, 'is_identity')
                and prop.property_type.is_identity()
                and identity_subclasses is not None):
            id_subclasses = identity_subclasses

        meta_info_data = get_meta_info_data(prop,
                                            prop.property_type,
                                            prop.stmt.search_one('type'),
                                            language,
                                            identity_subclasses=id_subclasses)

        if meta_info_data is None:
            continue

        keys = clazz.get_key_props()
        attribute_title = prop.name
        if language == 'go':
            attribute_title = prop.go_name()
        if prop in keys:
            attribute_title = '%s  <key>' % attribute_title
        properties_description.append('.. attribute:: %s\n\n' %
                                      (attribute_title))

        properties_description.append(
            '\t%s\n' % (convert_to_reStructuredText(prop_comment)))

        properties_description.extend(get_type_doc(meta_info_data, 1, ''))
        if len(meta_info_data.target_of_leafref) > 0:
            properties_description.append('\t**refers to**\: %s\n\n' %
                                          (meta_info_data.target_of_leafref))
        if meta_info_data.mandatory:
            properties_description.append('\t**mandatory**\: True\n\n')
        if meta_info_data.is_presence:
            properties_description.append('\t**presence node**\: True\n\n')
        if len(meta_info_data.units) > 0:
            properties_description.append('\t**units**\: %s\n\n' %
                                          meta_info_data.units)
        if len(meta_info_data.default_value) > 0:
            properties_description.append('\t**default value**\: %s\n\n' %
                                          meta_info_data.default_value)
        if len(meta_info_data.status) > 0:
            properties_description.append('\t**status**\: %s\n\n' %
                                          meta_info_data.status)

    return convert_to_reStructuredText(class_description) + '\n\n' + ''.join(
        properties_description)