Ejemplo n.º 1
0
 def print_deviation_entry(self, deviation):
     target = deviation.d_target
     stmts = deviation.d_stmts
     typ = deviation.d_type
     qn = deviation.qn()
     self.ctx.lvl_inc()
     self.ctx.writeln("'%s' : {" % qn)
     self.ctx.lvl_inc()
     self.ctx.writeln("'deviation_typ' : '%s'," % typ)
     if typ != 'not_supported':
         self.ctx.writeln("'keyword_value' : [")
         self.ctx.lvl_inc()
         for stmt in stmts:
             key = stmt.keyword
             self.ctx.write("(%s, " % self.convert_key_val(key))
             if key == 'type':
                 prop = target.i_property
                 meta = get_meta_info_data(prop, prop.property_type,
                                           prop.stmt.search_one('type'))
                 self.ctx.bline()
                 self.ctx.lvl_inc()
                 self.parent.print_meta_class_member(meta, self.ctx)
                 self.ctx.lvl_dec()
                 self.ctx.writeln("),")
             else:
                 val = self.convert_key_val(stmt.arg)
                 self.ctx.str("%s),\n" % val)
         self.ctx.lvl_dec()
         self.ctx.writeln("]")
     self.ctx.lvl_dec()
     self.ctx.writeln("},")
     self.ctx.lvl_dec()
Ejemplo n.º 2
0
 def print_deviation_entry(self, deviation):
     target = deviation.d_target
     stmts = deviation.d_stmts
     typ = deviation.d_type
     qn = deviation.qn()
     self.ctx.lvl_inc()
     self.ctx.writeln("'%s' : {" % qn)
     self.ctx.lvl_inc()
     self.ctx.writeln("'deviation_typ' : '%s'," % typ)
     if typ != 'not_supported':
         self.ctx.writeln("'keyword_value' : [")
         self.ctx.lvl_inc()
         for stmt in stmts:
             key = stmt.keyword
             self.ctx.write("(%s, " %self.convert_key_val(key))
             if key == 'type':
                 prop = target.i_property
                 meta = get_meta_info_data(prop, prop.property_type, prop.stmt.search_one('type'))
                 self.ctx.bline()
                 self.ctx.lvl_inc()
                 ClassMetaPrinter(self.ctx).print_meta_class_member(meta, self.ctx)
                 self.ctx.lvl_dec()
                 self.ctx.writeln("),")
             else:
                 val = self.convert_key_val(stmt.arg)
                 self.ctx.str("%s),\n" % val)
         self.ctx.lvl_dec()
         self.ctx.writeln("]")
     self.ctx.lvl_dec()
     self.ctx.writeln("},")
     self.ctx.lvl_dec()
Ejemplo n.º 3
0
    def _print_meta_member(self, clazz):
        self.ctx.writeln('\'%s\' : {' % (clazz.qn()))
        self.ctx.lvl_inc()
        self.ctx.writeln("'meta_info' : _MetaInfoClass('%s'," % clazz.qn())
        self.ctx.lvl_inc()
        description = " "
        for st in clazz.stmt.substmts:
            if st.keyword == 'description':
                description = st.arg
                break
        self.ctx.writeln("'''%s'''," % description)
        if clazz.is_grouping():
            self.ctx.writeln('True, ')
        else:
            self.ctx.writeln('False, ')
        self.ctx.writeln('[')

        prop_list = []
        if self.is_rpc:
            prop_list = [p for p in clazz.owned_elements if isinstance(p, Property)]
        else:
            prop_list = clazz.properties()

        for prop in prop_list:
            meta_info_data = get_meta_info_data(
                prop, prop.property_type, prop.stmt.search_one('type'), 'py', self.one_class_per_module,
                self.identity_subclasses)
            self.print_meta_class_member(meta_info_data, self.ctx)

        '''
        class _MetaInfoClass(object):

    def __init__(
            self,
            name,
            is_abstract,
            meta_info_class_members,
            module_name,
            yang_name,
            namespace,
            pmodule_name):
        '''
        self.ctx.writeln('],'),
        module_name = "%s" % get_module_name(clazz.stmt)
        self.ctx.writeln("'%s'," % module_name)
        self.ctx.writeln("'%s'," % clazz.stmt.arg)
        if clazz.is_grouping():
            self.ctx.writeln('None,')
        else:
            self.ctx.writeln("_yang_ns._namespaces['%s']," % module_name)
        self.ctx.lvl_dec()
        self.ctx.writeln("'%s'" % clazz.get_py_mod_name(self.one_class_per_module))
        self.ctx.writeln('),')

        self.ctx.lvl_dec()
        self.ctx.writeln('},')
