# debug aid. the daemon will write a textual representation of trees to # /tmp/lvrouted.tree*. this will take such a file and convert it to Tree.make # statements, which can then be compiled and debugged with. import sys def make_node(line, depth, make_children): addr = line.split()[0] eth = str('eth' in line).lower() gw = str('gw' in line).lower() cs = "[" + "; ".join(make_children(depth + 1)) + "]" return "Tree.make (Unix.inet_addr_of_string \"%s\") %s %s %s" % \ (addr, eth, gw, cs) lines = open(sys.argv[1]).readlines() lineno = 0 def foo(depth): global lineno, lines nodes = [] while lineno < len(lines): line = lines[lineno] this_depth = line.count('\t') if this_depth != depth: return nodes lineno = lineno + 1 if lineno == len(lines): return nodes nodes.append(make_node(line, depth, foo)) return nodes print foo(0)[0] """ 172.16.6.113 (eth) 172.16.4.148 172.20.145.1 172.20.145.65 172.16.4.145 172.16.17.116 172.20.144.1 172.16.5.233 172.16.17.132 172.16.5.185 172.21.0.1 172.16.5.9 172.16.5.60 172.16.4.236 172.19.0.1 172.16.4.228 172.16.4.225 172.16.3.164 172.16.3.148 172.17.53.1 172.16.3.146 172.16.3.121 172.17.55.1 172.16.3.97 172.17.54.1 172.16.17.217 172.16.3.169 172.16.3.172 172.16.17.220 172.17.43.1 172.16.17.145 172.19.8.1 172.16.17.148 172.16.5.121 172.16.3.137 172.16.3.138 (eth) 172.16.17.137 172.16.16.20 172.19.137.65 172.19.136.1 172.16.4.97 172.17.44.1 172.16.17.185 172.17.2.65 172.16.16.17 172.16.16.113 172.16.17.188 172.17.0.2 172.17.7.1 172.17.0.1 172.16.16.116 172.16.16.121 172.16.3.49 172.16.3.52 172.17.21.1 172.16.16.105 172.19.133.1 172.16.16.69 172.16.16.108 172.17.2.1 172.16.5.124 172.16.5.132 172.16.5.129 172.16.5.140 172.21.144.1 172.16.5.137 172.16.6.65 172.16.3.161 172.21.160.1 172.16.4.233 172.16.5.180 172.16.5.177 172.16.5.172 (gw) 172.16.5.169 172.18.49.72 172.18.49.1 172.18.49.71 (eth) 172.18.48.1 172.16.3.41 172.16.3.44 172.16.2.57 172.16.5.201 172.21.168.65 172.21.168.1 172.16.5.193 172.16.4.57 172.16.5.57 172.16.3.89 172.16.5.12 172.16.5.116 (gw) 172.16.5.113 172.16.4.169 172.17.25.1 172.16.17.196 172.17.140.1 172.16.17.209 172.16.17.201 172.16.17.204 172.16.3.212 172.18.128.1 (gw) 172.17.29.1 172.16.4.129 172.16.5.65 172.16.4.132 172.16.3.25 172.16.4.177 172.17.144.1 172.16.3.209 172.16.3.177 172.16.3.76 172.16.4.1 172.16.176.65 172.16.4.4 172.16.3.220 172.19.132.1 172.16.3.217 172.16.3.58 (eth) 172.17.30.1 172.16.4.172 172.17.0.21 172.16.0.34 (eth) 172.17.137.1 172.17.139.1 172.16.16.249 172.16.16.252 172.16.5.244 172.16.5.241 172.17.136.1 172.16.0.33 172.16.16.81 172.17.141.1 172.16.17.193 172.16.3.180 172.16.3.188 172.16.7.57 172.16.3.61 (eth) 172.17.82.1 172.16.3.129 172.17.87.1 (gw) 172.16.3.62 (gw) 172.17.88.1 (gw) 172.16.7.188 172.16.7.193 172.17.113.1 172.17.112.1 172.16.7.65 (gw) 172.16.7.185 (gw) 172.16.7.60 172.17.8.1 172.16.3.185 172.16.3.73 172.16.5.89 172.16.4.73 172.16.4.249 172.16.4.204 172.16.6.252 172.17.5.1 172.16.4.186 172.16.4.196 172.16.4.185 (eth) 172.16.17.225 172.16.7.44 172.17.86.1 172.16.7.41 172.16.17.228 172.16.3.132 172.19.152.1 172.16.5.161 172.17.3.1 172.16.16.1 172.16.4.76 172.16.4.153 172.17.45.1 172.16.176.66 172.16.4.156 172.19.131.1 172.16.3.57 (eth) 172.16.4.89 172.16.4.92 172.19.174.1 172.17.46.1 172.17.47.1 172.17.175.71 (eth) 172.16.16.44 172.16.16.49 172.17.48.1 172.17.0.25 172.16.16.52 172.17.42.1 172.17.24.1 172.17.174.1 172.16.16.41 172.16.16.60 172.16.5.29 172.21.8.1 172.16.1.1 172.16.16.57 172.17.0.17 172.17.26.1 172.16.4.201 172.16.4.252 172.17.19.1 172.17.15.1 172.16.4.180 172.17.17.1 172.16.4.193 172.17.175.73 172.16.5.68 172.17.175.72 (eth) 172.16.4.140 172.16.4.161 172.16.8.1 172.17.64.1 172.16.4.164 172.16.6.20 172.20.128.1 172.17.4.1 172.16.4.124 172.16.4.28 172.17.65.1 172.16.3.21 172.16.4.25 172.17.16.129 172.16.3.85 172.17.16.1 172.16.4.121 172.16.4.33 172.16.4.137 172.16.4.9 172.16.4.100 172.19.137.66 (eth) 172.16.3.193 172.19.137.1 172.16.4.36 172.17.117.1 172.16.3.251 172.22.0.1 172.16.3.155 172.16.4.12 172.16.4.81 172.16.4.84 172.16.3.2 (eth) 172.17.99.1 (gw) 172.17.98.1 (gw) 172.17.97.1 (gw) 172.16.3.1 (gw) 172.16.3.204 (gw) 172.16.3.201 (eth) 172.17.100.1 172.16.5.220 172.16.5.217 (eth) 172.19.128.65 172.17.35.1 172.19.128.67 (eth) 172.16.6.129 172.19.135.1 172.16.17.233 172.16.17.236 172.16.17.76 172.17.81.1 172.16.6.89 172.16.6.233 172.16.3.244 (eth) 172.25.90.68 (eth) 172.16.16.233 172.17.74.1 172.16.16.241 172.16.16.137 172.16.16.140 172.17.77.1 172.16.16.148 172.17.79.1 172.16.6.209 172.16.16.236 (gw) 172.16.16.145 (gw) 172.16.6.153 (gw) 172.16.16.76 172.17.2.129 172.16.16.225 172.17.11.1 172.16.6.156 172.16.7.145 (eth) 172.16.7.105 172.17.96.1 172.16.7.148 172.17.94.1 172.16.16.73 (gw) 172.17.14.1 (gw) 172.17.10.1 (gw) 172.16.16.33 (gw) 172.16.16.100 (gw) 172.16.16.36 172.17.12.1 172.17.0.129 172.17.0.193 172.25.90.65 (gw) 172.25.90.67 (eth) 172.17.0.36 172.17.75.1 172.16.16.89 172.17.92.1 172.17.0.33 172.17.9.1 172.27.8.1 172.16.3.241 172.16.4.45 172.16.17.244 172.23.24.1 172.16.17.73 172.16.17.241 172.16.17.97 172.16.17.100 172.19.128.68 (eth) 172.19.128.66 (eth) 172.22.8.1 172.16.16.129 172.16.0.165 172.17.103.1 172.16.5.228 (gw) 172.20.8.1 (gw) 172.16.3.153 172.24.0.1 172.24.0.65 172.17.93.1 172.17.176.1 172.16.5.92 (gw) 172.17.169.66 (gw) 172.17.169.1 (gw) 172.16.3.90 (eth) 172.16.5.41 172.16.5.44 172.17.61.1 172.16.5.105 172.17.67.1 172.16.3.225 172.16.6.4 172.17.50.1 172.16.7.100 (eth) 172.17.95.1 (gw) 172.17.52.1 172.17.51.1 172.16.7.97 172.17.66.1 172.16.7.177 172.16.6.172 172.17.68.1 172.16.7.228 172.16.6.105 172.16.6.1 172.16.3.228 (eth) 172.17.105.1 172.16.7.129 172.17.106.1 172.16.7.4 172.17.49.1 172.16.6.169 172.17.58.1 172.16.18.28 172.16.6.161 172.16.5.249 172.16.7.225 172.16.6.249 172.16.7.233 172.16.7.217 172.17.118.1 172.16.4.217 172.17.62.1 172.17.63.1 172.16.4.220 172.16.4.108 172.16.7.209 (eth) 172.17.78.1 172.16.7.252 172.16.7.1 172.16.6.217 172.17.115.1 172.17.116.1 172.17.60.1 172.16.4.105 172.17.59.1 172.16.5.108 172.21.1.1 172.16.5.25 172.16.5.49 172.16.5.2 172.16.5.36 172.16.5.33 172.16.4.244 172.16.5.76 172.16.5.84 172.16.7.212 172.17.114.1 172.16.7.201 172.17.22.1 (gw) 172.16.5.81 (gw) 172.17.27.1 (gw) 172.16.5.73 (gw) 172.16.5.153 172.16.3.12 172.16.5.212 172.25.64.1 172.25.64.65 172.16.5.252 172.16.6.57 172.16.18.44 172.16.6.73 172.25.52.1 172.16.18.25 172.25.56.1 172.16.6.76 172.17.28.1 (gw) 172.17.33.1 (gw) 172.16.5.209 172.16.5.145 172.17.1.1 172.16.5.148 172.16.5.101 172.16.6.177 172.17.32.1 172.16.3.33 172.17.31.1 172.16.6.196 172.16.5.98 172.16.6.193 172.16.6.137 172.17.76.1 172.17.80.1 172.16.7.49 172.16.6.225 172.16.6.185 172.16.6.140 (eth) 172.16.7.73 172.17.89.1 172.17.91.1 172.17.90.1 172.16.4.116 172.16.4.113 (eth) 172.16.6.145 172.16.253.2 (eth) 172.16.3.108 172.16.6.25 172.23.16.1 172.23.16.65 172.16.6.81 172.16.6.36 172.17.0.81 172.16.3.113 172.16.3.105 172.16.6.97 172.16.17.252 172.16.18.9 172.16.7.244 172.27.16.1 172.16.7.241 (eth) 172.16.3.93 (gw) 172.17.119.1 (gw) 172.16.3.94 172.16.9.20 172.17.121.1 172.17.122.1 172.17.120.1 172.16.9.9 172.16.9.1 (gw) 172.16.18.17 172.17.23.1 172.16.4.17 172.16.6.33 172.23.13.1 172.16.3.116 172.16.17.249 172.16.6.244 172.17.70.1 172.23.25.1 172.17.41.1 172.16.253.1 172.16.6.148 172.16.18.1 172.16.18.4 172.27.0.1 172.16.17.65 172.16.17.68 172.17.69.1 172.16.17.89 172.23.12.1 172.16.6.241 172.16.6.9 172.16.17.92 172.23.26.1 172.23.26.65 172.16.7.81 172.16.7.52 (eth) 172.17.109.1 172.17.111.1 172.17.110.1 172.24.16.1 172.16.18.41 172.18.32.1 172.16.4.241 172.16.3.9 172.16.5.17 172.16.5.52 172.16.4.52 172.16.4.49 172.27.129.65 172.16.16.169 172.27.129.1 172.16.16.172 172.17.13.65 172.17.20.1 172.17.13.1 172.27.129.129 172.17.57.1 172.17.56.1 172.16.17.129 172.16.6.114 (gw) 172.17.36.1 (gw) 172.17.34.1 (gw)"""