diff --git a/experiment/popularity_community/initial_filling.py b/experiment/popularity_community/initial_filling.py index 7575d7effaf..c39849bf92f 100644 --- a/experiment/popularity_community/initial_filling.py +++ b/experiment/popularity_community/initial_filling.py @@ -13,7 +13,7 @@ from ipv8.peerdiscovery.discovery import RandomWalk from ipv8_service import IPv8 from tribler_core.components.ipv8.ipv8_component import Ipv8Component -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.popularity import PopularityComponent diff --git a/src/seedbox/disseminator.py b/src/seedbox/disseminator.py index 17da5139b33..2a19c3d7fd7 100644 --- a/src/seedbox/disseminator.py +++ b/src/seedbox/disseminator.py @@ -30,14 +30,14 @@ from tribler_core.components.gigachannel.gigachannel_component import GigaChannelComponent from tribler_core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent from tribler_core.components.ipv8.ipv8_component import Ipv8Component -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.restapi import RESTComponent from tribler_core.components.socks_configurator import SocksServersComponent from tribler_core.config.tribler_config import TriblerConfig -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.utilities.tiny_tribler_service import TinyTriblerService # fmt: off diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py b/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py index e502889ea5a..7f44ec22af6 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py @@ -8,9 +8,9 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING, NTFY -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_node import COMMITTED from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT from tribler_core.components.metadata_store.db.store import MetadataStore diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager_component.py b/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager_component.py index 7d1887c81d1..a5406691567 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager_component.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager_component.py @@ -1,5 +1,5 @@ from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.restapi import RestfulComponent diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py index 95301542472..911fc6658dd 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py @@ -12,7 +12,7 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.tests.tools.base_test import MockObject @@ -104,7 +104,7 @@ async def mock_remove_download(download_obj, **_): # Test regenerating a non-empty channel gigachannel_manager.updated_my_channel = Mock() metadata_store.ChannelMetadata.consolidate_channel_torrent = lambda *_: Mock() - with patch("tribler_core.modules.libtorrent.torrentdef.TorrentDef.load_from_dict"): + with patch("tribler_core.components.libtorrent.torrentdef.TorrentDef.load_from_dict"): await gigachannel_manager.regenerate_channel_torrent(chan_pk, chan_id) gigachannel_manager.updated_my_channel.assert_called_once() diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py index fa44df9bb99..ccab01318ad 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py @@ -1,15 +1,12 @@ -from unittest.mock import patch - import pytest from tribler_core.components.base import Session from tribler_core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.restapi import RESTComponent from tribler_core.components.socks_configurator import SocksServersComponent -from tribler_core.restapi.rest_manager import RESTManager # pylint: disable=protected-access diff --git a/src/tribler-core/tribler_core/components/libtorrent/__init__.py b/src/tribler-core/tribler_core/components/libtorrent/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-core/tribler_core/components/libtorrent/download_manager/__init__.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-core/tribler_core/modules/libtorrent/download.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py similarity index 97% rename from src/tribler-core/tribler_core/modules/libtorrent/download.py rename to src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py index a94f2a649f0..2a278e99667 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/download.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py @@ -16,16 +16,15 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING, DLSTATUS_STOPPED, DOWNLOAD, NTFY from tribler_core.exceptions import SaveResumeDataError -from tribler_core.modules.libtorrent import check_handle, require_handle -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.download_state import DownloadState -from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings -from tribler_core.modules.libtorrent.stream import Stream -from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_state import DownloadState +from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings +from tribler_core.components.libtorrent.download_manager.stream import Stream +from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo from tribler_core.notifier import Notifier -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path -from tribler_core.utilities.torrent_utils import get_info_from_handle +from tribler_core.components.libtorrent.utils.torrent_utils import check_handle, get_info_from_handle, require_handle from tribler_core.utilities.unicode import ensure_unicode, hexlify from tribler_core.utilities.utilities import bdecode_compat diff --git a/src/tribler-core/tribler_core/modules/libtorrent/download_config.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py similarity index 97% rename from src/tribler-core/tribler_core/modules/libtorrent/download_config.py rename to src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py index f31fdf13e65..84ae36171b6 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/download_config.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py @@ -8,15 +8,14 @@ from tribler_core.exceptions import InvalidConfigException from tribler_core.utilities.install_dir import get_lib_path -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path from tribler_core.utilities.utilities import bdecode_compat SPEC_FILENAME = 'download_config.spec' -CONFIG_SPEC_PATH = get_lib_path() / 'modules' / 'libtorrent' / SPEC_FILENAME +CONFIG_SPEC_PATH = get_lib_path() / 'components/libtorrent/download_manager' / SPEC_FILENAME NONPERSISTENT_DEFAULTS = {} - class DownloadConfig: def __init__(self, config=None, state_dir=None): self.config = config or ConfigObj(configspec=str(CONFIG_SPEC_PATH), default_encoding='utf8') diff --git a/src/tribler-core/tribler_core/modules/libtorrent/download_config.spec b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.spec similarity index 100% rename from src/tribler-core/tribler_core/modules/libtorrent/download_config.spec rename to src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.spec diff --git a/src/tribler-core/tribler_core/modules/libtorrent/download_manager.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py similarity index 98% rename from src/tribler-core/tribler_core/modules/libtorrent/download_manager.py rename to src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py index 162ceb36678..80fc72d7c55 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/download_manager.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py @@ -20,13 +20,14 @@ from tribler_common.utilities import uri_to_path from tribler_core.modules.dht_health_manager import DHTHealthManager -from tribler_core.modules.libtorrent.download import Download -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings -from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo +from tribler_core.components.libtorrent.download_manager.download import Download +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings +from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo from tribler_core.notifier import Notifier -from tribler_core.utilities import path_util, torrent_utils -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.utilities import path_util +from tribler_core.components.libtorrent.utils import torrent_utils +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import bdecode_compat, has_bep33_support, parse_magnetlink diff --git a/src/tribler-core/tribler_core/modules/libtorrent/download_state.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_state.py similarity index 100% rename from src/tribler-core/tribler_core/modules/libtorrent/download_state.py rename to src/tribler-core/tribler_core/components/libtorrent/download_manager/download_state.py diff --git a/src/tribler-core/tribler_core/modules/libtorrent/stream.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py similarity index 99% rename from src/tribler-core/tribler_core/modules/libtorrent/stream.py rename to src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py index 977d6faaf89..48fe8413b95 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/stream.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py @@ -22,8 +22,7 @@ from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING -from tribler_core.modules.libtorrent import check_vod -from tribler_core.utilities.torrent_utils import get_info_from_handle +from tribler_core.components.libtorrent.utils.torrent_utils import check_vod, get_info_from_handle # Header and footer sizes are necessary for video client to detect file codecs and muxer metadata. # Without below pieces are ready, streamer should not start diff --git a/src/tribler-core/tribler_core/components/libtorrent.py b/src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py similarity index 95% rename from src/tribler-core/tribler_core/components/libtorrent.py rename to src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py index 0aa9d5e65aa..be9f348d3cc 100644 --- a/src/tribler-core/tribler_core/components/libtorrent.py +++ b/src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py @@ -4,7 +4,7 @@ from tribler_core.components.restapi import RestfulComponent from tribler_core.components.socks_configurator import SocksServersComponent from tribler_core.components.upgrade import UpgradeComponent -from tribler_core.modules.libtorrent.download_manager import DownloadManager +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager class LibtorrentComponent(RestfulComponent): diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/__init__.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/create_torrent_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/create_torrent_endpoint.py similarity index 96% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/create_torrent_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/create_torrent_endpoint.py index eb29b5abb15..85b19dbce3e 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/restapi/create_torrent_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/create_torrent_endpoint.py @@ -10,8 +10,8 @@ from marshmallow.fields import String from tribler_core.exceptions import DuplicateDownloadException -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.restapi.rest_endpoint import HTTP_BAD_REQUEST, RESTEndpoint, RESTResponse from tribler_core.restapi.schema import HandledErrorSchema from tribler_core.restapi.util import return_handled_exception diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/downloads_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py similarity index 98% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/downloads_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py index 78e1d926778..8cf58feb0be 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/restapi/downloads_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py @@ -20,9 +20,9 @@ dlstatus_strings, ) -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.stream import STREAM_PAUSE_TIME, StreamChunk +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.download_manager.stream import STREAM_PAUSE_TIME, StreamChunk from tribler_core.restapi.rest_endpoint import ( HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR, @@ -32,7 +32,7 @@ RESTStreamResponse, ) from tribler_core.restapi.util import return_handled_exception -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path from tribler_core.utilities.unicode import ensure_unicode, hexlify from tribler_core.utilities.utilities import froze_it diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/libtorrent_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/libtorrent_endpoint.py similarity index 100% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/libtorrent_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/libtorrent_endpoint.py diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/__init__.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_downloads_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py similarity index 99% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_downloads_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py index 66456161bbc..d5e084108b9 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_downloads_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py @@ -10,8 +10,8 @@ from tribler_common.simpledefs import DLSTATUS_CIRCUITS, DLSTATUS_DOWNLOADING, DLSTATUS_EXIT_NODES, DLSTATUS_STOPPED -from tribler_core.modules.libtorrent.download_state import DownloadState -from tribler_core.modules.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint, get_extended_status +from tribler_core.components.libtorrent.download_manager.download_state import DownloadState +from tribler_core.components.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint, get_extended_status from tribler_core.restapi.base_api_test import do_request from tribler_core.restapi.rest_manager import error_middleware from tribler_core.tests.tools.common import TESTS_DATA_DIR diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_libtorrent_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_libtorrent_endpoint.py similarity index 97% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_libtorrent_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_libtorrent_endpoint.py index ed10256f0ae..a09cea9193b 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_libtorrent_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_libtorrent_endpoint.py @@ -4,7 +4,7 @@ import pytest -from tribler_core.modules.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint +from tribler_core.components.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint from tribler_core.restapi.base_api_test import do_request from tribler_core.restapi.rest_manager import error_middleware from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_torrentinfo_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py similarity index 95% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_torrentinfo_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py index c12ace0bec4..924554f614a 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/restapi/tests/test_torrentinfo_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py @@ -13,8 +13,8 @@ from tribler_common.simpledefs import NTFY -from tribler_core.modules.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import tdef_to_metadata_dict from tribler_core.restapi.base_api_test import do_request from tribler_core.restapi.rest_manager import error_middleware @@ -79,7 +79,7 @@ async def mock_http_query(*_): with open(tmp_path / "ubuntu.torrent", 'rb') as f: return f.read() - with patch("tribler_core.modules.libtorrent.restapi.torrentinfo_endpoint.query_http_uri", new=mock_http_query): + with patch("tribler_core.components.libtorrent.restapi.torrentinfo_endpoint.query_http_uri", new=mock_http_query): verify_valid_dict(await do_request(rest_api, f'torrentinfo?uri={quote_plus(path)}', expected_code=200)) path = quote_plus(f'magnet:?xt=urn:btih:{hexlify(UBUNTU_1504_INFOHASH)}' diff --git a/src/tribler-core/tribler_core/modules/libtorrent/restapi/torrentinfo_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py similarity index 97% rename from src/tribler-core/tribler_core/modules/libtorrent/restapi/torrentinfo_endpoint.py rename to src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py index 61304ff0de3..4efe1de8a61 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/restapi/torrentinfo_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py @@ -13,10 +13,10 @@ from tribler_common.simpledefs import NTFY from tribler_common.utilities import uri_to_path -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import tdef_to_metadata_dict from tribler_core.restapi.rest_endpoint import HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR, RESTEndpoint, RESTResponse -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.unicode import hexlify, recursive_unicode from tribler_core.utilities.utilities import bdecode_compat, froze_it, parse_magnetlink diff --git a/src/tribler-core/tribler_core/modules/libtorrent/settings.py b/src/tribler-core/tribler_core/components/libtorrent/settings.py similarity index 94% rename from src/tribler-core/tribler_core/modules/libtorrent/settings.py rename to src/tribler-core/tribler_core/components/libtorrent/settings.py index 7e69bc0cbdf..4ec3ade28e2 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/settings.py +++ b/src/tribler-core/tribler_core/components/libtorrent/settings.py @@ -7,7 +7,7 @@ # pylint: disable=no-self-argument from tribler_core.config.tribler_config_section import TriblerConfigSection -from tribler_core.modules.libtorrent.download_config import get_default_dest_dir +from tribler_core.components.libtorrent.download_manager.download_config import get_default_dest_dir @validator('port', 'anon_listen_port') diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/__init__.py b/src/tribler-core/tribler_core/components/libtorrent/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/conftest.py b/src/tribler-core/tribler_core/components/libtorrent/tests/conftest.py similarity index 82% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/conftest.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/conftest.py index 1ace4931799..fccb5f5b181 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/conftest.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/conftest.py @@ -1,6 +1,6 @@ import pytest -from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo +from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo @pytest.fixture diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download.py similarity index 98% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_download.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_download.py index 7f34bb6ec15..a2cea81392c 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download.py @@ -10,10 +10,10 @@ import pytest from tribler_core.exceptions import SaveResumeDataError -from tribler_core.modules.libtorrent.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.tests.tools.base_test import MockObject from tribler_core.tests.tools.common import TESTS_DATA_DIR -from tribler_core.utilities.torrent_utils import get_info_from_handle +from tribler_core.components.libtorrent.utils.torrent_utils import get_info_from_handle from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import bdecode_compat diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_api.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py similarity index 100% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_api.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_config.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_config.py similarity index 94% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_config.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_download_config.py index 2bb4ebbf6e2..202341232dc 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_config.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_config.py @@ -4,7 +4,7 @@ import pytest -from tribler_core.modules.libtorrent.download_config import DownloadConfig, get_default_dest_dir +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig, get_default_dest_dir from tribler_core.tests.tools.common import TESTS_DATA_DIR diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_manager.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py similarity index 98% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_manager.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py index 23f2742a8f2..0e106a5d95e 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_manager.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py @@ -9,9 +9,9 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.settings import LibtorrentSettings -from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.settings import LibtorrentSettings +from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo from tribler_core.tests.tools.common import TESTS_DATA_DIR, TORRENT_UBUNTU_FILE from tribler_core.utilities.path_util import Path from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_state.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py similarity index 97% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_state.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py index bace1ff3ed3..245564e5ed7 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_download_state.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py @@ -4,7 +4,7 @@ from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DOWNLOAD, UPLOAD -from tribler_core.modules.libtorrent.download_state import DownloadState +from tribler_core.components.libtorrent.download_manager.download_state import DownloadState @pytest.fixture diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_component.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_component.py new file mode 100644 index 00000000000..12a18e78a66 --- /dev/null +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_component.py @@ -0,0 +1,24 @@ +import pytest + +from tribler_core.components.base import Session +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent +from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent +from tribler_core.components.restapi import RESTComponent +from tribler_core.components.socks_configurator import SocksServersComponent + +pytestmark = pytest.mark.asyncio + + +# pylint: disable=protected-access + +async def test_libtorrent_component(tribler_config): + components = [RESTComponent(), MasterKeyComponent(), SocksServersComponent(), LibtorrentComponent()] + session = Session(tribler_config, components) + with session: + await session.start() + + comp = LibtorrentComponent.instance() + assert comp.started_event.is_set() and not comp.failed + assert comp.download_manager + + await session.shutdown() diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_libtorrent_settings.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py similarity index 90% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_libtorrent_settings.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py index 430ea696ce8..ad1a838e3f1 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_libtorrent_settings.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py @@ -2,7 +2,7 @@ from tribler_common.network_utils import NetworkUtils -from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings, SeedingMode +from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings, SeedingMode @pytest.mark.asyncio diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_seeding.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py similarity index 89% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_seeding.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py index 5ac45e16eb8..6d50a471d95 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_seeding.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py @@ -7,7 +7,7 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING -from tribler_core.modules.libtorrent.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.tests.tools.common import TESTS_DATA_DIR diff --git a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_torrent_def.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_torrent_def.py similarity index 98% rename from src/tribler-core/tribler_core/modules/libtorrent/tests/test_torrent_def.py rename to src/tribler-core/tribler_core/components/libtorrent/tests/test_torrent_def.py index b301da3fffc..016c4befd5b 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/tests/test_torrent_def.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_torrent_def.py @@ -6,7 +6,7 @@ import pytest -from tribler_core.modules.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo +from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo from tribler_core.tests.tools.common import TESTS_DATA_DIR, TORRENT_UBUNTU_FILE from tribler_core.utilities.path_util import Path from tribler_core.utilities.utilities import bdecode_compat diff --git a/src/tribler-core/tribler_core/modules/libtorrent/torrentdef.py b/src/tribler-core/tribler_core/components/libtorrent/torrentdef.py similarity index 99% rename from src/tribler-core/tribler_core/modules/libtorrent/torrentdef.py rename to src/tribler-core/tribler_core/components/libtorrent/torrentdef.py index 0d20e8808c5..96cdd927fe1 100644 --- a/src/tribler-core/tribler_core/modules/libtorrent/torrentdef.py +++ b/src/tribler-core/tribler_core/components/libtorrent/torrentdef.py @@ -9,9 +9,9 @@ from tribler_common.simpledefs import INFOHASH_LENGTH from tribler_core.utilities import maketorrent, path_util -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path -from tribler_core.utilities.torrent_utils import create_torrent_file +from tribler_core.components.libtorrent.utils.torrent_utils import create_torrent_file from tribler_core.utilities.unicode import ensure_unicode from tribler_core.utilities.utilities import bdecode_compat, is_valid_url, parse_magnetlink diff --git a/src/tribler-core/tribler_core/components/libtorrent/utils/__init__.py b/src/tribler-core/tribler_core/components/libtorrent/utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-core/tribler_core/utilities/libtorrent_helper.py b/src/tribler-core/tribler_core/components/libtorrent/utils/libtorrent_helper.py similarity index 100% rename from src/tribler-core/tribler_core/utilities/libtorrent_helper.py rename to src/tribler-core/tribler_core/components/libtorrent/utils/libtorrent_helper.py diff --git a/src/tribler-core/tribler_core/utilities/torrent_utils.py b/src/tribler-core/tribler_core/components/libtorrent/utils/torrent_utils.py similarity index 71% rename from src/tribler-core/tribler_core/utilities/torrent_utils.py rename to src/tribler-core/tribler_core/components/libtorrent/utils/torrent_utils.py index b48f1b2e598..1848726aed1 100644 --- a/src/tribler-core/tribler_core/utilities/torrent_utils.py +++ b/src/tribler-core/tribler_core/components/libtorrent/utils/torrent_utils.py @@ -1,12 +1,61 @@ import logging +from asyncio import CancelledError, Future +from contextlib import suppress from hashlib import sha1 -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path logger = logging.getLogger(__name__) +def check_handle(default=None): + """ + Return the libtorrent handle if it's available, else return the default value. + Author(s): Egbert Bouman + """ + def wrap(f): + def invoke_func(*args, **kwargs): + download = args[0] + if download.handle and download.handle.is_valid(): + return f(*args, **kwargs) + return default + return invoke_func + return wrap + + +def require_handle(func): + """ + Invoke the function once the handle is available. Returns a future that will fire once the function has completed. + Author(s): Egbert Bouman + """ + def invoke_func(*args, **kwargs): + result_future = Future() + + def done_cb(fut): + with suppress(CancelledError): + handle = fut.result() + if not fut.cancelled() and not result_future.done() and handle == download.handle and handle.is_valid(): + result_future.set_result(func(*args, **kwargs)) + download = args[0] + handle_future = download.get_handle() + handle_future.add_done_callback(done_cb) + return result_future + return invoke_func + + +def check_vod(default=None): + """ + Check if torrent is vod mode, else return default + """ + def wrap(f): + def invoke_func(self, *args, **kwargs): + if self.enabled: + return f(self, *args, **kwargs) + return default + return invoke_func + return wrap + def commonprefix(paths_list): # this unlike the os path .commonprefix version always returns path prefixes as it compares # path component wise. diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py index 8b7327e6df7..17d6553d5ec 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py @@ -25,7 +25,7 @@ ChannelMetadataPayload, HealthItemsPayload, ) -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.path_util import Path from tribler_core.utilities.random_utils import random_infohash from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py index 2e7a8d7af3f..dbb86a3298d 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py @@ -20,7 +20,7 @@ from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, \ CollectionNodePayload from tribler_core.exceptions import DuplicateTorrentFileError -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.utilities.random_utils import random_infohash diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_torrent_metadata.py b/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_torrent_metadata.py index bbb055f51ba..cac281e11f9 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_torrent_metadata.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_torrent_metadata.py @@ -8,7 +8,7 @@ import pytest -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.discrete_clock import clock from tribler_core.components.metadata_store.db.orm_bindings.channel_node import TODELETE from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import tdef_to_metadata_dict diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py index d8aea7bde9b..3c428f37e82 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py @@ -17,7 +17,7 @@ from tribler_common.simpledefs import CHANNEL_STATE -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_node import DIRTY_STATUSES, NEW from tribler_core.components.metadata_store.restapi.metadata_endpoint_base import MetadataEndpointBase from tribler_core.components.metadata_store.restapi.metadata_schema import ChannelSchema diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py index 5efcd5ac211..15397023730 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py @@ -14,7 +14,7 @@ from tribler_common.simpledefs import CHANNEL_STATE -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.gigachannel.community.gigachannel_community import NoChannelSourcesException from tribler_core.components.metadata_store.restapi.channels_endpoint import ChannelsEndpoint from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT diff --git a/src/tribler-core/tribler_core/components/metadata_store/tests/gen_test_data.py b/src/tribler-core/tribler_core/components/metadata_store/tests/gen_test_data.py index 3bedc3f7c42..54c0b211f8a 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/tests/gen_test_data.py +++ b/src/tribler-core/tribler_core/components/metadata_store/tests/gen_test_data.py @@ -6,7 +6,7 @@ from pony.orm import db_session -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.components.metadata_store.db.store import MetadataStore from tribler_core.components.metadata_store.tests.test_channel_download import ( diff --git a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py index 8cc88e3edc7..747a7e4beea 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py +++ b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py @@ -8,10 +8,10 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.settings import LibtorrentSettings -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.settings import LibtorrentSettings +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager from tribler_core.components.metadata_store.db.serialization import ChannelMetadataPayload from tribler_core.tests.tools.common import TESTS_DATA_DIR diff --git a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py index 7c7e5a1b67d..a738c6202cb 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py +++ b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py @@ -15,7 +15,7 @@ from tribler_common.simpledefs import CHANNEL_STATE -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import ( CHANNEL_DIR_NAME_LENGTH, MetadataCompressor, diff --git a/src/tribler-core/tribler_core/components/tests/test_tribler_components.py b/src/tribler-core/tribler_core/components/tests/test_tribler_components.py index 6828f24a493..72e387db510 100644 --- a/src/tribler-core/tribler_core/components/tests/test_tribler_components.py +++ b/src/tribler-core/tribler_core/components/tests/test_tribler_components.py @@ -3,7 +3,7 @@ from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler_core.components.base import Session, SessionError from tribler_core.components.ipv8.ipv8_component import Ipv8Component -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.payout import PayoutComponent @@ -47,21 +47,6 @@ def test_session_context_manager(loop, tribler_config): Session.current() -async def test_libtorrent_component(tribler_config): - tribler_config.libtorrent.enabled = True - tribler_config.chant.enabled = True - components = [RESTComponent(), MasterKeyComponent(), SocksServersComponent(), LibtorrentComponent()] - session = Session(tribler_config, components) - with session: - await session.start() - - comp = LibtorrentComponent.instance() - assert comp.started_event.is_set() and not comp.failed - assert comp.download_manager - - await session.shutdown() - - async def test_payout_component(tribler_config): tribler_config.ipv8.enabled = True components = [BandwidthAccountingComponent(), MasterKeyComponent(), RESTComponent(), Ipv8Component(), diff --git a/src/tribler-core/tribler_core/components/torrent_checker.py b/src/tribler-core/tribler_core/components/torrent_checker.py index a3560af0013..6a6e0fbc71c 100644 --- a/src/tribler-core/tribler_core/components/torrent_checker.py +++ b/src/tribler-core/tribler_core/components/torrent_checker.py @@ -1,6 +1,6 @@ from tribler_common.simpledefs import STATE_START_TORRENT_CHECKER -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.restapi import RestfulComponent from tribler_core.components.socks_configurator import SocksServersComponent diff --git a/src/tribler-core/tribler_core/components/tunnels.py b/src/tribler-core/tribler_core/components/tunnels.py index b73b8bcce03..e3b37c7c83d 100644 --- a/src/tribler-core/tribler_core/components/tunnels.py +++ b/src/tribler-core/tribler_core/components/tunnels.py @@ -3,7 +3,7 @@ from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler_core.components.ipv8.ipv8_component import INFINITE, Ipv8Component -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.restapi import RestfulComponent from tribler_core.components.socks_configurator import SocksServersComponent from tribler_core.modules.tunnel.community.community import TriblerTunnelCommunity, TriblerTunnelTestnetCommunity diff --git a/src/tribler-core/tribler_core/components/watch_folder.py b/src/tribler-core/tribler_core/components/watch_folder.py index f40ad32a888..ed02a2dae83 100644 --- a/src/tribler-core/tribler_core/components/watch_folder.py +++ b/src/tribler-core/tribler_core/components/watch_folder.py @@ -1,6 +1,6 @@ from tribler_common.simpledefs import STATE_START_WATCH_FOLDER -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.restapi import RestfulComponent from tribler_core.modules.watch_folder.watch_folder import WatchFolder diff --git a/src/tribler-core/tribler_core/config/tribler_config_sections.py b/src/tribler-core/tribler_core/config/tribler_config_sections.py index c82c0c3011f..5429cb58e0f 100644 --- a/src/tribler-core/tribler_core/config/tribler_config_sections.py +++ b/src/tribler-core/tribler_core/config/tribler_config_sections.py @@ -5,7 +5,7 @@ from tribler_core.components.masterkey.settings import BootstrapSettings, DHTSettings, DiscoveryCommunitySettings, \ Ipv8Settings, \ TrustchainSettings, WatchFolderSettings -from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings +from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings from tribler_core.modules.popularity.settings import PopularityCommunitySettings from tribler_core.modules.remote_query_community.settings import RemoteQueryCommunitySettings from tribler_core.modules.resource_monitor.settings import ResourceMonitorSettings diff --git a/src/tribler-core/tribler_core/conftest.py b/src/tribler-core/tribler_core/conftest.py index 90d9af97381..59a761a4c31 100644 --- a/src/tribler-core/tribler_core/conftest.py +++ b/src/tribler-core/tribler_core/conftest.py @@ -14,11 +14,11 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING from tribler_core.config.tribler_config import TriblerConfig -from tribler_core.modules.libtorrent.download import Download -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.settings import LibtorrentSettings -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download import Download +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.settings import LibtorrentSettings +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.store import MetadataStore from tribler_core.tests.tools.common import TESTS_DATA_DIR, TESTS_DIR from tribler_core.tests.tools.tracker.udp_tracker import UDPTracker diff --git a/src/tribler-core/tribler_core/modules/bootstrap.py b/src/tribler-core/tribler_core/modules/bootstrap.py index f34eb083e17..9c936b93217 100644 --- a/src/tribler-core/tribler_core/modules/bootstrap.py +++ b/src/tribler-core/tribler_core/modules/bootstrap.py @@ -5,8 +5,8 @@ from ipv8.dht import DHTError from ipv8.taskmanager import TaskManager -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.torrentdef import TorrentDefNoMetainfo +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.torrentdef import TorrentDefNoMetainfo from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/modules/dht_health_manager.py b/src/tribler-core/tribler_core/modules/dht_health_manager.py index 5dbbfbc53be..eec961b2163 100644 --- a/src/tribler-core/tribler_core/modules/dht_health_manager.py +++ b/src/tribler-core/tribler_core/modules/dht_health_manager.py @@ -1,10 +1,9 @@ import math from asyncio import Future -from ipv8.dht.routing import distance from ipv8.taskmanager import TaskManager -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/modules/libtorrent/__init__.py b/src/tribler-core/tribler_core/modules/libtorrent/__init__.py deleted file mode 100644 index 6ba3366aa51..00000000000 --- a/src/tribler-core/tribler_core/modules/libtorrent/__init__.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -The Libtorrent package contains code to manage the torrent library. - -Author(s): Egbert Bouman -""" -from asyncio import CancelledError, Future -from contextlib import suppress - - -def check_handle(default=None): - """ - Return the libtorrent handle if it's available, else return the default value. - """ - def wrap(f): - def invoke_func(*args, **kwargs): - download = args[0] - if download.handle and download.handle.is_valid(): - return f(*args, **kwargs) - return default - return invoke_func - return wrap - - -def require_handle(func): - """ - Invoke the function once the handle is available. Returns a future that will fire once the function has completed. - """ - def invoke_func(*args, **kwargs): - result_future = Future() - - def done_cb(fut): - with suppress(CancelledError): - handle = fut.result() - if not fut.cancelled() and not result_future.done() and handle == download.handle and handle.is_valid(): - result_future.set_result(func(*args, **kwargs)) - download = args[0] - handle_future = download.get_handle() - handle_future.add_done_callback(done_cb) - return result_future - return invoke_func - - -def check_vod(default=None): - """ - Check if torrent is vod mode, else return default - """ - def wrap(f): - def invoke_func(self, *args, **kwargs): - if self.enabled: - return f(self, *args, **kwargs) - return default - return invoke_func - return wrap diff --git a/src/tribler-core/tribler_core/modules/torrent_checker/torrent_checker.py b/src/tribler-core/tribler_core/modules/torrent_checker/torrent_checker.py index d6d1d046fa9..c02770bed29 100644 --- a/src/tribler-core/tribler_core/modules/torrent_checker/torrent_checker.py +++ b/src/tribler-core/tribler_core/modules/torrent_checker/torrent_checker.py @@ -12,7 +12,7 @@ from tribler_common.simpledefs import NTFY from tribler_core.config.tribler_config import TriblerConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.metadata_store.db.store import MetadataStore from tribler_core.modules.torrent_checker.torrentchecker_session import ( FakeBep33DHTSession, diff --git a/src/tribler-core/tribler_core/modules/tunnel/test_full_session/test_tunnel_community.py b/src/tribler-core/tribler_core/modules/tunnel/test_full_session/test_tunnel_community.py index 6db712a6e93..6be9dc038c0 100644 --- a/src/tribler-core/tribler_core/modules/tunnel/test_full_session/test_tunnel_community.py +++ b/src/tribler-core/tribler_core/modules/tunnel/test_full_session/test_tunnel_community.py @@ -23,10 +23,10 @@ # Pylint does not agree with the way pytest handles fixtures. # pylint: disable=W0613,W0621 from tribler_core.components.socks_configurator import NUM_SOCKS_PROXIES -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.settings import LibtorrentSettings -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.settings import LibtorrentSettings +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.modules.tunnel.community.community import TriblerTunnelCommunity from tribler_core.modules.tunnel.community.settings import TunnelCommunitySettings from tribler_core.modules.tunnel.socks5.server import Socks5Server diff --git a/src/tribler-core/tribler_core/modules/watch_folder/watch_folder.py b/src/tribler-core/tribler_core/modules/watch_folder/watch_folder.py index 0180a41bb1e..c7f9f0ff8fe 100644 --- a/src/tribler-core/tribler_core/modules/watch_folder/watch_folder.py +++ b/src/tribler-core/tribler_core/modules/watch_folder/watch_folder.py @@ -4,8 +4,8 @@ from ipv8.taskmanager import TaskManager from tribler_common.simpledefs import NTFY -from tribler_core.modules.libtorrent.download_manager import DownloadManager -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.notifier import Notifier from tribler_core.utilities import path_util diff --git a/src/tribler-core/tribler_core/restapi/root_endpoint.py b/src/tribler-core/tribler_core/restapi/root_endpoint.py index 55174c48b0e..f71f83ea033 100644 --- a/src/tribler-core/tribler_core/restapi/root_endpoint.py +++ b/src/tribler-core/tribler_core/restapi/root_endpoint.py @@ -2,10 +2,10 @@ from tribler_core.config.tribler_config import TriblerConfig from tribler_core.components.bandwidth_accounting.restapi.bandwidth_endpoint import BandwidthEndpoint -from tribler_core.modules.libtorrent.restapi.create_torrent_endpoint import CreateTorrentEndpoint -from tribler_core.modules.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint -from tribler_core.modules.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint -from tribler_core.modules.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint +from tribler_core.components.libtorrent.restapi.create_torrent_endpoint import CreateTorrentEndpoint +from tribler_core.components.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint +from tribler_core.components.libtorrent.restapi.libtorrent_endpoint import LibTorrentEndpoint +from tribler_core.components.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint from tribler_core.components.metadata_store.restapi.channels_endpoint import ChannelsEndpoint from tribler_core.components.metadata_store.restapi.metadata_endpoint import MetadataEndpoint from tribler_core.components.metadata_store.restapi.remote_query_endpoint import RemoteQueryEndpoint diff --git a/src/tribler-core/tribler_core/restapi/settings.py b/src/tribler-core/tribler_core/restapi/settings.py index 7e336cf32cc..a211add5175 100644 --- a/src/tribler-core/tribler_core/restapi/settings.py +++ b/src/tribler-core/tribler_core/restapi/settings.py @@ -3,7 +3,7 @@ from pydantic import validator from tribler_core.config.tribler_config_section import TriblerConfigSection -from tribler_core.modules.libtorrent.settings import validate_port_with_minus_one +from tribler_core.components.libtorrent.settings import validate_port_with_minus_one class APISettings(TriblerConfigSection): diff --git a/src/tribler-core/tribler_core/restapi/tests/test_create_torrent_endpoint.py b/src/tribler-core/tribler_core/restapi/tests/test_create_torrent_endpoint.py index 2a611324afe..bc1a254dcd2 100644 --- a/src/tribler-core/tribler_core/restapi/tests/test_create_torrent_endpoint.py +++ b/src/tribler-core/tribler_core/restapi/tests/test_create_torrent_endpoint.py @@ -6,8 +6,8 @@ import pytest -from tribler_core.modules.libtorrent.restapi.create_torrent_endpoint import CreateTorrentEndpoint -from tribler_core.modules.libtorrent.settings import DownloadDefaultsSettings +from tribler_core.components.libtorrent.restapi.create_torrent_endpoint import CreateTorrentEndpoint +from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings from tribler_core.restapi.base_api_test import do_request from tribler_core.restapi.rest_manager import error_middleware from tribler_core.tests.tools.common import TESTS_DATA_DIR diff --git a/src/tribler-core/tribler_core/restapi/tests/test_settings_endpoint.py b/src/tribler-core/tribler_core/restapi/tests/test_settings_endpoint.py index bfd7ab570b4..1b755dfa6a2 100644 --- a/src/tribler-core/tribler_core/restapi/tests/test_settings_endpoint.py +++ b/src/tribler-core/tribler_core/restapi/tests/test_settings_endpoint.py @@ -6,7 +6,7 @@ from tribler_common.simpledefs import MAX_LIBTORRENT_RATE_LIMIT from tribler_core.config.tribler_config import TriblerConfig -from tribler_core.modules.libtorrent.download_manager import DownloadManager +from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.restapi.base_api_test import do_request from tribler_core.restapi.rest_manager import error_middleware from tribler_core.restapi.settings_endpoint import SettingsEndpoint diff --git a/src/tribler-core/tribler_core/start_core.py b/src/tribler-core/tribler_core/start_core.py index 09662699a10..8b3de47a7ea 100644 --- a/src/tribler-core/tribler_core/start_core.py +++ b/src/tribler-core/tribler_core/start_core.py @@ -18,7 +18,7 @@ from tribler_core.components.gigachannel.gigachannel_component import GigaChannelComponent from tribler_core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent from tribler_core.components.ipv8.ipv8_component import Ipv8Component -from tribler_core.components.libtorrent import LibtorrentComponent +from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.masterkey.masterkey_component import MasterKeyComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent from tribler_core.components.payout import PayoutComponent diff --git a/src/tribler-core/tribler_core/upgrade/config_converter.py b/src/tribler-core/tribler_core/upgrade/config_converter.py index e8142fd92ad..6a6330c63e7 100644 --- a/src/tribler-core/tribler_core/upgrade/config_converter.py +++ b/src/tribler-core/tribler_core/upgrade/config_converter.py @@ -9,10 +9,10 @@ from tribler_common.simpledefs import STATEDIR_CHECKPOINT_DIR -from tribler_core.modules.libtorrent.download_config import DownloadConfig -from tribler_core.modules.libtorrent.torrentdef import TorrentDef +from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.utilities.configparser import CallbackConfigParser -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.unicode import recursive_ungarble_metainfo logger = logging.getLogger(__name__) diff --git a/src/tribler-core/tribler_core/upgrade/tests/test_config_upgrade_to_75.py b/src/tribler-core/tribler_core/upgrade/tests/test_config_upgrade_to_75.py index 4d56ea6e1ec..3cda6c3ff68 100644 --- a/src/tribler-core/tribler_core/upgrade/tests/test_config_upgrade_to_75.py +++ b/src/tribler-core/tribler_core/upgrade/tests/test_config_upgrade_to_75.py @@ -2,13 +2,8 @@ import shutil from pathlib import Path -from configobj import ParseError as ConfigObjParseError - -import pytest - from tribler_common.simpledefs import STATEDIR_CHECKPOINT_DIR -from tribler_core.modules.libtorrent.download_config import DownloadConfig from tribler_core.tests.tools.common import TESTS_DATA_DIR from tribler_core.upgrade.config_converter import convert_config_to_tribler75 diff --git a/src/tribler-core/tribler_core/utilities/tests/test_torrent_utils.py b/src/tribler-core/tribler_core/utilities/tests/test_torrent_utils.py index 45f33d7f594..01734ccbb27 100644 --- a/src/tribler-core/tribler_core/utilities/tests/test_torrent_utils.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_torrent_utils.py @@ -4,7 +4,8 @@ from tribler_core.tests.tools.common import TESTS_DATA_DIR from tribler_core.utilities.path_util import Path -from tribler_core.utilities.torrent_utils import commonprefix, create_torrent_file, get_info_from_handle +from tribler_core.components.libtorrent.utils.torrent_utils import commonprefix, create_torrent_file, \ + get_info_from_handle TORRENT_DATA_DIR = TESTS_DATA_DIR / "torrent_creation_files" FILE1_NAME = "file1.txt" diff --git a/src/tribler-core/tribler_core/utilities/utilities.py b/src/tribler-core/tribler_core/utilities/utilities.py index 05d8f54ed4c..7353c3446dc 100644 --- a/src/tribler-core/tribler_core/utilities/utilities.py +++ b/src/tribler-core/tribler_core/utilities/utilities.py @@ -10,7 +10,7 @@ from functools import wraps from urllib.parse import parse_qsl, urlsplit -from tribler_core.utilities.libtorrent_helper import libtorrent as lt +from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.utilities.sentinels import sentinel logger = logging.getLogger(__name__)