Ejemplo n.º 4
0
    def _get_meta_info_data(self, prop):
        property_type = prop.property_type
        type_stmt = prop.stmt.search_one('type')

        id_subclasses = None
        if (hasattr(property_type, 'is_identity')
                and property_type.is_identity()):
            id_subclasses = self.identity_subclasses

        meta_info_data = get_meta_info_data(prop,
                                            property_type,
                                            type_stmt,
                                            'go',
                                            identity_subclasses=id_subclasses)

        if type(prop.property_type) in (Class, Enum, Bits):
            meta_info_data.clazz_name = "'%s'" % property_type.qualified_go_name(
            )

        if isinstance(prop.property_type, Class):
            if id_subclasses is None:
                meta_info_data.doc_link = prop.qualified_go_name()
            else:
                meta_info_data.doc_link = self._get_many_docstring(
                    id_subclasses, property_type)
                meta_info_data.doc_link_description = 'one of the following: '
            if prop.is_many:
                meta_info_data.doc_link = 'slice of %s' % meta_info_data.doc_link
        else:
            meta_info_data.doc_link = get_type_name(property_type)
            if prop.stmt.keyword == 'leaf-list':
                meta_info_data.doc_link = 'slice of %s' % get_type_name(
                    property_type)
            elif prop.stmt.keyword == 'anyxml':
                return meta_info_data

            type_spec = type_stmt.i_type_spec
            if isinstance(type_spec, PathTypeSpec):
                if prop.stmt.i_leafref_ptr is not None:
                    ref_class = prop.stmt.i_leafref_ptr[0].parent.i_class
                    ref_prop = prop.stmt.i_leafref_ptr[0].i_property
                    ref_path = '%s.%s' % (ref_class.get_package().name,
                                          ref_prop.qualified_go_name())
                    meta_info_data.target_of_leafref = ref_path
            elif isinstance(type_spec, UnionTypeSpec):
                pairs = zip(meta_info_data.children, type_spec.types)
                for child, ptype in pairs:
                    if child.mtype == 'REFERENCE_ENUM_CLASS':
                        child.doc_link = 'enumeration %s' % (child.ptype)
        return meta_info_data
Ejemplo n.º 5
0
    def _print_meta_member(self, clazz):
        self.ctx.writeln('\'%s\' : {' % (clazz.qn()))
        self.ctx.lvl_inc()
        self.ctx.writeln("'meta_info' : _MetaInfoClass('%s'," % clazz.qn())
        self.ctx.lvl_inc()
        if clazz.is_grouping():
            self.ctx.writeln('True, ')
        else:
            self.ctx.writeln('False, ')
        self.ctx.writeln('[')

        prop_list = []
        if self.is_rpc:
            prop_list = [p for p in clazz.owned_elements if isinstance(p, Property)]
        else:
            prop_list = clazz.properties()

        for prop in prop_list:
            meta_info_data = get_meta_info_data(
                prop, prop.property_type, prop.stmt.search_one('type'))
            self.print_meta_class_member(meta_info_data, self.ctx)

        '''
        class _MetaInfoClass(object):

    def __init__(
            self,
            name,
            is_abstract,
            meta_info_class_members,
            module_name,
            yang_name,
            namespace,
            pmodule_name):
        '''
        self.ctx.writeln('],'),
        module_name = "%s" % get_module_name(clazz.stmt)
        self.ctx.writeln("'%s'," % module_name)
        self.ctx.writeln("'%s'," % clazz.stmt.arg)
        if clazz.is_grouping_contribution():
            self.ctx.writeln('None,')
        else:
            self.ctx.writeln("_yang_ns._namespaces['%s']," % module_name)
        self.ctx.lvl_dec()
        self.ctx.writeln("'%s'" % clazz.get_py_mod_name())
        self.ctx.writeln('),')

        self.ctx.lvl_dec()
        self.ctx.writeln('},')
