コード例 #1
0
    def _print_identity_lookup(self, packages):
        packages = sorted(packages, key=lambda p: p.name)

        self.ctx.writeln('IDENTITY_LOOKUP = {')
        self.ctx.lvl_inc()
        for package in packages:
            identities = [
                idx for idx in package.owned_elements
                if isinstance(idx, Class) and idx.is_identity()
            ]
            identities = sorted(identities, key=lambda c: c.name)
            for identity_clazz in identities:
                if self.one_class_per_module:
                    pkg_name = identity_clazz.get_package().name
                    self.ctx.writeln("'%s:%s':('%s.%s', '%s')," %
                                     (get_module_name(identity_clazz.stmt),
                                      identity_clazz.stmt.arg,
                                      identity_clazz.get_py_mod_name(),
                                      pkg_name, identity_clazz.qn()))
                else:
                    self.ctx.writeln("'%s:%s':('%s', '%s')," %
                                     (get_module_name(identity_clazz.stmt),
                                      identity_clazz.stmt.arg,
                                      identity_clazz.get_py_mod_name(),
                                      identity_clazz.qn()))
        self.ctx.lvl_dec()
        self.ctx.writeln('}')
        self.ctx.bline()
コード例 #2
0
ファイル: enum_printer.py プロジェクト: shgandhi/ydk-gen
 def print_enum_meta(self, enum_class):
     self.ctx.writeln(
         "'%s' : _MetaInfoEnum('%s', '%s'," %
         (enum_class.qn(), enum_class.name, enum_class.get_py_mod_name()))
     self.ctx.lvl_inc()
     self.ctx.writeln("{")
     self.ctx.lvl_inc()
     for literal in enum_class.literals:
         self.ctx.writeln("'%s':'%s'," % (literal.stmt.arg, literal.name))
     self.ctx.lvl_dec()
     self.ctx.writeln(
         "}, '%s', _yang_ns._namespaces['%s'])," % (get_module_name(
             enum_class.stmt), get_module_name(enum_class.stmt)))
     self.ctx.lvl_dec()
コード例 #3
0
    def _print_common_path_functions_body(self, clazz):
        owners = []
        owner_key_props = []
        current_owner = clazz.owner
        while current_owner != None and isinstance(current_owner, Class):
            owners.append(current_owner)
            owner_key_props.extend(current_owner.get_key_props())
            current_owner = current_owner.owner

        common_path = ''
        if len(owners) == 0 or len(owner_key_props) == 0:
            segments = ''
            for owner in reversed(owners):
                segments = "%s/%s:%s" % (segments,
                                         owner.module.arg, owner.stmt.arg)
            common_path = "return '%s" % segments
        else:
            self._print_common_path_validation_error(
                'parent', 'parent is not set . Cannot derive path.')
            common_path = "return self.parent._common_path +'"

        common_path = "%s/%s:%s" % (common_path,
                                    clazz.module.arg, clazz.stmt.arg)
        predicates = ''
        key_props = clazz.get_key_props()
        for key_prop in key_props:
            self._print_common_path_validation_error(
                key_prop.name, 'Key property {0} is None'.format(key_prop.name))
            predicates = "%s[%s:%s = ' + str(self.%s) + ']" % (predicates, get_module_name(key_prop.stmt),
                                                               key_prop.stmt.arg, key_prop.name)
        common_path = "%s%s'" % (common_path, predicates)

        self.ctx.bline()
        self.ctx.writeln(common_path)
