From ba6f30dad1451e0f2400fc3414fced67d6b9df04 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 26 Jul 2009 03:26:18 +0000 Subject: [PATCH] Add a deluge._libtorrent module to handle importing libtorrent Use the new module --- deluge/_libtorrent.py | 52 +++++++++++++++++++++++++++++++ deluge/core/alertmanager.py | 7 +---- deluge/core/autoadd.py | 7 +---- deluge/core/core.py | 11 +++---- deluge/core/oldstateupgrader.py | 7 +---- deluge/core/preferencesmanager.py | 7 +---- deluge/core/torrent.py | 7 +---- deluge/core/torrentmanager.py | 7 +---- 8 files changed, 62 insertions(+), 43 deletions(-) create mode 100644 deluge/_libtorrent.py diff --git a/deluge/_libtorrent.py b/deluge/_libtorrent.py new file mode 100644 index 000000000..095206726 --- /dev/null +++ b/deluge/_libtorrent.py @@ -0,0 +1,52 @@ +# +# _libtorrent.py +# +# Copyright (C) 2009 Andrew Resch +# +# Deluge is free software. +# +# You may redistribute it and/or modify it under the terms of the +# GNU General Public License, as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) +# any later version. +# +# deluge is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with deluge. If not, write to: +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. +# +# + +""" +This module is used to handle the importing of libtorrent. + +We use this module to control what versions of libtorrent this version of Deluge +supports. + +** Usage ** + +>>> from deluge._libtorrent import lt + +""" +try: + import deluge.libtorrent as lt +except ImportError: + import libtorrent as lt + if not (lt.version_major == 0 and lt.version_minor == 14): + raise ImportError("This version of Deluge requires libtorrent 0.14!") diff --git a/deluge/core/alertmanager.py b/deluge/core/alertmanager.py index 9e28947ae..ef4ff6783 100644 --- a/deluge/core/alertmanager.py +++ b/deluge/core/alertmanager.py @@ -44,12 +44,7 @@ This should typically only be used by the Core. Plugins should utilize the from twisted.internet import reactor import deluge.component as component -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") +from deluge._libtorrent import lt from deluge.log import LOG as log diff --git a/deluge/core/autoadd.py b/deluge/core/autoadd.py index d3387a281..136b57d8c 100644 --- a/deluge/core/autoadd.py +++ b/deluge/core/autoadd.py @@ -36,12 +36,7 @@ import os -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") +from deluge._libtorrent import lt import deluge.component as component from deluge.configmanager import ConfigManager diff --git a/deluge/core/core.py b/deluge/core/core.py index cf1065b03..622c4706d 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -1,7 +1,7 @@ # # core.py # -# Copyright (C) 2007, 2008 Andrew Resch +# Copyright (C) 2007-2009 Andrew Resch # # Deluge is free software. # @@ -33,6 +33,8 @@ # # +from deluge._libtorrent import lt + import os import glob import base64 @@ -49,12 +51,7 @@ import twisted.web.client from deluge.httpdownloader import download_file from deluge.log import LOG as log -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") + import deluge.configmanager import deluge.common diff --git a/deluge/core/oldstateupgrader.py b/deluge/core/oldstateupgrader.py index 7d0de754a..840418316 100644 --- a/deluge/core/oldstateupgrader.py +++ b/deluge/core/oldstateupgrader.py @@ -40,12 +40,7 @@ import pickle import cPickle import shutil -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") +from deluge._libtorrent import lt from deluge.configmanager import ConfigManager import deluge.core.torrentmanager diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index d743de13c..07a08ba35 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -40,12 +40,7 @@ import pkg_resources from twisted.internet import reactor from twisted.internet.task import LoopingCall -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") +from deluge._libtorrent import lt from deluge.event import * import deluge.configmanager diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 94898b20e..872823b44 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -38,12 +38,7 @@ import os import time from urlparse import urlparse -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") +from deluge._libtorrent import lt import deluge.common import deluge.component as component diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 65a939066..ed61e99ef 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -45,12 +45,7 @@ import operator from twisted.internet import reactor from twisted.internet.task import LoopingCall -try: - import deluge.libtorrent as lt -except ImportError: - import libtorrent as lt - if not (lt.version_major == 0 and lt.version_minor == 14): - raise ImportError("This version of Deluge requires libtorrent 0.14!") +from deluge._libtorrent import lt from deluge.event import *