예제 #1
0
def get_child_list_classes(clazz, one_class_per_module):
    m = []
    for prop in clazz.properties():
        if prop.stmt.keyword == 'list':
            if one_class_per_module:
                m.append('("%s", ("%s", %s.%s))' % (get_qualified_yang_name(prop.property_type), prop.name, clazz.name, prop.property_type.name))
            else:
                m.append('("%s", ("%s", %s))' % (get_qualified_yang_name(prop.property_type), prop.name, prop.property_type.qn()))
    return '%s' % (', '.join(m))
예제 #2
0
def get_child_classes(clazz, one_class_per_module):
    m = []
    for prop in clazz.properties():
        if prop.stmt.keyword in ('list', 'container'):
            if one_class_per_module:
                m.append('("%s", ("%s", %s.%s))' % (
                    get_qualified_yang_name(prop.property_type), prop.name, clazz.name, prop.property_type.name))
            else:
                m.append('("%s", ("%s", %s))' % (
                    get_qualified_yang_name(prop.property_type), prop.name, prop.property_type.qn()))
    return '%s' % (', '.join(m))
예제 #3
0
    def _print_children(fp, children, data_alias):
        fp.ctx.writeln('%s.Children = types.NewOrderedMap()' % data_alias)
        for child in children:
            path = get_qualified_yang_name(child)
            if child.is_many:
                fp.ctx.writeln(
                    '%s.Children.Append("%s", types.YChild{"%s", nil})' %
                    (data_alias, path, child.property_type.go_name()))

                child_stmt = '%s.%s' % (fp.class_alias,
                                        child.property_type.go_name())
                fp.ctx.writeln('for i := range %s {' % (child_stmt))
                fp.ctx.lvl_inc()
                child_stmt = '%s[i]' % child_stmt
                fp.ctx.writeln(
                    '%s.Children.Append(types.GetSegmentPath(%s), types.YChild{"%s", %s})'
                    % (data_alias, child_stmt, child.property_type.go_name(),
                       child_stmt))
                fp.ctx.lvl_dec()
                fp.ctx.writeln('}')
            else:
                fp.ctx.writeln(
                    '%s.Children.Append("%s", types.YChild{"%s", &%s.%s})' %
                    (data_alias, path, child.property_type.go_name(),
                     fp.class_alias, child.property_type.go_name()))
예제 #4
0
 def _print_class_set_values(self, leaf):
     self.ctx.writeln('if(value_path == "%s")' %
                      (get_qualified_yang_name(leaf)))
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     if isinstance(leaf.property_type, Bits):
         if leaf.is_many:
             self.ctx.writeln('Bits bits_value{};')
             self.ctx.writeln('bits_value[value] = true;')
             self.ctx.writeln('%s.append(bits_value);' % leaf.name)
         else:
             self.ctx.writeln('%s[value] = true;' % leaf.name)
     elif leaf.is_many:
         if isinstance(leaf.property_type,
                       Class) and leaf.property_type.is_identity():
             self.ctx.writeln(
                 'Identity identity{name_space, name_space_prefix, value};')
             self.ctx.writeln('%s.append(identity);' % leaf.name)
         else:
             self.ctx.writeln('%s.append(value);' % leaf.name)
     else:
         self.ctx.writeln('%s = value;' % leaf.name)
         self.ctx.writeln('%s.value_namespace = name_space;' % leaf.name)
         self.ctx.writeln('%s.value_namespace_prefix = name_space_prefix;' %
                          leaf.name)
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
예제 #5
0
 def _print_class_get_child(self, child):
     self.ctx.writeln('if(child_yang_name == "%s")' % get_qualified_yang_name(child))
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     if child.is_many:
         self._print_class_get_child_many(child)
     else:
         self._print_class_get_child_unique(child)
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
예제 #6
0
 def print_function_body(self):
     self.ctx.writeln('children := make(map[string]types.Entity)')
     for child in self.children:
         if child.is_many:
             self._print_many(child)
         else:
             path = get_qualified_yang_name(child)
             self.ctx.writeln('children["%s"] = &%s.%s' %
                              (path, self.class_alias, child.go_name()))
     self.ctx.writeln('return children')
예제 #7
0
 def _print_class_get_child(self, child):
     self.ctx.writeln('if(child_yang_name == "%s")' %
                      get_qualified_yang_name(child))
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     if child.is_many:
         self._print_class_get_child_many(child)
     else:
         self._print_class_get_child_unique(child)
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
예제 #8
0
 def _print_check_child(self, child):
     self.ctx.writeln('if childYangName == "%s" {' %
                      get_qualified_yang_name(child))
     self.ctx.lvl_inc()
     if child.is_many:
         self._print_check_many(child)
     else:
         self.ctx.writeln('return &%s.%s' %
                          (self.class_alias, child.go_name()))
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
예제 #9
0
 def _print_class_get_go_name(self, clazz, leafs, children):
     fp = FunctionPrinter(self.ctx, clazz)
     fp.print_function_header_helper('GetGoName',
                                     args='yname string',
                                     return_type='string')
     for leaf in leafs:
         fp.ctx.writeln('if yname == "%s" { return "%s" }' %
                        (leaf.stmt.arg, leaf.go_name()))
     for child in children:
         fp.ctx.writeln('if yname == "%s" { return "%s" }' %
                        (get_qualified_yang_name(child), child.go_name()))
     fp.ctx.writeln('return ""')
     fp.print_function_trailer()
