]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/python/location-importer.in
Bump database version to "1"
[people/ms/libloc.git] / src / python / location-importer.in
index 36a525ee5bffbdba05196437844e8abe4eb8f97c..eb4a303b80aa0d375f3184e893f2cf8981a154ed 100644 (file)
@@ -70,6 +70,7 @@ class CLI(object):
                write.add_argument("--vendor", nargs="?", help=_("Sets the vendor"))
                write.add_argument("--description", nargs="?", help=_("Sets a description"))
                write.add_argument("--license", nargs="?", help=_("Sets the license"))
+               write.add_argument("--version", type=int, help=_("Database Format Version"))
 
                # Update WHOIS
                update_whois = subparsers.add_parser("update-whois", help=_("Update WHOIS Information"))
@@ -155,6 +156,7 @@ class CLI(object):
                                CREATE TABLE IF NOT EXISTS autnum_overrides(
                                        number bigint NOT NULL,
                                        name text,
+                                       country text,
                                        is_anonymous_proxy boolean DEFAULT FALSE,
                                        is_satellite_provider boolean DEFAULT FALSE,
                                        is_anycast boolean DEFAULT FALSE
@@ -221,7 +223,21 @@ class CLI(object):
                                DISTINCT ON (announcements.network)
                                announcements.network AS network,
                                announcements.autnum AS autnum,
-                               networks.country AS country,
+
+                               -- Country
+                               COALESCE(
+                                       (
+                                               SELECT country FROM network_overrides overrides
+                                                       WHERE announcements.network <<= overrides.network
+                                                       ORDER BY masklen(overrides.network) DESC
+                                                       LIMIT 1
+                                       ),
+                                       (
+                                               SELECT country FROM autnum_overrides overrides
+                                                       WHERE announcements.autnum = overrides.number
+                                       ),
+                                       networks.country
+                               ) AS country,
 
                                -- Must be part of returned values for ORDER BY clause
                                masklen(networks.network) AS sort,
@@ -448,7 +464,6 @@ class CLI(object):
                server = ns.server[0]
 
                # Pre-compile regular expression for routes
-               #route = re.compile(b"^\*>?\s[\si]?([^\s]+)[.\s]*?(\d+)\si$", re.MULTILINE)
                route = re.compile(b"^\*[\s\>]i([^\s]+).+?(\d+)\si\r\n", re.MULTILINE|re.DOTALL)
 
                with telnetlib.Telnet(server) as t:
@@ -457,8 +472,10 @@ class CLI(object):
                        #       t.set_debuglevel(10)
 
                        # Wait for console greeting
-                       greeting = t.read_until(b"> ")
-                       log.debug(greeting.decode())
+                       greeting = t.read_until(b"> ", timeout=30)
+                       if not greeting:
+                               log.error("Could not get a console prompt")
+                               return 1
 
                        # Disable pagination
                        t.write(b"terminal length 0\n")
@@ -611,8 +628,8 @@ class CLI(object):
                                                                block.get("is-anycast") == "yes",
                                                        )
 
-                                               elif type == "autnum":
-                                                       autnum = block.get("autnum")
+                                               elif type == "aut-num":
+                                                       autnum = block.get("aut-num")
 
                                                        # Check if AS number begins with "AS"
                                                        if not autnum.startswith("AS"):
@@ -626,12 +643,15 @@ class CLI(object):
                                                                INSERT INTO autnum_overrides(
                                                                        number,
                                                                        name,
+                                                                       country,
                                                                        is_anonymous_proxy,
                                                                        is_satellite_provider,
                                                                        is_anycast
-                                                               ) VALUES(%s, %s, %s, %s, %s)
+                                                               ) VALUES(%s, %s, %s, %s, %s, %s)
                                                                ON CONFLICT DO NOTHING""",
-                                                               autnum, block.get("name"),
+                                                               autnum,
+                                                               block.get("name"),
+                                                               block.get("country"),
                                                                block.get("is-anonymous-proxy") == "yes",
                                                                block.get("is-satellite-provider") == "yes",
                                                                block.get("is-anycast") == "yes",