Ejemplo n.º 6
0
def get_ptype(prop, property_type, type_stmt, one_class_per_module, identity_subclasses):
    meta_info_data = get_meta_info_data(prop, property_type, type_stmt, 'py', identity_subclasses)
    if meta_info_data.pmodule_name is None:
        return "'%s'" % meta_info_data.ptype

    pmodule_name = meta_info_data.pmodule_name
    clazz = meta_info_data.clazz_name.replace("'", '')
    if one_class_per_module:
        pmodule_name = get_pmodule_name_for_one_class_per_module(pmodule_name, property_type)
    if meta_info_data.mtype == 'REFERENCE_BITS' or isinstance(property_type, Bits):
        ptype = "'Bits'"
    elif meta_info_data.mtype == 'REFERENCE_ENUM_CLASS' or isinstance(property_type, Enum):
        ptype = get_enum_ptype(pmodule_name, clazz)
    else:
        ptype = "(%s, %s)" % (pmodule_name, meta_info_data.clazz_name)
    return ptype
Ejemplo n.º 7
0
    def _print_meta_member(self, clazz):
        self.ctx.writeln('\'%s\' : {' % (clazz.qn()))
        self.ctx.lvl_inc()
        self.ctx.writeln("'meta_info' : _MetaInfoClass('%s'," % clazz.qn())
        self.ctx.lvl_inc()
        description = " "
        for st in clazz.stmt.substmts:
            if st.keyword == 'description':
                description = st.arg
                break
        self.ctx.writeln("'''%s'''," % description)
        if clazz.is_grouping():
            self.ctx.writeln('True, ')
        else:
            self.ctx.writeln('False, ')
        self.ctx.writeln('[')

        prop_list = []
        if self.is_rpc:
            prop_list = [p for p in clazz.owned_elements if isinstance(p, Property)]
        else:
            prop_list = clazz.properties()

        for prop in prop_list:
            meta_info_data = get_meta_info_data(
                prop, prop.property_type, prop.stmt.search_one('type'), 'py',
                self.identity_subclasses)
            self.print_meta_class_member(meta_info_data, self.ctx)

        self.ctx.writeln('],')
        module_name = "%s" % get_module_name(clazz.stmt)
        self.ctx.writeln("'%s'," % module_name)
        self.ctx.writeln("'%s'," % clazz.stmt.arg)
        if clazz.is_grouping():
            self.ctx.writeln('None,')
        else:
            self.ctx.writeln("_yang_ns.NAMESPACE_LOOKUP['%s']," % module_name)
        self.ctx.lvl_dec()
        self.ctx.writeln("'%s'" % clazz.get_py_mod_name())
        self.ctx.writeln('),')

        self.ctx.lvl_dec()
        self.ctx.writeln('},')
Ejemplo n.º 8
0
    def _get_meta_info_data(self, prop):
        property_type = prop.property_type
        type_stmt = prop.stmt.search_one('type')

        id_subclasses = None
        if (hasattr(property_type, 'is_identity') and property_type.is_identity()):
            id_subclasses = self.identity_subclasses

        meta_info_data = get_meta_info_data(
            prop, property_type, type_stmt, 'go', identity_subclasses=id_subclasses)

        if type(prop.property_type) in (Class, Enum, Bits):
            meta_info_data.clazz_name = "'%s'" % property_type.qualified_go_name()

        if isinstance(prop.property_type, Class):
            if id_subclasses is None:
                meta_info_data.doc_link = prop.qualified_go_name()
            else:
                meta_info_data.doc_link = self._get_many_docstring(id_subclasses, property_type)
                meta_info_data.doc_link_description = 'one of the following: '
            if prop.is_many:
                meta_info_data.doc_link = 'slice of %s' % meta_info_data.doc_link
        else:
            meta_info_data.doc_link = get_type_name(property_type)
            if prop.stmt.keyword == 'leaf-list':
                meta_info_data.doc_link = 'slice of %s' % get_type_name(property_type)
            elif prop.stmt.keyword == 'anyxml':
                return meta_info_data

            type_spec = type_stmt.i_type_spec
            if isinstance(type_spec, PathTypeSpec):
                if prop.stmt.i_leafref_ptr is not None:
                    ref_class = prop.stmt.i_leafref_ptr[0].parent.i_class
                    ref_prop = prop.stmt.i_leafref_ptr[0].i_property
                    ref_path = '%s.%s' % (ref_class.get_package().name, ref_prop.qualified_go_name())
                    meta_info_data.target_of_leafref = ref_path
            elif isinstance(type_spec, UnionTypeSpec):
                pairs = zip(meta_info_data.children, type_spec.types)
                for child, ptype in pairs:
                    if child.mtype == 'REFERENCE_ENUM_CLASS':
                        child.doc_link = 'enumeration %s' % (child.ptype)
        return meta_info_data
