Commit f1fb21bd authored by Michael Tremer's avatar Michael Tremer

location: Fix output of list-* commands

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent b767db8d
......@@ -47,13 +47,15 @@ class OutputWriter(object):
# Enable network flattening (i.e. networks cannot overlap)
flatten = False
def __init__(self, name, family=None, directory=None):
def __init__(self, name, family=None, directory=None, f=None):
self.name = name
self.family = family
self.directory = directory
# Open output file
if self.directory:
if f:
self.f = f
elif self.directory:
self.f = open(self.filename, self.mode)
elif "b" in self.mode:
self.f = io.BytesIO()
......
......@@ -514,7 +514,7 @@ class CLI(object):
writer = self.__get_output_formatter(ns)
for asn in ns.asn:
f = writer(sys.stdout, prefix="AS%s" % asn)
f = writer("AS%s" % asn, f=sys.stdout)
# Print all matching networks
for n in db.search_networks(asns=[asn], family=ns.family):
......@@ -527,7 +527,7 @@ class CLI(object):
for country_code in ns.country_code:
# Open standard output
f = writer(sys.stdout, prefix=country_code)
f = writer(country_code, f=sys.stdout)
# Print all matching networks
for n in db.search_networks(country_codes=[country_code], family=ns.family):
......@@ -554,7 +554,7 @@ class CLI(object):
raise ValueError(_("You must at least pass one flag"))
writer = self.__get_output_formatter(ns)
f = writer(sys.stdout, prefix="custom")
f = writer("custom", f=sys.stdout)
for n in db.search_networks(flags=flags, family=ns.family):
f.write(n)
......@@ -563,7 +563,7 @@ class CLI(object):
def handle_list_bogons(self, db, ns):
writer = self.__get_output_formatter(ns)
f = writer(sys.stdout, prefix="bogons")
f = writer("bogons", f=sys.stdout)
for n in db.list_bogons(family=ns.family):
f.write(n)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment