def print_node(s, module, fd, prefix, ctx, level=0): global levelcnt fontstarttag = "" fontendtag = "" status = get_status_str(s) nodetype = '' options = '' folder = False if s.i_module.i_modulename == module.i_modulename: name = s.arg else: name = s.i_module.i_prefix + ':' + s.arg pr = module.search_one('prefix') if pr is not None: prstr = pr.arg else: prstr = "" descr = s.search_one('description') descrstring = "No description" if descr is not None: descrstring = descr.arg flags = get_flags_str(s) if s.keyword == 'list': folder = True elif s.keyword == 'container': folder = True p = s.search_one('presence') if p is not None: pr_str = p.arg options = "<abbr title=\"" + pr_str + "\">Presence</abbr>" elif s.keyword == 'choice': folder = True m = s.search_one('mandatory') if m is None or m.arg == 'false': name = '(' + s.arg + ')' options = 'Choice' else: name = '(' + s.arg + ')' elif s.keyword == 'case': folder = True # fd.write(':(' + s.arg + ')') name = ':(' + s.arg + ')' elif s.keyword == 'input': folder = True elif s.keyword == 'output': folder = True elif s.keyword == 'rpc': folder = True elif s.keyword == 'notification': folder = True else: if s.keyword == 'leaf-list': options = '*' elif s.keyword == 'leaf' and not hasattr(s, 'i_is_key'): m = s.search_one('mandatory') if m is None or m.arg == 'false': options = '?' nodetype = get_typename(s) if s.keyword == 'list' and s.search_one('key') is not None: name += '[' + s.search_one('key').arg + ']' descr = s.search_one('description') if descr is not None: descrstring = ''.join([x for x in descr.arg if ord(x) < 128]) else: descrstring = "No description" levelcnt[level] += 1 idstring = str(levelcnt[1]) for i in range(2, level + 1): idstring += '-' + str(levelcnt[i]) pathstr = statements.mk_path_str(s, True) if not ctx.opts.jstree_no_path: if ctx.opts.strip_namespace: re_ns = re.compile(r'^.+:') path_components = [ re_ns.sub('', comp) for comp in pathstr.split('/') ] pathstr = '/'.join(path_components) else: # append the path to the description popup descrstring = descrstring + "\n\npath: " + pathstr pathstr = "" if '?' in options: fontstarttag = "<em>" fontendtag = "</em>" keyword = s.keyword if folder: # html plugin specific changes if hasattr(ctx, 'html_plugin_user'): from pyang.plugins.html import force_link name = force_link(ctx, s, module, name) fd.write("""<tr id="%s" class="a"> <td nowrap id="p4000"> <div id="p5000" style="margin-left:%sem;"> <a href="#" id="p6000" onclick="toggleRows(this);return false" class="folder"> </a> <abbr title="%s">%s</abbr> </div> </td> \n""" % (idstring, (level * 1.5 - 1.5), descrstring, name)) fd.write("""<td nowrap>%s</td> <td nowrap>%s</td> <td nowrap>%s</td> <td>%s</td> <td>%s</td> <td nowrap>%s</td> </tr> \n""" % (s.keyword, nodetype, flags, options, status, pathstr)) else: if s.keyword in ['action', ('tailf-common', 'action')]: classstring = "action" typeinfo = action_params(s) typename = "parameters" keyword = "action" elif s.keyword == 'rpc' or s.keyword == 'notification': classstring = "folder" typeinfo = action_params(s) typename = "parameters" else: classstring = s.keyword typeinfo = typestring(s) typename = nodetype fd.write("""<tr id="%s" class="a"> <td nowrap> <div id=9999 style="margin-left: %sem;"> <a class="%s"> </a> <abbr title="%s"> %s %s %s</abbr> </div> </td> <td>%s</td> <td nowrap><abbr title="%s">%s</abbr></td> <td nowrap>%s</td> <td>%s</td> <td>%s</td> <td nowrap>%s</td</tr> \n""" % (idstring, (level * 1.5 - 1.5), classstring, descrstring, fontstarttag, name, fontendtag, keyword, typeinfo, typename, flags, options, status, pathstr)) if hasattr(s, 'i_children'): level += 1 if s.keyword in ['choice', 'case']: print_children(s.i_children, module, fd, prefix, ctx, level) else: print_children(s.i_children, module, fd, prefix, ctx, level)
def emit_tree(modules, fd, ctx): global levelcnt for module in modules: bstr = "" b = module.search_one('belongs-to') if b is not None: bstr = " (belongs-to %s)" % b.arg ns = module.search_one('namespace') if ns is not None: nsstr = ns.arg pr = module.search_one('prefix') if pr is not None: prstr = pr.arg else: prstr = "" temp_mod_arg = module.arg # html plugin specific changes if hasattr(ctx, 'html_plugin_user'): from pyang.plugins.html import force_link temp_mod_arg = force_link(ctx, module, module) levelcnt[1] += 1 fd.write("""<tr id="%s" class="a"> <td id="p1"> <div id="p2" class="tier1"> <a href="#" id="p3" onclick="toggleRows(this);return false;" class="folder"> </a> <font color=blue>%s</font> </div> </td> \n""" % (levelcnt[1], temp_mod_arg)) fd.write("""<td>%s</td><td></td><td></td><td></td><td> </td></tr>\n""" % module.keyword) #fd.write("<td>module</td><td></td><td></td><td></td><td></td></tr>\n") chs = [ ch for ch in module.i_children if ch.keyword in statements.data_definition_keywords ] print_children(chs, module, fd, ' ', ctx, 2) rpcs = module.search('rpc') levelcnt[1] += 1 if len(rpcs) > 0: fd.write("""<tr id="%s" class="a"> <td nowrap id="p1000"> <div id="p2000" class="tier1"> <a href="#" id="p3000" onclick="toggleRows(this); return false;" class="folder"> </a> %s:rpcs </div> </td> \n""" % (levelcnt[1], prstr)) fd.write("<td></td><td></td><td></td><td></td><td></td></tr>\n") print_children(rpcs, module, fd, ' ', ctx, 2) notifs = module.search('notification') levelcnt[1] += 1 if len(notifs) > 0: fd.write("""<tr id="%s" class="a"> <td nowrapid="p4000"> <div id="p5000" class="tier1"> <a href="#" id="p6000" onclick="toggleRows(this);return false;" class="folder"> </a>%s:notifs </div> </td> \n""" % (levelcnt[1], prstr)) fd.write("<td></td><td></td><td></td><td></td><td></td></tr>\n") print_children(notifs, module, fd, ' ', ctx, 2)
def emit_tree(modules, fd, ctx): global levelcnt for module in modules: bstr = "" b = module.search_one('belongs-to') if b is not None: bstr = " (belongs-to %s)" % b.arg ns = module.search_one('namespace') if ns is not None: nsstr = ns.arg pr = module.search_one('prefix') if pr is not None: prstr = pr.arg else: prstr = "" temp_mod_arg = module.arg # html plugin specific changes if hasattr(ctx, 'html_plugin_user'): from pyang.plugins.html import force_link temp_mod_arg = force_link(ctx,module,module) levelcnt[1] += 1 fd.write("""<tr id="%s" class="a"> <td id="p1"> <div id="p2" class="tier1"> <a href="#" id="p3" onclick="toggleRows(this);return false;" class="folder"> </a> <font color=blue>%s</font> </div> </td> \n""" %(levelcnt[1], temp_mod_arg)) fd.write("""<td>%s</td><td></td><td></td><td></td><td> </td></tr>\n""" %module.keyword) #fd.write("<td>module</td><td></td><td></td><td></td><td></td></tr>\n") chs = [ch for ch in module.i_children if ch.keyword in statements.data_definition_keywords] print_children(chs, module, fd, ' ', ctx, 2) rpcs = module.search('rpc') levelcnt[1] += 1 if len(rpcs) > 0: fd.write("""<tr id="%s" class="a"> <td nowrap id="p1000"> <div id="p2000" class="tier1"> <a href="#" id="p3000" onclick="toggleRows(this); return false;" class="folder"> </a> %s:rpcs </div> </td> \n""" %(levelcnt[1],prstr)) fd.write("<td></td><td></td><td></td><td></td><td></td></tr>\n") print_children(rpcs, module, fd, ' ', ctx, 2) notifs = module.search('notification') levelcnt[1] += 1 if len(notifs) > 0: fd.write("""<tr id="%s" class="a"> <td nowrapid="p4000"> <div id="p5000" class="tier1"> <a href="#" id="p6000" onclick="toggleRows(this);return false;" class="folder"> </a>%s:notifs </div> </td> \n""" %(levelcnt[1],prstr)) fd.write("<td></td><td></td><td></td><td></td><td></td></tr>\n") print_children(notifs, module, fd, ' ', ctx, 2)
def print_node(s, module, fd, prefix, ctx, level=0): global levelcnt fontstarttag = "" fontendtag = "" status = get_status_str(s) nodetype = '' options = '' folder = False if s.i_module.i_modulename == module.i_modulename: name = s.arg else: name = s.i_module.i_prefix + ':' + s.arg pr = module.search_one('prefix') if pr is not None: prstr = pr.arg else: prstr = "" descr = s.search_one('description') descrstring = "No description" if descr is not None: descrstring = descr.arg flags = get_flags_str(s) if s.keyword == 'list': folder = True elif s.keyword == 'container': folder = True p = s.search_one('presence') if p is not None: pr_str = p.arg options = "<abbr title=\"" + pr_str + "\">Presence</abbr>" elif s.keyword == 'choice': folder = True m = s.search_one('mandatory') if m is None or m.arg == 'false': name = '(' + s.arg + ')' options = 'Choice' else: name = '(' + s.arg + ')' elif s.keyword == 'case': folder = True # fd.write(':(' + s.arg + ')') name = ':(' + s.arg + ')' elif s.keyword == 'input': folder = True elif s.keyword == 'output': folder = True elif s.keyword == 'rpc': folder = True elif s.keyword == 'notification': folder = True else: if s.keyword == 'leaf-list': options = '*' elif s.keyword == 'leaf' and not hasattr(s, 'i_is_key'): m = s.search_one('mandatory') if m is None or m.arg == 'false': options = '?' nodetype = get_typename(s) if s.keyword == 'list' and s.search_one('key') is not None: name += '[' + s.search_one('key').arg + ']' descr = s.search_one('description') if descr is not None: descrstring = ''.join([x for x in descr.arg if ord(x) < 128]) else: descrstring = "No description"; levelcnt[level] += 1 idstring = str(levelcnt[1]) for i in range(2,level+1): idstring += '-' + str(levelcnt[i]) pathstr = "" if not ctx.opts.jstree_no_path: pathstr = statements.mk_path_str(s, True) if '?' in options: fontstarttag = "<em>" fontendtag = "</em>" keyword = s.keyword if folder: # html plugin specific changes if hasattr(ctx, 'html_plugin_user'): from pyang.plugins.html import force_link name = force_link(ctx,s,module,name) fd.write("""<tr id="%s" class="a"> <td nowrap id="p4000"> <div id="p5000" class="tier%s"> <a href="#" id="p6000" onclick="toggleRows(this);return false" class="folder"> </a> <abbr title="%s">%s</abbr> </div> </td> \n""" %(idstring, level, descrstring, name)) fd.write("""<td nowrap>%s</td> <td nowrap>%s</td> <td nowrap>%s</td> <td>%s</td> <td>%s</td> <td nowrap>%s</td> </tr> \n""" %(s.keyword, nodetype, flags, options, status, pathstr)) else: if s.keyword in ['action', ('tailf-common', 'action')]: classstring = "action" typeinfo = action_params(s) typename = "parameters" keyword = "action" elif s.keyword == 'rpc' or s.keyword == 'notification': classstring = "folder" typeinfo = action_params(s) typename = "parameters" else: classstring = s.keyword typeinfo = typestring(s) typename = nodetype fd.write("""<tr id="%s" class="a"> <td nowrap> <div id=9999 class=tier%s> <a class="%s"> </a> <abbr title="%s"> %s %s %s</abbr> </div> </td> <td>%s</td> <td nowrap><abbr title="%s">%s</abbr></td> <td nowrap>%s</td> <td>%s</td> <td>%s</td> <td nowrap>%s</td</tr> \n""" %(idstring, level, classstring, descrstring, fontstarttag, name, fontendtag, keyword, typeinfo, typename, flags, options, status, pathstr)) if hasattr(s, 'i_children'): level += 1 if s.keyword in ['choice', 'case']: print_children(s.i_children, module, fd, prefix, ctx, level) else: print_children(s.i_children, module, fd, prefix, ctx, level)
def print_node(s, module, fd, prefix, path, ctx, level=0): global levelcnt fontstarttag = "" fontendtag = "" status = get_status_str(s) nodetype = '' options = '' folder = False if s.i_module.i_modulename == module.i_modulename: name = s.arg else: name = s.i_module.i_prefix + ':' + s.arg pr = module.search_one('prefix') if pr is not None: prstr = pr.arg else: prstr = "" descr = s.search_one('description') descrstring = "No description" if descr is not None: descrstring = descr.arg flags = get_flags_str(s) if s.keyword in ('list', 'input', 'output', 'rpc', 'notification', 'action'): folder = True elif s.keyword == 'container': folder = True p = s.search_one('presence') if p is not None: pr_str = p.arg options = "<abbr title=\"" + pr_str + "\">Presence</abbr>" elif s.keyword == 'choice': folder = True m = s.search_one('mandatory') if m is None or m.arg == 'false': name = '(' + s.arg + ')' options = 'Choice' else: name = '(' + s.arg + ')' elif s.keyword == 'case': folder = True # fd.write(':(' + s.arg + ')') name = ':(' + s.arg + ')' else: if s.keyword == 'leaf-list': options = '*' elif s.keyword == 'leaf' and not hasattr(s, 'i_is_key'): m = s.search_one('mandatory') if m is None or m.arg == 'false': options = '?' nodetype = get_typename(s) if s.keyword == 'list' and s.search_one('key') is not None: name += '[' + s.search_one('key').arg + ']' descr = s.search_one('description') if descr is not None: descrstring = ''.join([x for x in descr.arg if ord(x) < 128]) else: descrstring = "No description" levelcnt[level] += 1 idstring = str(levelcnt[1]) for i in range(2, level + 1): idstring += '-' + str(levelcnt[i]) pathstr = "" if not ctx.opts.jstree_no_path: pathstr = statements.mk_path_str(s, True) if '?' in options: fontstarttag = "<em>" fontendtag = "</em>" keyword = s.keyword type_html_info = "" attr_html_info = "" element_htmnl_info = "" if folder: if hasattr(ctx, 'html_plugin_user'): from pyang.plugins.html import force_link name = force_link(ctx, s, module, name) attr_html_info = """<abbr title="%s">%s</abbr>""" % (descrstring, name) classstring = s.keyword if s.keyword in ('action', 'rpc', 'notification'): type_html_info = """<td nowrap><abbr title="%s">%s</abbr></td> """ % (action_params(s), "parameters") else: type_html_info = """<td nowrap>%s</td>""" % (nodetype) element_html_info = """ <td nowrap id="p4000"> <div id="p5000" class="tier%s"> <a href="#" id="p6000" onclick="toggleRows(this);return false" class="%s"> </a> %s </div> </td>""" % (level, "folder", attr_html_info) else: attr_html_info = """<attr title="%s"> %s %s %s</abbr> """ % (descrstring, fontstarttag, name, fontendtag) if s.keyword == ('tailf-common', 'action'): type_html_info = """<td nowrap><abbr title="%s">%s</abbr></td> """ % (action_params(s), "parameters") classstring = "action" else: type_html_info = """<td nowrap><abbr title="%s">%s</abbr></td> """ % (typestring(s), nodetype) classstring = s.keyword element_html_info = """ <td nowrap> <div id=9999 class=tier%s> <a class="%s"> </a> %s </div> </td> """ % (level, classstring, attr_html_info) fd.write(""" <tr id="%s" class="a"> %s <td nowrap>%s</td> %s <td nowrap>%s</td> <td>%s</td> <td>%s</td> <td nowrap>%s</td> </tr>""" % (idstring, element_html_info, classstring, type_html_info, flags, options, status, pathstr)) if hasattr(s, 'i_children'): level += 1 chs = s.i_children if path is not None and len(path) > 0: chs = [ch for ch in chs if ch.arg == path[0]] path = path[1:] if s.keyword in ['choice', 'case']: print_children(chs, module, fd, prefix, path, ctx, level) else: print_children(chs, module, fd, prefix, path, ctx, level)