コード例 #4
0
 def _print_class_inits_body(self, clazz, leafs, children):
     if clazz.is_identity():
         module_name = get_module_name(clazz.stmt)
         namespace = self.module_namespace_lookup[module_name]
         line = 'super(%s, self).__init__("%s", "%s", "%s:%s")' % (clazz.name, namespace, module_name, module_name, clazz.stmt.arg)
         self.ctx.writeln(line)
     else:
         if self.one_class_per_module:
             self.ctx.writeln('super(%s, self).__init__()' % clazz.name)
         else:
             self.ctx.writeln('super(%s, self).__init__()' % clazz.qn())
         if clazz.owner is not None and isinstance(clazz.owner, Package):
             self.ctx.writeln('self._top_entity = None')
         self.ctx.bline()
         if self.one_class_per_module:
             self._print_children_imports(clazz, children)
         self.ctx.writeln('self.yang_name = "%s"' % clazz.stmt.arg)
         self.ctx.writeln('self.yang_parent_name = "%s"' % clazz.owner.stmt.arg)
         self.ctx.writeln('self.is_top_level_class = %s' % ('True' if is_top_level_class(clazz) else 'False'))
         self.ctx.writeln('self.has_list_ancestor = %s' % ('True' if has_list_ancestor(clazz) else 'False'))
         self.ctx.writeln(
             'self.ylist_key_names = [%s]' % (','.join(["'%s'" % key.name for key in clazz.get_key_props()])))
         self.ctx.writeln('self._child_container_classes = OrderedDict([%s])' % (get_child_container_classes(clazz, self.one_class_per_module)))
         self.ctx.writeln('self._child_list_classes = OrderedDict([%s])' % (get_child_list_classes(clazz, self.one_class_per_module)))
         if clazz.stmt.search_one('presence') is not None:
             self.ctx.writeln('self.is_presence_container = True')
         self._print_init_leafs_and_leaflists(clazz, leafs)
         self._print_init_children(children)
         self._print_init_lists(clazz)
         self._print_class_segment_path(clazz)
         self._print_class_absolute_path(clazz, leafs)
コード例 #5
0
 def __init__(self, prop):
     self.name = prop.stmt.arg
     self.mtype = ''
     self.ptype = ''
     self.ytype = ''
     self.prange = []
     self.pattern = []
     self.presentation_name = "%s" % prop.name
     self.module_name = "%s" % get_module_name(prop.stmt)
     self.pmodule_name = None
     self.clazz_name = None
     self.is_many = prop.is_many
     self.doc_link = None
     self.doc_link_description = ''
     self.children = []
     self.comment = prop.comment
     self.is_key = prop.is_key()
     self.max_elements = prop.max_elements
     self.min_elements = prop.min_elements
     self.target_of_leafref = ''
     self.mandatory = False
     self.is_presence = False
     self.units = ''
     self.default_value = ''
     self.default_value_object = None
     self.is_config = is_config_stmt(prop.stmt)
     self.status = ''
コード例 #6
0
ファイル: meta_data_util.py プロジェクト: 111pontes/ydk-gen
 def __init__(self, prop):
     self.name = prop.stmt.arg
     self.mtype = ''
     self.ptype = ''
     self.ytype = ''
     self.prange = []
     self.pattern = []
     self.presentation_name = "%s" % prop.name
     self.module_name = "%s" % get_module_name(prop.stmt)
     self.pmodule_name = None
     self.clazz_name = None
     self.is_many = prop.is_many
     self.doc_link = None
     self.doc_link_description = ''
     self.children = []
     self.comment = prop.comment
     self.is_key = prop.is_key()
     self.max_elements = prop.max_elements
     self.min_elements = prop.min_elements
     self.target_of_leafref = ''
     self.mandatory = False
     self.is_presence = False
     self.units = ''
     self.default_value = ''
     self.default_value_object = None
     self.is_config = is_config_stmt(prop.stmt)
     self.status = ''
コード例 #7
0
    def _print_common_path_functions_body(self, clazz):
        owners = []
        owner_key_props = []
        current_owner = clazz.owner
        while current_owner != None and isinstance(current_owner, Class):
            owners.append(current_owner)
            owner_key_props.extend(current_owner.get_key_props())
            current_owner = current_owner.owner

        common_path = ''
        if len(owners) == 0 or len(owner_key_props) == 0:
            segments = ''
            for owner in reversed(owners):
                segments = "%s/%s:%s" % (segments,
                                         owner.module.arg, owner.stmt.arg)
            common_path = "return '%s" % segments
        else:
            self._print_common_path_validation_error(
                'parent', 'parent is not set . Cannot derive path.')
            common_path = "return self.parent._common_path +'"

        common_path = "%s/%s:%s" % (common_path,
                                    clazz.module.arg, clazz.stmt.arg)
        predicates = ''
        key_props = clazz.get_key_props()
        for key_prop in key_props:
            self._print_common_path_validation_error(
                key_prop.name, 'Key property {0} is None'.format(key_prop.name))
            predicates = "%s[%s:%s = ' + str(self.%s) + ']" % (predicates, get_module_name(key_prop.stmt),
                                                               key_prop.stmt.arg, key_prop.name)
        common_path = "%s%s'" % (common_path, predicates)

        self.ctx.bline()
        self.ctx.writeln(common_path)
