]> git.ipfire.org Git - pbs.git/commitdiff
Use IPFire Location for location information
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 May 2022 16:13:03 +0000 (16:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 May 2022 16:13:03 +0000 (16:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
README
src/buildservice/__init__.py
src/buildservice/mirrors.py

index bec950b1d3881b8e2c717e7de7118fc2a8fbbad2..c492618ab962e1b9d031b3a23184b94c80ba6701 100644 (file)
@@ -85,7 +85,6 @@ buildservice_PYTHON = \
        src/buildservice/database.py \
        src/buildservice/decorators.py \
        src/buildservice/distribution.py \
-       src/buildservice/geoip.py \
        src/buildservice/git.py \
        src/buildservice/jobqueue.py \
        src/buildservice/jobs.py \
@@ -425,14 +424,8 @@ databasedir = $(datadir)/database
 EXTRA_DIST += \
        src/crontab/pakfire-build-service
 
-dist_geoip_DATA = \
-       src/geoip/GeoLite2-Country.mmdb
-
-geoipdir = $(datadir)/geoip
-
 EXTRA_DIST += \
-       src/tools/dump-database-schema.sh \
-       src/tools/update-geoip-database.sh
+       src/tools/dump-database-schema.sh
 
 # ------------------------------------------------------------------------------
 
diff --git a/README b/README
index 40da6cbe405d7a3a2ef6e6bd542eedaf778b323d..9093afb027496c70ec706f74d41eb90906fc8470 100644 (file)
--- a/README
+++ b/README
@@ -1,13 +1,4 @@
-
-REQUIREMENTS
-       Python modules:
-               * geoip2
-
 TRANSLATE
        Help translating the build service!
 
        http://pootle.ipfire.org/projects/pakfire-build-service/
-
-
-This product includes GeoLite2 data created by MaxMind, available from
-  https://dev.maxmind.com/geoip/geoip2/geolite2/
index d26f92d96b17935a81402283ec2c49e0be60747a..6a7a783455016ccdb086550d79dee24d820bc8cd 100644 (file)
@@ -14,7 +14,6 @@ from . import builds
 from . import cache
 from . import database
 from . import distribution
-from . import geoip
 from . import jobqueue
 from . import jobs
 from . import keys
@@ -52,7 +51,6 @@ class Backend(object):
                self.arches      = arches.Arches(self)
                self.builds      = builds.Builds(self)
                self.cache       = cache.Cache(self)
-               self.geoip       = geoip.GeoIP(self)
                self.jobs        = jobs.Jobs(self)
                self.builders    = builders.Builders(self)
                self.distros     = distribution.Distributions(self)
index 374c9eabf875f345815fc282f22a1642603cda21..45c8ea7ba1770616650a527e13ee2171dc0929ee 100644 (file)
@@ -8,6 +8,8 @@ import time
 import tornado.httpclient
 import urllib.parse
 
+import location
+
 from . import base
 from . import logs
 
@@ -17,6 +19,9 @@ log.propagate = 1
 from .decorators import lazy_property
 
 class Mirrors(base.Object):
+       def init(self):
+               self.location = location.Database("/var/lib/location/database.db")
+
        def _get_mirror(self, query, *args):
                res = self.db.get(query, *args)
 
@@ -60,14 +65,14 @@ class Mirrors(base.Object):
                        WHERE hostname = %s AND deleted IS FALSE", hostname)
 
        def make_mirrorlist(self, client_address=None):
-               country_code = self.backend.geoip.guess_from_address(client_address)
+               network = self.location.lookup(client_address)
 
                # Walk through all mirrors in a random order
                # and put all preferred mirrors to the front of the list
                # and everything else at the end
                mirrors = []
                for mirror in self.random:
-                       if mirror.is_preferred_for_country(country_code):
+                       if mirror.is_preferred_for_country(network.country_code if network else None):
                                mirrors.insert(0, mirror)
                        else:
                                mirrors.append(mirror)
@@ -269,7 +274,12 @@ class Mirror(base.DataObject):
 
        @lazy_property
        def country_code(self):
-               return self.backend.geoip.guess_from_address(self.address) or "UNKNOWN"
+               network = self.location.lookup(self.address)
+
+               if network:
+                       return network.country_code
+
+               return "UNKNOWN"
 
        def get_history(self, *args, **kwargs):
                kwargs["mirror"] = self