From d40d40af31aa878baf0ec4bf826b89ea6fb1b20b Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sat, 25 May 2019 19:50:54 +0300 Subject: [PATCH] [Core] Update to support libtorrent 1.2 Some changes between lt 1.1 and 1.2 require updates to core code. - Switch from proxy_type to proxy_type_t - Replace hardcoded flag value with add_torrent_params_flags_t since 1.2 uses different flag values. - add_torrent_params requires flags set instead of dict values. Refs: #3255 --- deluge/core/preferencesmanager.py | 8 ++++---- deluge/tests/test_core.py | 9 ++++++++- deluge/tests/test_torrent.py | 16 ++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index e3c935c99..db9556acc 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -426,7 +426,7 @@ class PreferencesManager(component.Component): def _on_set_proxy(self, key, value): # Initialise with type none and blank hostnames. proxy_settings = { - 'proxy_type': lt.proxy_type.none, + 'proxy_type': lt.proxy_type_t.none, 'i2p_hostname': '', 'proxy_hostname': '', 'proxy_hostnames': value['proxy_hostnames'], @@ -436,15 +436,15 @@ class PreferencesManager(component.Component): 'anonymous_mode': value['anonymous_mode'], } - if value['type'] == lt.proxy_type.i2p_proxy: + if value['type'] == lt.proxy_type_t.i2p_proxy: proxy_settings.update( { - 'proxy_type': lt.proxy_type.i2p_proxy, + 'proxy_type': lt.proxy_type_t.i2p_proxy, 'i2p_hostname': value['hostname'], 'i2p_port': value['port'], } ) - elif value['type'] != lt.proxy_type.none: + elif value['type'] != lt.proxy_type_t.none: proxy_settings.update( { 'proxy_type': value['type'], diff --git a/deluge/tests/test_core.py b/deluge/tests/test_core.py index 4f64c73e6..15fbc1bcf 100644 --- a/deluge/tests/test_core.py +++ b/deluge/tests/test_core.py @@ -23,6 +23,7 @@ from twisted.web.static import File import deluge.common import deluge.component as component import deluge.core.torrent +from deluge._libtorrent import lt from deluge.core.core import Core from deluge.core.rpcserver import RPCServer from deluge.error import AddTorrentError, InvalidTorrentError @@ -116,7 +117,13 @@ class CoreTestCase(BaseTestCase): def add_torrent(self, filename, paused=False): if not paused: # Patch libtorrent flags starting torrents paused - self.patch(deluge.core.torrentmanager, 'LT_DEFAULT_ADD_TORRENT_FLAGS', 592) + self.patch( + deluge.core.torrentmanager, + 'LT_DEFAULT_ADD_TORRENT_FLAGS', + lt.add_torrent_params_flags_t.flag_auto_managed + | lt.add_torrent_params_flags_t.flag_update_subscribe + | lt.add_torrent_params_flags_t.flag_apply_ip_filter, + ) options = {'add_paused': paused, 'auto_managed': False} filepath = common.get_test_data_file(filename) with open(filepath, 'rb') as _file: diff --git a/deluge/tests/test_torrent.py b/deluge/tests/test_torrent.py index 43d355bba..7bbe79ed8 100644 --- a/deluge/tests/test_torrent.py +++ b/deluge/tests/test_torrent.py @@ -73,12 +73,16 @@ class TorrentTestCase(BaseTestCase): filename = common.get_test_data_file(filename) with open(filename, 'rb') as _file: info = lt.torrent_info(lt.bdecode(_file.read())) - atp = {'ti': info} - atp['save_path'] = os.getcwd() - atp['storage_mode'] = lt.storage_mode_t.storage_mode_sparse - atp['add_paused'] = False - atp['auto_managed'] = True - atp['duplicate_is_error'] = True + atp = { + 'ti': info, + 'save_path': os.getcwd(), + 'storage_mode': lt.storage_mode_t.storage_mode_sparse, + 'flags': ( + lt.add_torrent_params_flags_t.flag_auto_managed + | lt.add_torrent_params_flags_t.flag_duplicate_is_error + & ~lt.add_torrent_params_flags_t.flag_paused + ), + } return atp def test_set_file_priorities(self):