Example #1
0
    def stmt(self, stmt):
        name = escape_name(stmt.arg)
        if stmt.keyword == 'grouping':
            name = '%s_Grouping' % camel_case(name)
        elif stmt.keyword == 'identity':
            name = '%s_Identity' % camel_case(name)
        elif stmt.keyword == 'rpc':
            name = camel_case(name) + 'Rpc'
        else:
            name = camel_case(name)
        if iskeyword(name):
            name = '%s_' % name
        self.name = name

        if self.name.startswith('_'):
            self.name = '%s%s' % ('Y', name)

        self._stmt = stmt
        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg

        if stmt.keyword == 'module':
            self._module = stmt
        else:
            self._module = stmt.i_module
Example #2
0
    def stmt(self, stmt):
        self._stmt = stmt
        # the name of the numeration is derived either from the typedef
        # or the leaf under which it is defined
        leaf_or_typedef = stmt
        while leaf_or_typedef.parent is not None and not leaf_or_typedef.keyword in ('leaf', 'leaf-list', 'typedef'):
            leaf_or_typedef = leaf_or_typedef.parent

        name = '%s_Enum' % camel_case(escape_name(leaf_or_typedef.arg))
        if iskeyword(name):
            name = '%s_' % name

        if name[0] == '_':
            name = 'Y%s' % name

        self.name = name

        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg
        else:
            desc = leaf_or_typedef.search_one('description')
            if desc is not None:
                self.comment = desc.arg
        for enum_stmt in stmt.search('enum'):
            literal = EnumLiteral()
            literal.stmt = enum_stmt
            self.literals.append(literal)
Example #3
0
    def stmt(self, stmt):
        self._stmt = stmt
        self._dictionary = {}
        self._pos_map = {}
        # the name of the enumeration is derived either from the typedef
        # or the leaf under which it is defined
        leaf_or_typedef = stmt
        while leaf_or_typedef.parent is not None and not leaf_or_typedef.keyword in ('leaf', 'leaf-list', 'typedef'):
            leaf_or_typedef = leaf_or_typedef.parent

        name = '%s_Bits' % camel_case(leaf_or_typedef.arg)
        if iskeyword(name):
            name = '%s_' % name
        self.name = name

        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg
        else:
            desc = leaf_or_typedef.search_one('description')
            if desc is not None:
                self.comment = desc.arg
        for bit_stmt in stmt.search('bit'):
            self._dictionary[bit_stmt.arg] = False
            pos_stmt = bit_stmt.search_one('position')
            if pos_stmt is not None:
                self._pos_map[bit_stmt.arg] = pos_stmt.arg
Example #4
0
    def stmt(self, stmt):
        self._stmt = stmt
        # the name of the numeration is derived either from the typedef
        # or the leaf under which it is defined
        leaf_or_typedef = stmt
        while leaf_or_typedef.parent is not None and not leaf_or_typedef.keyword in (
                'leaf', 'leaf-list', 'typedef'):
            leaf_or_typedef = leaf_or_typedef.parent

        name = '%sEnum' % camel_case(escape_name(leaf_or_typedef.arg))
        if iskeyword(name):
            name = '%s_' % name

        if name[0] == '_':
            name = 'Y%s' % name

        self.name = name

        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg
        else:
            desc = leaf_or_typedef.search_one('description')
            if desc is not None:
                self.comment = desc.arg
        for enum_stmt in stmt.search('enum'):
            literal = EnumLiteral()
            literal.stmt = enum_stmt
            self.literals.append(literal)
Example #5
0
    def stmt(self, stmt):
        self._stmt = stmt
        self._dictionary = {}
        self._pos_map = {}
        # the name of the enumeration is derived either from the typedef
        # or the leaf under which it is defined
        leaf_or_typedef = stmt
        while leaf_or_typedef.parent is not None and not leaf_or_typedef.keyword in (
                'leaf', 'leaf-list', 'typedef'):
            leaf_or_typedef = leaf_or_typedef.parent

        name = '%s_Bits' % camel_case(leaf_or_typedef.arg)
        if iskeyword(name):
            name = '%s_' % name
        self.name = name

        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg
        else:
            desc = leaf_or_typedef.search_one('description')
            if desc is not None:
                self.comment = desc.arg
        for bit_stmt in stmt.search('bit'):
            self._dictionary[bit_stmt.arg] = False
            pos_stmt = bit_stmt.search_one('position')
            if pos_stmt is not None:
                self._pos_map[bit_stmt.arg] = pos_stmt.arg
Example #6
0
    def stmt(self, stmt):
        name = escape_name(stmt.arg)
        if stmt.keyword == 'grouping':
            name = '%s_Grouping' % camel_case(name)
        elif stmt.keyword == 'identity':
            name = '%s_Identity' % camel_case(name)
        elif stmt.keyword == 'rpc':
            name = camel_case(name) + 'Rpc'
        else:
            name = camel_case(name)
        if iskeyword(name):
            name = '%s_' % name
        self.name = name

        if self.name.startswith('_'):
            self.name = '%s%s' % ('Y', name)

        self._stmt = stmt
        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg

        if stmt.keyword == 'module':
            self._module = stmt
        else:
            self._module = stmt.i_module
Example #7
0
    def convert_prop_name(self, stmt):
        name = snake_case(stmt.arg)
        if iskeyword(name):
            name = '%s_' % name

        if name.startswith('_'):
            name = '%s%s' % ('y', name)
        return name
Example #8
0
    def convert_prop_name(self, stmt):
        name = snake_case(stmt.arg)
        if iskeyword(name):
            name = '%s_' % name

        if name.startswith('_'):
            name = '%s%s' % ('y', name)
        return name
Example #9
0
    def stmt(self, stmt):
        name = stmt.arg.replace('-', '_')
        if iskeyword(name):
            name = '%s_' % name
        if name[0] == '_':
            name = 'y%s' % name

        self.name = name
        self._stmt = stmt
        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg
Example #10
0
    def stmt(self, stmt):
        name = stmt.arg.replace('-', '_')
        if iskeyword(name):
            name = '%s_' % name
        if name[0] == '_':
            name = 'y%s' % name

        self.name = name
        self._stmt = stmt
        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg
Example #11
0
    def convert_owner_name(self, stmt):
        name = escape_name(stmt.arg)
        if stmt.keyword == 'grouping':
            name = '%s_Grouping' % camel_case(name)
        elif stmt.keyword == 'identity':
            name = '%s_Identity' % camel_case(name)
        elif stmt.keyword == 'rpc':
            name = camel_case(name) + 'Rpc'
        else:
            name = camel_case(name)
        if iskeyword(name):
            name = '%s_' % name

        if name.startswith('_'):
            name = '%s%s' % ('Y', name)
        return name
Example #12
0
    def convert_owner_name(self, stmt):
        name = escape_name(stmt.arg)
        if stmt.keyword == 'grouping':
            name = '%s_Grouping' % camel_case(name)
        elif stmt.keyword == 'identity':
            name = '%s_Identity' % camel_case(name)
        elif stmt.keyword == 'rpc':
            name = camel_case(name) + 'Rpc'
        else:
            name = camel_case(name)
        if iskeyword(name):
            name = '%s_' % name

        if name.startswith('_'):
            name = '%s%s' % ('Y', name)
        return name
Example #13
0
 def get_py_mod_name(self):
     """
         Get the python module name that contains this
         NamedElement.
     """
     pkg = self
     while pkg is not None and not isinstance(pkg, Package):
         pkg = pkg.owner
     if pkg is None:
         return ''
     t = pkg.name.split('_')
     t = [n for n in t if n.lower() not in ['cisco', 'ios', 'xr']]
     if t:
         sub = t[0].lower()
         if iskeyword(sub):
             sub = '%s_' % sub
         sub = '.%s' % sub
     else:
         sub = ''
     py_mod_name = 'ydk.models%s.%s' % (sub, pkg.name)
     return py_mod_name
Example #14
0
    def stmt(self, stmt):
        self._stmt = stmt
        name = snake_case(stmt.arg)
        if iskeyword(name):
            name = '%s_' % name
        self.name = name

        if self.name.startswith('_'):
            self.name = '%s%s' % ('y', name)
        if stmt.keyword in ['leaf-list', 'list']:
            self.is_many = True
        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg

        max_elem_stmt = stmt.search_one('max-elements')
        min_elem_stmt = stmt.search_one('min-elements')
        if max_elem_stmt:
            self.max_elements = max_elem_stmt.arg
        if min_elem_stmt:
            self.min_elements = min_elem_stmt.arg
Example #15
0
    def stmt(self, stmt):
        self._stmt = stmt
        name = snake_case(stmt.arg)
        if iskeyword(name):
            name = '%s_' % name
        self.name = name

        if self.name.startswith('_'):
            self.name = '%s%s' % ('y', name)
        if stmt.keyword in ['leaf-list', 'list']:
            self.is_many = True
        desc = stmt.search_one('description')
        if desc is not None:
            self.comment = desc.arg

        max_elem_stmt = stmt.search_one('max-elements')
        min_elem_stmt = stmt.search_one('min-elements')
        if max_elem_stmt:
            self.max_elements = max_elem_stmt.arg
        if min_elem_stmt:
            self.min_elements = min_elem_stmt.arg
Example #16
0
 def get_py_mod_name(self):
     """
         Get the python module name that contains this
         NamedElement.
     """
     pkg = self
     while pkg is not None and not isinstance(pkg, Package):
         pkg = pkg.owner
     if pkg is None:
         return ''
     t = pkg.name.split('_')
     t = [n for n in t if n.lower() not in ['cisco', 'ios', 'xr']]
     if t:
         sub = t[0].lower()
         if iskeyword(sub):
             sub = '%s_' % sub
         sub = '.%s' % sub
     else:
         sub = ''
     py_mod_name = 'ydk.models%s.%s' % (sub, pkg.name)
     return py_mod_name