Changeset 13327 in genesis for tools


Ignore:
Timestamp:
Jul 28, 2015, 9:11:25 AM (9 years ago)
Author:
rick
Message:

Get rid of the formatting quircks for the tables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r13325 r13327  
    10431043""").render(datadump)
    10441044
     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
    10451056  (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 = []
    10491058  for iface,addrs in sorted(addrs_list.iteritems()):
    10501059    if iface in ['lo0']:
    10511060      continue
    10521061    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)
    10551065  output += '\n'
    10561066  output += """\
    1057 Attached bridges:
     1067Attached devices:
    10581068"""
    1059   has_item = False
     1069  table = []
    10601070  for iface_key in datadump['autogen_iface_keys']:
    10611071    ifacedump = datadump[iface_key]
    10621072    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)
    10701078  output += '\n'
    10711079  output += """\
     
    10781086      continue
    10791087
    1080     # Some formatting quirks
    1081     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 
    10841088    for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])):
    10851089      if not addr.startswith('172.'):
     
    10901094          table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_ifname'] + ")", neighbour[1]['comment']))
    10911095
    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)
    11001097
    11011098  return output
     
    19491946        datadumps[datadump['autogen_realname']] = datadump
    19501947
    1951       (poel, errors) = make_relations(datadumps)
     1948      (poel, errors) = make_relations()
    19521949      print "\n".join(["# WARNING: %s" % x for x in errors])
    19531950
Note: See TracChangeset for help on using the changeset viewer.