From: Michael Tremer Date: Wed, 25 May 2022 16:13:03 +0000 (+0000) Subject: Use IPFire Location for location information X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d897466de49af153ac59f7c19b0f91fb291ccaa;p=pbs.git Use IPFire Location for location information Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index bec950b1..c492618a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 40da6cbe..9093afb0 100644 --- 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/ diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index d26f92d9..6a7a7834 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -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) diff --git a/src/buildservice/mirrors.py b/src/buildservice/mirrors.py index 374c9eab..45c8ea7b 100644 --- a/src/buildservice/mirrors.py +++ b/src/buildservice/mirrors.py @@ -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