コード例 #8
0
 def _print_class_inits_header(self, clazz):
     if clazz.is_identity():
         module_name = get_module_name(clazz.stmt)
         namespace = self.module_namespace_lookup[module_name]
         self.ctx.writeln('def __init__(self, ns="%s", pref="%s", tag="%s:%s"):' % (
                         namespace, module_name, module_name, clazz.stmt.arg))
     else:
         self.ctx.writeln('def __init__(self):')
     self.ctx.lvl_inc()
コード例 #9
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('},')
コード例 #10
0
 def _print_class_inits_header(self, clazz):
     if clazz.is_identity():
         module_name = get_module_name(clazz.stmt)
         namespace = self.module_namespace_lookup[module_name]
         self.ctx.writeln(
             'def __init__(self, ns="%s", pref="%s", tag="%s:%s"):' %
             (namespace, module_name, module_name, clazz.stmt.arg))
     else:
         self.ctx.writeln('def __init__(self):')
     self.ctx.lvl_inc()
コード例 #11
0
 def _get_module_namespace_lookup(self, packages):
     module_namespace_lookup = {}
     for p in packages:
         module_name = get_module_name(p.stmt)
         if module_name is None:
             continue
         ns = p.stmt.search_one('namespace')
         assert ns is not None, '%s has no namespace!!' % module_name
         namespace = ns.arg
         module_namespace_lookup[module_name] = namespace
     return module_namespace_lookup
コード例 #12
0
 def print_enum_meta(self, enum_class):
     self.ctx.writeln("'%s' : _MetaInfoEnum('%s', '%s', '%s'," %
                      (enum_class.qn(), enum_class.name,
                       enum_class.get_py_mod_name(), enum_class.qn()))
     self.ctx.lvl_inc()
     description = " "
     for st in enum_class.stmt.parent.substmts:
         if st.keyword == 'description':
             description = st.arg
             break
     self.ctx.writeln("'''%s'''," % description)
     self.ctx.writeln("{")
     self.ctx.lvl_inc()
     for literal in enum_class.literals:
         self.ctx.writeln("'%s':'%s'," % (literal.stmt.arg, literal.name))
     self.ctx.lvl_dec()
     self.ctx.writeln(
         "}, '%s', _yang_ns._namespaces['%s'])," % (get_module_name(
             enum_class.stmt), get_module_name(enum_class.stmt)))
     self.ctx.lvl_dec()
コード例 #13
0
 def _get_module_namespace_lookup(self, packages):
     module_namespace_lookup = {}
     for p in packages:
         module_name = get_module_name(p.stmt)
         if module_name is None:
             continue
         ns = p.stmt.search_one('namespace')
         assert ns is not None, '%s has no namespace!!' % module_name
         namespace = ns.arg
         module_namespace_lookup[module_name] = namespace
     return module_namespace_lookup
コード例 #14
0
 def _print_class_constructor_header(self, clazz, leafs, children):
     self.ctx.writeln(clazz.qualified_cpp_name() + '::' + clazz.name + '()')
     self.ctx.lvl_inc()
     if clazz.is_identity():
         module_name = get_module_name(clazz.stmt)
         namespace = self.module_namespace_lookup[module_name]
         self.ctx.writeln(' : Identity("%s", "%s", "%s:%s")' % (namespace, module_name, module_name, clazz.stmt.arg))
     else:
         self._print_class_inits(clazz, leafs, children)
     self.ctx.lvl_dec()
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
コード例 #15
0
 def _print_class_constructor_header(self, clazz, leafs, children):
     self.ctx.writeln(clazz.qualified_cpp_name() + '::' + clazz.name + '()')
     self.ctx.lvl_inc()
     if clazz.is_identity():
         module_name = get_module_name(clazz.stmt)
         namespace = self.module_namespace_lookup[module_name]
         self.ctx.writeln(' : Identity("%s", "%s", "%s:%s")' % (namespace, module_name, module_name, clazz.stmt.arg))
     else:
         self._print_class_inits(clazz, leafs, children)
     self.ctx.lvl_dec()
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
コード例 #16
0
    def _print_identity_lookup(self, packages):
        packages = sorted(packages, key=lambda p:p.name)

        self.ctx.writeln('IDENTITY_LOOKUP = {')
        self.ctx.lvl_inc()
        for package in packages:
            identities = [idx for idx in package.owned_elements if isinstance(
                idx, Class) and idx.is_identity()]
            identities = sorted(identities, key=lambda c: c.name)
            for identity_clazz in identities:
                if self.one_class_per_module:
                    pkg_name = identity_clazz.get_package().name
                    self.ctx.writeln(
                        "'%s:%s':('%s.%s', '%s')," % (get_module_name(identity_clazz.stmt), identity_clazz.stmt.arg,
                                                   identity_clazz.get_py_mod_name(), pkg_name, identity_clazz.qn()))
                else:
                    self.ctx.writeln(
                        "'%s:%s':('%s', '%s')," % (get_module_name(identity_clazz.stmt), identity_clazz.stmt.arg,
                                                   identity_clazz.get_py_mod_name(), identity_clazz.qn()))
        self.ctx.lvl_dec()
        self.ctx.writeln('}')
        self.ctx.bline()
コード例 #17
0
ファイル: enum_printer.py プロジェクト: waffle-iron/ydk-gen
 def print_enum_meta(self, enum_class):
     self.ctx.writeln("'%s' : _MetaInfoEnum('%s', '%s'," % (
                      enum_class.qn(),
                      enum_class.name,
                      enum_class.get_py_mod_name()))
     self.ctx.lvl_inc()
     self.ctx.writeln("{")
     self.ctx.lvl_inc()
     for literal in enum_class.literals:
         self.ctx.writeln("'%s':'%s'," % (literal.stmt.arg, literal.name))
     self.ctx.lvl_dec()
     self.ctx.writeln("}, '%s', _yang_ns._namespaces['%s'])," % (get_module_name(enum_class.stmt), get_module_name(enum_class.stmt)))
     self.ctx.lvl_dec()
コード例 #18
0
 def print_identity_map(self, packages):
     self.ctx.writeln("_identity_map = { \\")
     self.ctx.lvl_inc()
     for package in packages:
         identities = [idx for idx in package.owned_elements if isinstance(
             idx, Class) and idx.is_identity()]
         identities = sorted(identities, key=lambda c: c.name)
         for identity_clazz in identities:
             self.ctx.writeln("('%s', '%s'):('%s', '%s')," % (get_module_name(identity_clazz.stmt), identity_clazz.stmt.arg,
                                                              identity_clazz.get_py_mod_name(), identity_clazz.qn()))
     self.ctx.lvl_dec()
     self.ctx.writeln("}")
     self.ctx.bline()
コード例 #19
0
 def _print_identity_map(self, packages):
     packages = sorted(packages, key=lambda p:p.name)
     self.ctx.writeln("_identity_map = { \\")
     self.ctx.lvl_inc()
     for package in packages:
         identities = [idx for idx in package.owned_elements if isinstance(
             idx, Class) and idx.is_identity()]
         identities = sorted(identities, key=lambda c: c.name)
         for identity_clazz in identities:
             self.ctx.writeln("('%s', '%s'):('%s', '%s')," % (get_module_name(identity_clazz.stmt), identity_clazz.stmt.arg,
                                                              identity_clazz.get_py_mod_name(self.one_class_per_module), identity_clazz.qn()))
     self.ctx.lvl_dec()
     self.ctx.writeln("}")
     self.ctx.bline()