Ejemplo n.º 9
0
def get_ptype(prop, property_type, type_stmt, one_class_per_module,
              identity_subclasses):
    meta_info_data = get_meta_info_data(prop, property_type, type_stmt, 'py',
                                        identity_subclasses)
    if meta_info_data.pmodule_name is None:
        return "'%s'" % meta_info_data.ptype

    pmodule_name = meta_info_data.pmodule_name
    clazz = meta_info_data.clazz_name.replace("'", '')
    if one_class_per_module:
        pmodule_name = get_pmodule_name_for_one_class_per_module(
            pmodule_name, property_type)
    if meta_info_data.mtype == 'REFERENCE_BITS' or isinstance(
            property_type, Bits):
        ptype = "'Bits'"
    elif meta_info_data.mtype == 'REFERENCE_ENUM_CLASS' or isinstance(
            property_type, Enum):
        ptype = get_enum_ptype(pmodule_name, clazz)
    else:
        ptype = "(%s, %s)" % (pmodule_name, meta_info_data.clazz_name)
    return ptype
Ejemplo n.º 10
0
    def _print_meta_member(self, clazz):
        mtype = 'REFERENCE_CLASS'
        if clazz.stmt.keyword == 'list':
            mtype = 'REFERENCE_LIST'
        elif clazz.stmt.keyword == 'leaf-list':
            mtype = 'REFERENCE_LEAFLIST'
        elif clazz.stmt.keyword == 'identity':
            mtype = 'REFERENCE_IDENTITY_CLASS'
        self.ctx.writeln('\'%s\' : {' % (clazz.qn()))
        self.ctx.lvl_inc()
        self.ctx.writeln("'meta_info' : _MetaInfoClass('%s', %s," %
                         (clazz.qn(), mtype))
        self.ctx.lvl_inc()
        description = " "
        for st in clazz.stmt.substmts:
            if st.keyword == 'description':
                description = st.arg
                break
        self.ctx.writeln("'''%s'''," % description)
        if clazz.is_grouping():
            self.ctx.writeln('True, ')
        else:
            self.ctx.writeln('False, ')
        self.ctx.writeln('[')

        if self.is_rpc:
            prop_list = [
                p for p in clazz.owned_elements if isinstance(p, Property)
            ]
        else:
            prop_list = clazz.properties()

        for prop in prop_list:
            meta_info_data = get_meta_info_data(prop, prop.property_type,
                                                prop.stmt.search_one('type'),
                                                'py', self.identity_subclasses)
            self.print_meta_class_member(meta_info_data, self.ctx)

        self.ctx.writeln('],')
        module_name = "%s" % get_module_name(clazz.stmt)
        self.ctx.writeln("'%s'," % module_name)
        self.ctx.writeln("'%s'," % clazz.stmt.arg)
        if clazz.is_grouping():
            self.ctx.writeln('None,')
        else:
            self.ctx.writeln("_yang_ns.NAMESPACE_LOOKUP['%s']," % module_name)
        self.ctx.writeln("'%s'," % clazz.get_py_mod_name())
        if mtype == 'REFERENCE_CLASS' or mtype == 'REFERENCE_LIST':
            if not is_config_stmt(clazz.stmt):
                self.ctx.writeln("is_config=False,")
            if clazz.stmt.search_one('presence'):
                self.ctx.writeln("is_presence=True,")
            if clazz.stmt.search_one('mandatory'):
                self.ctx.writeln("has_mandatory=True,")
            if clazz.stmt.search_one('when'):
                self.ctx.writeln("has_when=True,")
            if clazz.stmt.search_one('must'):
                self.ctx.writeln("has_must=True,")
        self.ctx.lvl_dec()
        self.ctx.writeln('),')

        self.ctx.lvl_dec()
        self.ctx.writeln('},')