[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
This commit is contained in:
Calum Lind 2019-06-17 17:21:44 +01:00 committed by Calum Lind
parent 9b97c74025
commit 65e5010e7f
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
3 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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