aboutsummaryrefslogtreecommitdiff
path: root/myrpki
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2009-12-22 20:59:49 +0000
committerRob Austein <sra@hactrn.net>2009-12-22 20:59:49 +0000
commitdc143998330c129e037f2adcdba1d2fb116e3548 (patch)
tree6607b1a601330f9da5d4a3071bf7a3d1d696dc29 /myrpki
parent2f5d4c8f5cdf89d93594bcaaed2bc2dc6e032439 (diff)
Generate something that could be construed as CSV in a sufficiently bad light.
svn path=/myrpki/ripe-to-csv.py; revision=2901
Diffstat (limited to 'myrpki')
-rw-r--r--myrpki/ripe-to-csv.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/myrpki/ripe-to-csv.py b/myrpki/ripe-to-csv.py
index e700e669..8166d682 100644
--- a/myrpki/ripe-to-csv.py
+++ b/myrpki/ripe-to-csv.py
@@ -65,15 +65,32 @@ class as_set(Handle):
class aut_num(Handle):
want_tags = ("aut-num", "mnt-by", "as-name")
+ def set(self, tag, val):
+ if tag == "aut-num" and val.startswith("AS"):
+ val = val[2:]
+ Handle.set(self, tag, val)
+
+ def finish(self, ctx):
+ if self.check():
+ ctx.asns.writerow((self["mnt-by"], self["aut-num"]))
+
class inetnum(Handle):
want_tags = ("inetnum", "mnt-by", "netname")
+ def finish(self, ctx):
+ if self.check():
+ ctx.prefixes.writerow((self["mnt-by"], self["inetnum"]))
+
class inet6num(Handle):
want_tags = ("inet6num", "mnt-by", "netname")
+ def finish(self, ctx):
+ if self.check():
+ ctx.prefixes.writerow((self["mnt-by"], self["inet6num"]))
+
class main(object):
- types = dict((x.want_tags[0], x) for x in (as_block, aut_num, as_set, inetnum, inet6num))
+ types = dict((x.want_tags[0], x) for x in (as_block, as_set, aut_num, inetnum, inet6num))
@staticmethod
def csvout(fn):
@@ -83,8 +100,8 @@ class main(object):
if self.statement:
tag, sep, val = self.statement.partition(":")
assert sep, "Couldn't find separator in %r" % self.statement
- tag = tag.strip()
- val = val.strip()
+ tag = tag.strip().lower()
+ val = val.strip().upper()
if self.cur is None:
self.cur = self.types[tag]() if tag in self.types else False
if self.cur is not False:
@@ -93,19 +110,24 @@ class main(object):
self.cur.finish(self)
self.cur = None
+ #filenames = ("ripe.db.gz",)
+ filenames = ("ripe.db.aut-num.gz", "ripe.db.inet6num.gz", "ripe.db.inetnum.gz")
+
def __init__(self):
self.asns = self.csvout("asns.csv")
self.prefixes = self.csvout("prefixes.csv")
- f = gzip.open("ripe.db.gz")
- self.statement = ""
- self.cur = None
- for line in f:
- line = line.expandtabs().partition("#")[0].rstrip("\n")
- if line and not line[0].isalpha():
- self.statement += line[1:] if line[0] == "+" else line
- else:
- self.finish_statement(not line)
- self.statement = line
- self.finish_statement(True)
+ for fn in self.filenames:
+ f = gzip.open(fn)
+ self.statement = ""
+ self.cur = None
+ for line in f:
+ line = line.expandtabs().partition("#")[0].rstrip("\n")
+ if line and not line[0].isalpha():
+ self.statement += line[1:] if line[0] == "+" else line
+ else:
+ self.finish_statement(not line)
+ self.statement = line
+ self.finish_statement(True)
+ f.close()
main()