- Timestamp:
- Jul 28, 2015, 9:11:25 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r13325 r13327 1043 1043 """).render(datadump) 1044 1044 1045 1046 def make_table(table): 1047 if not table: 1048 return " - none\n" 1049 else: 1050 lines = "" 1051 col_width = [max(len(x) for x in col) for col in zip(*table)] 1052 for row in table: 1053 lines += " - " + " || ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(row)) + "\n" 1054 return lines 1055 1045 1056 (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump) 1046 # Just nasty hack to make the formatting looks nice 1047 iface_len = max(map(len,addrs_list.keys())) 1048 addr_len = max(map(len,[x[0] for x in [x[0] for x in addrs_list.values()]])) 1057 table = [] 1049 1058 for iface,addrs in sorted(addrs_list.iteritems()): 1050 1059 if iface in ['lo0']: 1051 1060 continue 1052 1061 for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])): 1053 output += " - %s || %s || %s\n" % (iface.ljust(iface_len), addr.ljust(addr_len), comment) 1054 1062 table.append((iface, addr, comment)) 1063 1064 output += make_table(table) 1055 1065 output += '\n' 1056 1066 output += """\ 1057 Attached bridges:1067 Attached devices: 1058 1068 """ 1059 has_item = False1069 table = [] 1060 1070 for iface_key in datadump['autogen_iface_keys']: 1061 1071 ifacedump = datadump[iface_key] 1062 1072 if ifacedump.has_key('ns_ip'): 1063 ifacedump['autogen_ns_ip'] = ifacedump['ns_ip'].split('/')[0] 1064 has_item = True 1065 ifacedump['autogen_protocol'] = 'https' if 'M' in ifacedump['bridge_type'] else 'http' 1066 output += " - %(autogen_ifname)s || %(mode)s || %(autogen_protocol)s://%(autogen_ns_ip)s\n" % ifacedump 1067 if not has_item: 1068 output += " - none\n" 1069 1073 x_ip = ifacedump['ns_ip'].split('/')[0] 1074 x_proto = 'https' if 'M' in ifacedump['bridge_type'] else 'http' 1075 table.append((ifacedump['autogen_ifname'], ifacedump['mode'], "%s://%s" % (x_proto, x_ip))) 1076 1077 output += make_table(table) 1070 1078 output += '\n' 1071 1079 output += """\ … … 1078 1086 continue 1079 1087 1080 # Some formatting quirks1081 iface_len = max(map(len,addrs_list.keys()))1082 addr_len = max(map(len,[x[0] for x in [x[0] for x in addrs_list.values()]]))1083 1084 1088 for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])): 1085 1089 if not addr.startswith('172.'): … … 1090 1094 table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_ifname'] + ")", neighbour[1]['comment'])) 1091 1095 1092 if not table: 1093 # This should be considered very odd as it indicate no active connections to other nodes 1094 output += " - none\n" 1095 else: 1096 col_width = [max(len(x) for x in col) for col in zip(*table)] 1097 for row in table: 1098 output += " - " + " || ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(row)) + "\n" 1099 1096 output += make_table(table) 1100 1097 1101 1098 return output … … 1949 1946 datadumps[datadump['autogen_realname']] = datadump 1950 1947 1951 (poel, errors) = make_relations( datadumps)1948 (poel, errors) = make_relations() 1952 1949 print "\n".join(["# WARNING: %s" % x for x in errors]) 1953 1950
Note:
See TracChangeset
for help on using the changeset viewer.