From 7c2a3ba493d9b966ce685e864389e09783521a2e Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Mon, 11 Oct 2010 23:47:42 +0000 Subject: We've already built a resource_set by the time we find a match, might as well use it to prettify our output. svn path=/scripts/csvgrep.py; revision=3479 --- scripts/csvgrep.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'scripts/csvgrep.py') diff --git a/scripts/csvgrep.py b/scripts/csvgrep.py index 823785bd..7c419021 100644 --- a/scripts/csvgrep.py +++ b/scripts/csvgrep.py @@ -45,16 +45,22 @@ for datum in sys.argv[1:]: #print "Looking for: ASNs %s IPv4 %s IPv6 %s" % (asn, ipv4, ipv6) -def matches(resource_set, datum): - return resource_set.intersection(resource_set.__class__(datum)) +def matches(set1, datum): + set2 = set1.__class__(datum) + if set1.intersection(set2): + return set2 + else: + return False if asn: for h, a in rpki.myrpki.csv_reader("asns.csv", columns = 2): - if matches(asn, a): - print h, a + m = matches(asn, a) + if m: + print h, m if ipv4 or ipv6: for h, a in rpki.myrpki.csv_reader("prefixes.csv", columns = 2): t = ipv6 if ":" in a else ipv4 - if t and matches(t, a): - print h, a + m = t and matches(t, a) + if m: + print h, m -- cgit v1.2.3