Beispiel #1
0
 def _print_yang_models_function(self, clazz):
     self.ctx.writeln('std::string %s::get_bundle_yang_models_location() const' % clazz.qualified_cpp_name())
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     self.ctx.writeln('return ydk_%s_models_path;' % snake_case(self.bundle_name))
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
     self.ctx.bline()
Beispiel #2
0
 def _print_bundle_name_function(self, clazz):
     self.ctx.writeln('std::string %s::get_bundle_name() const' % clazz.qualified_cpp_name())
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     self.ctx.writeln('return "%s";' % snake_case(self.bundle_name))
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
     self.ctx.bline()
 def _print_namespace_identity_lookup_function(self, clazz):
     self.ctx.writeln('std::map<std::pair<std::string, std::string>, std::string> %s::get_namespace_identity_lookup() const' % clazz.qualified_cpp_name())
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     self.ctx.writeln("return %s_namespace_identity_lookup;" % snake_case(self.bundle_name))
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
     self.ctx.bline()
Beispiel #4
0
 def _print_capabilities_lookup_function(self, clazz):
     self.ctx.writeln('augment_capabilities_function %s::get_augment_capabilities_function() const' % clazz.qualified_cpp_name())
     self.ctx.writeln('{')
     self.ctx.lvl_inc()
     self.ctx.writeln("return %s_augment_lookup_tables;" % snake_case(self.bundle_name))
     self.ctx.lvl_dec()
     self.ctx.writeln('}')
     self.ctx.bline()
Beispiel #5
0
 def _print_python_modules(self, element, index, path, size, sub):
     for c in [
             clazz for clazz in element.owned_elements
             if isinstance(clazz, Class)
     ]:
         if not c.is_identity():
             self._print_python_module(
                 c, index, os.path.join(path, snake_case(c.stmt.arg)), size,
                 sub)
Beispiel #6
0
 def print_header(self, bundle_name):
     self.bundle_name = bundle_name
     self._print_include_guard_header(
         get_include_guard_name('entity_lookup'))
     self.ctx.writeln('#include <map>')
     self.ctx.writeln('#include <string>')
     self.ctx.bline()
     self.ctx.writeln('namespace %s' % bundle_name)
     self.ctx.writeln('{')
     self.ctx.bline()
     self.ctx.writeln("void {}_augment_lookup_tables();".format(
         snake_case(self.bundle_name)))
     self.ctx.writeln(
         "extern std::map<std::pair<std::string, std::string>, std::string> {0}_namespace_identity_lookup;"
         .format(snake_case(self.bundle_name)))
     self.ctx.bline()
     self.ctx.writeln('}')
     self._print_include_guard_trailer(
         get_include_guard_name('entity_lookup'))
 def _print_mandatory_leafs(self, element):
     mandatory_leafs = self._get_mandatory_leafs(element)
     if len(mandatory_leafs) > 0:
         self.ctx.writeln('#MANDATORY LEAFS CREATE')
     for mandatory_leaf in mandatory_leafs:
         leafs_to_set = mandatory_leaf.clazz.get_key_props()
         leafs_to_set.extend(x for x in mandatory_leaf.props if x not in leafs_to_set)
         self._print_class_instance(mandatory_leaf.clazz, leafs_to_set, suffix='')
         self.ctx.writeln('print "Creating mandatory %s"' % snake_case(mandatory_leaf.clazz.qn() + '.' + mandatory_leaf.props[0].name))
         self.ctx.writeln('self.crud.create(self.ncc, %s)' % get_obj_name(mandatory_leaf.clazz))
         self.ctx.bline()
Beispiel #8
0
    def _print_capabilities_lookup_func_header(self):
        self.ctx.bline()
        self.ctx.writeln('namespace %s' % self.bundle_name)
        self.ctx.writeln('{')
        self.ctx.bline()
        self.ctx.writelns([
            "void {}_augment_lookup_tables()".format(
                snake_case(self.bundle_name)), "{"
        ])

        self.ctx.bline()
        self.ctx.lvl_inc()
Beispiel #9
0
 def _print_namespace_identity_lookup(self, packages):
     self.ctx.bline()
     self.ctx.writeln(
         "std::map<std::pair<std::string, std::string>, std::string> %s_namespace_identity_lookup {"
         % (snake_case(self.bundle_name)))
     self.ctx.lvl_inc()
     for package in packages:
         identities = self._get_identities(package)
         for identity in identities:
             self._print_namespace_identity_lookup_statement(identity)
     self.ctx.lvl_dec()
     self.ctx.writeln("};")
     self.ctx.bline()
Beispiel #10
0
 def print_header(self, bundle_name):
     self.bundle_name = bundle_name
     self._print_include_guard_header(
         get_include_guard_name('entity_lookup'))
     self.ctx.writeln('namespace ydk')
     self.ctx.writeln('{')
     self.ctx.bline()
     self.ctx.writeln("void {}_augment_lookup_tables();".format(
         snake_case(self.bundle_name)))
     self.ctx.bline()
     self.ctx.writeln('}')
     self._print_include_guard_trailer(
         get_include_guard_name('entity_lookup'))
Beispiel #11
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, snake_case(child.property_type.stmt.arg), 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, child.stmt.arg))
             self.ctx.writeln('self._children_yang_names.add("%s")' % (child.stmt.arg))
def get_obj_name(clazz):
    obj_name = snake_case(clazz.qn())
    if iskeyword(obj_name):
        obj_name = '%s_' % obj_name
    return obj_name
 def _print_test_case_header(self, clazz):
     self.ctx.writeln('def test_%s(self):' % ('_'.join([snake_case(f) for f in clazz.qn().split('.')])))
     self.ctx.lvl_inc()
Beispiel #14
0
 def _print_children_imports(self, clazz, children):
     for child in children:
         self.ctx.writeln('from .%s import %s' % (snake_case(child.property_type.stmt.arg), snake_case(child.property_type.stmt.arg)))
         self.ctx.writeln('self.__class__.%s = %s.%s' % (child.property_type.name, snake_case(child.property_type.stmt.arg), child.property_type.name))
     self.ctx.bline()
Beispiel #15
0
def get_python_module_file_name(path, package):
    if isinstance(package, Package):
        return '%s/%s.py' % (path, package.name)
    else:
        return '%s/%s.py' % (path, snake_case(package.stmt.arg))