]> git.ipfire.org Git - location/libloc.git/commitdiff
location-query: Include flags in dump output
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 15 May 2020 12:08:52 +0000 (12:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 15 May 2020 12:08:52 +0000 (12:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location-query.in

index 0d1510ad4d3e2036f320d36589dfdab3f8b48f3a..2e03b946e1ede64314b271e0b893c3d9dc30a0df 100644 (file)
@@ -312,6 +312,9 @@ class CLI(object):
                # Use output file or write to stdout
                f = ns.output or sys.stdout
 
+               # Format everything like this
+               format = "%-24s %s\n"
+
                # Write metadata
                f.write("#\n# Location Database Export\n#\n")
 
@@ -336,19 +339,30 @@ class CLI(object):
                # Iterate over all ASes
                for a in db.ases:
                        f.write("\n")
-                       f.write("aut-num:        AS%s\n" % a.number)
-                       f.write("name:           %s\n" % a.name)
+                       f.write(format % ("aut-num:", "AS%s" % a.number))
+                       f.write(format % ("name:", a.name))
+
+               flags = {
+                       location.NETWORK_FLAG_ANONYMOUS_PROXY    : "is-anonymous-proxy:",
+                       location.NETWORK_FLAG_SATELLITE_PROVIDER : "is-satellite-provider:",
+                       location.NETWORK_FLAG_ANYCAST            : "is-anycast:",
+               }
 
                # Iterate over all networks
                for n in db.networks:
                        f.write("\n")
-                       f.write("net:            %s\n" % n)
+                       f.write(format % ("net:", n))
 
                        if n.country_code:
-                               f.write("country:        %s\n" % n.country_code)
+                               f.write(format % ("country:", n.country_code))
 
                        if n.asn:
-                               f.write("autnum:         %s\n" % n.asn)
+                               f.write(format % ("autnum:", n.asn))
+
+                       # Print all flags
+                       for flag in flags:
+                               if n.has_flag(flag):
+                                       f.write(format % (flags[flag], "yes"))
 
        def handle_get_as(self, db, ns):
                """