예제 #10
0
 def _print_init_children(self, children):
     for child in children:
         if not child.is_many:
             self.ctx.bline()
             if (child.stmt.search_one('presence') is None):
                 if self.one_class_per_module:
                     self.ctx.writeln('self.%s = %s.%s()' % (child.name, get_unclashed_name(child.property_type, child.property_type.iskeyword), child.property_type.name))
                 else:
                     self.ctx.writeln('self.%s = %s()' % (child.name, child.property_type.qn()))
                 self.ctx.writeln('self.%s.parent = self' % child.name)
             else:
                 self.ctx.writeln('self.%s = None' % (child.name))
             self.ctx.writeln('self._children_name_map["%s"] = "%s"' % (child.name, get_qualified_yang_name(child)))
             self.ctx.writeln('self._children_yang_names.add("%s")' % (get_qualified_yang_name(child)))
예제 #11
0
    def _print_children(fp, children, data_alias):
        fp.ctx.writeln('%s.Children = types.NewOrderedMap()' % data_alias)
        for child in children:
            path = get_qualified_yang_name(child)
            if child.is_many:
                fp.ctx.writeln('%s.Children.Append("%s", types.YChild{"%s", nil})' % (
                    data_alias, path, child.property_type.go_name()))

                child_stmt = '%s.%s' % (fp.class_alias, child.property_type.go_name())
                fp.ctx.writeln('for i := range %s {' % (child_stmt))
                fp.ctx.lvl_inc()
                child_stmt = '%s[i]' % child_stmt
                if child.stmt.keyword == 'list' and len(child.stmt.i_key) == 0:
                    fp.ctx.writeln('types.SetYListKey(%s, i)' % child_stmt)
                fp.ctx.writeln('%s.Children.Append(types.GetSegmentPath(%s), types.YChild{"%s", %s})' %(
                    data_alias, child_stmt, child.property_type.go_name(), child_stmt))
                fp.ctx.lvl_dec()
                fp.ctx.writeln('}')
            else:
                fp.ctx.writeln('%s.Children.Append("%s", types.YChild{"%s", &%s.%s})' % (
                    data_alias, path, child.property_type.go_name(), fp.class_alias, child.property_type.go_name()))
예제 #12
0
 def _print_class_set_values(self, leaf):
     self.ctx.writeln('if(value_path == "%s")' % (get_qualified_yang_name(leaf)))
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     if(isinstance(leaf.property_type, Bits)):
         if leaf.is_many:
             self.ctx.writeln('Bits bits_value{};')
             self.ctx.writeln('bits_value[value] = true;')
             self.ctx.writeln('%s.append(bits_value);' % leaf.name)
         else:
             self.ctx.writeln('%s[value] = true;' % leaf.name)
     elif(leaf.is_many):
         if (isinstance(leaf.property_type, Class) and leaf.property_type.is_identity()):
             self.ctx.writeln('Identity identity{name_space, name_space_prefix, value};')
             self.ctx.writeln('%s.append(identity);' % leaf.name)
         else:
             self.ctx.writeln('%s.append(value);' % leaf.name)
     else:
         self.ctx.writeln('%s = value;' % leaf.name)
         self.ctx.writeln('%s.value_namespace = name_space;' % leaf.name)
         self.ctx.writeln('%s.value_namespace_prefix = name_space_prefix;' % leaf.name)
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
예제 #13
0
    def _print_children(fp, children, data_alias):
        fp.ctx.writeln('%s.Children = make(map[string]types.YChild)' %
                       data_alias)
        for child in children:
            path = get_qualified_yang_name(child)
            if child.is_many:
                fp.ctx.writeln('%s.Children["%s"] = types.YChild{"%s", nil}' %
                               (data_alias, path, child.go_name()))

                child_stmt = '%s.%s' % (fp.class_alias, child.go_name())
                fp.ctx.writeln('for i := range %s {' % (child_stmt))
                fp.ctx.lvl_inc()
                child_stmt = '%s[i]' % child_stmt
                fp.ctx.writeln(
                    '%s.Children[types.GetSegmentPath(&%s)] = types.YChild{"%s", &%s}'
                    % (data_alias, child_stmt, child.go_name(), child_stmt))
                fp.ctx.lvl_dec()
                fp.ctx.writeln('}')
            else:
                fp.ctx.writeln(
                    '%s.Children["%s"] = types.YChild{"%s", &%s.%s}' %
                    (data_alias, path, child.go_name(), fp.class_alias,
                     child.go_name()))
예제 #14
0
 def _print_init_children(self, children):
     for child in children:
         if not child.is_many:
             self.ctx.bline()
             if (child.stmt.search_one('presence') is None):
                 if self.one_class_per_module:
                     self.ctx.writeln('self.%s = %s.%s()' % (
                         child.name, get_unclashed_name(child.property_type, child.property_type.iskeyword),
                         child.property_type.name))
                 else:
                     self.ctx.writeln('self.%s = %s()' % (child.name, child.property_type.qn()))
                 self.ctx.writeln('self.%s.parent = self' % child.name)
             else:
                 self.ctx.writeln('self.%s = None' % (child.name))
             self.ctx.writeln('self._children_name_map["%s"] = "%s"' % (child.name, get_qualified_yang_name(child)))