コード例 #20
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('},')
コード例 #21
0
ファイル: meta_data_util.py プロジェクト: togis123/ydk-gen
 def __init__(self, prop):
     self.name = prop.stmt.arg
     self.mtype = ''
     self.ptype = ''
     self.prange = []
     self.pattern = []
     self.presentation_name = "%s" % prop.name
     self.module_name = "%s" % get_module_name(prop.stmt)
     self.pmodule_name = None
     self.clazz_name = None
     self.is_many = prop.is_many
     self.doc_link = None
     self.children = []
     self.comment = prop.comment
     self.is_key = prop.is_key()
     self.max_elements = prop.max_elements
     self.min_elements = prop.min_elements
コード例 #22
0
 def __init__(self, prop):
     self.name = prop.stmt.arg
     self.mtype = ''
     self.ptype = ''
     self.prange = []
     self.pattern = []
     self.presentation_name = "%s" % prop.name
     self.module_name = "%s" % get_module_name(prop.stmt)
     self.pmodule_name = None
     self.clazz_name = None
     self.is_many = prop.is_many
     self.doc_link = None
     self.children = []
     self.comment = prop.comment
     self.is_key = prop.is_key()
     self.max_elements = prop.max_elements
     self.min_elements = prop.min_elements
コード例 #23
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('},')
コード例 #24
0
ファイル: enum_printer.py プロジェクト: 111pontes/ydk-gen
 def print_enum_meta(self, enum_class):
     self.ctx.writeln("'%s' : _MetaInfoEnum('%s', '%s', '%s'," % (
                      enum_class.qn(),
                      enum_class.name,
                      enum_class.get_py_mod_name(),
                      enum_class.qn()))
     self.ctx.lvl_inc()
     description = " "
     for st in enum_class.stmt.parent.substmts:
         if st.keyword == 'description':
             description = st.arg
             break
     self.ctx.writeln("'''%s'''," % description)
     self.ctx.writeln("{")
     self.ctx.lvl_inc()
     for literal in enum_class.literals:
         self.ctx.writeln("'%s':'%s'," % (literal.stmt.arg, literal.name))
     self.ctx.lvl_dec()
     self.ctx.writeln("}, '%s', _yang_ns.NAMESPACE_LOOKUP['%s'])," % (get_module_name(enum_class.stmt), get_module_name(enum_class.stmt)))
     self.ctx.lvl_dec()
コード例 #25
0
 def _print_class_inits_body(self, clazz, leafs, children):
     if clazz.is_identity():
         module_name = get_module_name(clazz.stmt)
         namespace = self.module_namespace_lookup[module_name]
         line = 'super(%s, self).__init__("%s", "%s", "%s:%s")' % (
             clazz.name, namespace, module_name, module_name,
             clazz.stmt.arg)
         self.ctx.writeln(line)
     else:
         self.ctx.writeln('super(%s, self).__init__()' % clazz.qn())
         if clazz.owner is not None and isinstance(clazz.owner, Package):
             self.ctx.writeln('self._top_entity = None')
         self.ctx.bline()
         self.ctx.writeln('self.yang_name = "%s"' % clazz.stmt.arg)
         self.ctx.writeln('self.yang_parent_name = "%s"' %
                          clazz.owner.stmt.arg)
         if clazz.stmt.search_one('presence') is not None:
             self.ctx.writeln('self.is_presence_container = True')
         self._print_init_leafs_and_leaflists(clazz, leafs)
         self._print_init_children(children)
     self._print_init_lists(clazz)
コード例 #26
0
 def _print_namespace_identity_lookup_statement(self, identity):
     module_name = get_module_name(identity.stmt)
     namespace = self.module_namespace_lookup[module_name]
     self.ctx.writeln('{ {"%s", "%s"},  "%s"},' %
                      (identity.stmt.arg, namespace, module_name))
コード例 #27
0
ファイル: class_meta_printer.py プロジェクト: xulleon/ydk-gen
    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('},')
コード例 #28
0
 def _print_namespace_identity_lookup_statement(self, identity):
     module_name = get_module_name(identity.stmt)
     namespace = self.module_namespace_lookup[module_name]
     self.ctx.writeln('{ {"%s", "%s"},  "%s"},' % (identity.stmt.arg, namespace, module_name))