def _init_namespace_info(self, packages): module_map = {} for m in [p.stmt for p in packages]: ns = m.search_one('namespace') if ns is not None: self.namespace_list.append( (m.arg.replace('-', '_'), ns.arg, yang_id(m))) module_map[m.arg] = ns.arg for m in [p.stmt for p in packages]: if m.keyword == 'submodule': including_module = m.i_including_modulename if including_module is not None and including_module in module_map: main_ns = module_map[including_module] self.namespace_list.append( (m.arg.replace('-', '_'), main_ns, yang_id(m))) for package in packages: ns = package.stmt.search_one('namespace') for ele in package.owned_elements: if hasattr(ele, 'stmt') and ele.stmt is not None and ( ele.stmt.keyword == 'container' or ele.stmt.keyword == 'list'): self.namespace_map[(ns.arg, ele.stmt.arg)] = ( package.get_py_mod_name(), ele.name)
def emit_yang_ns(ctx, packages): ctx.printer.print_yang_ns_header() ns_list = [] module_map = {} namespace_map = {} for m in [p.stmt for p in packages]: ns = m.search_one('namespace') if ns is not None: ns_list.append((m.arg.replace('-', '_'), ns.arg, yang_id(m))) module_map[m.arg] = ns.arg for m in [p.stmt for p in packages]: if m.keyword == 'submodule': including_module = m.i_including_modulename if including_module is not None and including_module in module_map: main_ns = module_map[including_module] ns_list.append((m.arg.replace('-', '_'), main_ns, yang_id(m))) for package in packages: ns = package.stmt.search_one('namespace') for ele in package.owned_elements: if hasattr(ele, 'stmt') and ele.stmt is not None and ( ele.stmt.keyword == 'container' or ele.stmt.keyword == 'list'): namespace_map[(ns.arg, ele.stmt.arg)] = (package.get_py_mod_name(), ele.name) ctx.printer.print_namespaces(ns_list) ctx.printer.print_identity_map(packages) ctx.printer.print_namespaces_map(namespace_map)
def emit_yang_ns(ctx, packages): ctx.printer.print_yang_ns_header() ns_list = [] module_map = {} namespace_map = {} for m in [p.stmt for p in packages]: ns = m.search_one('namespace') if ns is not None: ns_list.append((m.arg.replace('-', '_'), ns.arg, yang_id(m))) module_map[m.arg] = ns.arg for m in [p.stmt for p in packages]: if m.keyword == 'submodule': including_module = m.i_including_modulename if including_module is not None and including_module in module_map: main_ns = module_map[including_module] ns_list.append((m.arg.replace('-', '_'), main_ns, yang_id(m))) for package in packages: ns = package.stmt.search_one('namespace') for ele in package.owned_elements: if hasattr(ele, 'stmt') and ele.stmt is not None and (ele.stmt.keyword == 'container' or ele.stmt.keyword == 'list'): namespace_map[(ns.arg, ele.stmt.arg)] = (package.get_py_mod_name(), ele.name) ctx.printer.print_namespaces(ns_list) ctx.printer.print_identity_map(packages) ctx.printer.print_namespaces_map(namespace_map)
def _init_namespace_info(self, packages): module_map = {} for m in [p.stmt for p in packages]: ns = m.search_one('namespace') if ns is not None: self.namespace_list.append((m.arg.replace('-', '_'), ns.arg, yang_id(m))) module_map[m.arg] = ns.arg for m in [p.stmt for p in packages]: if m.keyword == 'submodule': including_module = m.i_including_modulename if including_module is not None and including_module in module_map: main_ns = module_map[including_module] self.namespace_list.append((m.arg.replace('-', '_'), main_ns, yang_id(m))) for package in packages: ns = package.stmt.search_one('namespace') for ele in package.owned_elements: if hasattr(ele, 'stmt') and ele.stmt is not None and (ele.stmt.keyword == 'container' or ele.stmt.keyword == 'list'): self.namespace_map[(ns.arg, ele.stmt.arg)] = (package.get_py_mod_name(), ele.name)
def emit_module_header(ctx, package, mheader=None, is_meta=False): # :::::::::::::::::::::::::::::::::::::::: # Print the header # :::::::::::::::::::::::::::::::::::::::: s = package.stmt if is_meta: rpcs = [ idx for idx in package.owned_elements if isinstance(idx, Class) and idx.is_rpc() ] anyxml_import = '' if len(rpcs) > 0: anyxml_import = ', ANYXML_CLASS' ctx.printer.meta_header(anyxml_import) else: comment = s.search_one('description') ctx.writeln('""" %s ' % package.name) ctx.bline() if comment is not None and not is_meta: ctx.comment = comment.arg for line in ctx.comment.split('\n'): ctx.writeln(convert_to_reStructuredText(line)) ctx.bline() ctx.writeln('"""') ctx.printer.header(mheader) ctx.printer.imports(package) ctx.root = s ctx.augment_path = '' ctx.aug_stmt = None ctx.module_name = yang_id(s) ctx.module = s # get the yang meta information. prefix = s.search_one('prefix') if prefix is not None: ctx.prefix = yang_id(prefix) namespace = s.search_one('namespace') if namespace is not None: ctx.namespace = yang_id(namespace) org = s.search_one('organization') if org is not None: ctx.organization = yang_id(org) contact = s.search_one('contact') if contact is not None: ctx.contact = yang_id(contact) revision = s.search_one('revision') if revision is not None: ctx.revision = yang_id(revision) ctx.ns += [(yang_id(s), ctx.namespace)]
def emit_module_header(ctx, package, mheader=None, is_meta=False): # :::::::::::::::::::::::::::::::::::::::: # Print the header # :::::::::::::::::::::::::::::::::::::::: s = package.stmt if is_meta: rpcs = [idx for idx in package.owned_elements if isinstance(idx, Class) and idx.is_rpc()] anyxml_import = '' if len(rpcs) > 0: anyxml_import = ', ANYXML_CLASS' ctx.printer.meta_header(anyxml_import) else: comment = s.search_one('description') ctx.writeln('""" %s ' % package.name) ctx.bline() if comment is not None and not is_meta: ctx.comment = comment.arg for line in ctx.comment.split('\n'): ctx.writeln(convert_to_reStructuredText(line)) ctx.bline() ctx.writeln('"""') ctx.printer.header(mheader) ctx.printer.imports(package) ctx.root = s ctx.augment_path = '' ctx.aug_stmt = None ctx.module_name = yang_id(s) ctx.module = s # get the yang meta information. prefix = s.search_one('prefix') if prefix is not None: ctx.prefix = yang_id(prefix) namespace = s.search_one('namespace') if namespace is not None: ctx.namespace = yang_id(namespace) org = s.search_one('organization') if org is not None: ctx.organization = yang_id(org) contact = s.search_one('contact') if contact is not None: ctx.contact = yang_id(contact) revision = s.search_one('revision') if revision is not None: ctx.revision = yang_id(revision) ctx.ns += [(yang_id(s), ctx.namespace)]