]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/python/export.py
as: Add list for easier processing
[people/ms/libloc.git] / src / python / export.py
index be4a68efb2fc36b762288bdb9d8346f2e8223fd7..f675eb312db6eff401df619c1e4e5c57597cb3d8 100644 (file)
@@ -29,7 +29,7 @@ import _location
 log = logging.getLogger("location.export")
 log.propagate = 1
 
-flags = {
+FLAGS = {
        _location.NETWORK_FLAG_ANONYMOUS_PROXY    : "A1",
        _location.NETWORK_FLAG_SATELLITE_PROVIDER : "A2",
        _location.NETWORK_FLAG_ANYCAST            : "A3",
@@ -184,8 +184,20 @@ class Exporter(object):
 
                                writers[asn] = self.writer.open(self.db, filename, prefix="AS%s" % asn)
 
+                       # Filter countries from special country codes
+                       country_codes = [
+                               country_code for country_code in countries if not country_code in FLAGS.values()
+                       ]
+
+                       # Collect flags
+                       flags = 0
+                       for flag in FLAGS:
+                               if FLAGS[flag] in countries:
+                                       flags |= flag
+
                        # Get all networks that match the family
-                       networks = self.db.search_networks(family=family, flatten=True)
+                       networks = self.db.search_networks(family=family,
+                               country_codes=country_codes, asns=asns, flags=flags, flatten=True)
 
                        # Walk through all networks
                        for network in networks:
@@ -202,10 +214,10 @@ class Exporter(object):
                                        pass
 
                                # Handle flags
-                               for flag in flags:
+                               for flag in FLAGS:
                                        if network.has_flag(flag):
                                                # Fetch the "fake" country code
-                                               country = flags[flag]
+                                               country = FLAGS[flag]
 
                                                try:
                                                        writers[country].write(network)