From 65e5010e7fbdef6cf484368cf8375e9f142a4e69 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Mon, 17 Jun 2019 17:21:44 +0100 Subject: [PATCH] [Core] Add pygeoip dependency support Provide support for the pure-python pygeoip as compiled GeoIP is not always available. Ref: https://dev.deluge-torrent.org/ticket/3271 --- DEPENDS.md | 2 +- deluge/core/preferencesmanager.py | 16 +++++++++------- requirements.txt | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DEPENDS.md b/DEPENDS.md index 04d95c8a2..31fdfd0c3 100644 --- a/DEPENDS.md +++ b/DEPENDS.md @@ -41,7 +41,7 @@ All modules will require the [common](#common) section dependencies. ## Core (deluged daemon) - [libtorrent] _>= 1.1.1_ -- [GeoIP] - Optional: IP address location lookup. (_Debian: `python-geoip`_) +- [GeoIP] or [pygeoip] - Optional: IP address country lookup. (_Debian: `python-geoip`_) ## GTK UI diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index 42e4eb6f2..79e960252 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -23,10 +23,14 @@ import deluge.configmanager from deluge._libtorrent import lt from deluge.event import ConfigValueChangedEvent +GeoIP = None try: - import GeoIP + from GeoIP import GeoIP except ImportError: - GeoIP = None + try: + from pygeoip import GeoIP + except ImportError: + pass log = logging.getLogger(__name__) @@ -456,11 +460,9 @@ class PreferencesManager(component.Component): # Load the GeoIP DB for country look-ups if available if os.path.exists(geoipdb_path): try: - self.core.geoip_instance = GeoIP.open( - geoipdb_path, GeoIP.GEOIP_STANDARD - ) - except AttributeError: - log.warning('GeoIP Unavailable') + self.core.geoip_instance = GeoIP(geoipdb_path, 0) + except Exception as ex: + log.warning('GeoIP Unavailable: %s', ex) else: log.warning('Unable to find GeoIP database file: %s', geoipdb_path) diff --git a/requirements.txt b/requirements.txt index 800b45828..655595d98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ certifi; sys_platform == 'win32' windows-curses; sys_platform == 'win32' zope.interface>=4.4.2 distro; 'linux' in sys_platform or 'bsd' in sys_platform +pygeoip