Skip to content

Commit

Permalink
Polish PR
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Mar 14, 2023
1 parent 89e7ab1 commit 504eb18
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 160 deletions.
18 changes: 9 additions & 9 deletions doc/restapi/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ Download states
There are various download states possible which are returned when fetching downloads. These states are explained in the table below.

+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_ALLOCATING_DISKSPACE | Libtorrent is allocating disk space for the download |
| ALLOCATING_DISKSPACE | Libtorrent is allocating disk space for the download |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_WAITING4HASHCHECK | The download is waiting for the hash check to be performed |
| WAITING_FOR_HASHCHECK | The download is waiting for the hash check to be performed |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_HASHCHECKING | Libtorrent is checking the hashes of the download |
| HASHCHECKING | Libtorrent is checking the hashes of the download |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_DOWNLOADING | The torrent is being downloaded |
| DOWNLOADING | The torrent is being downloaded |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_SEEDING | The torrent has been downloaded and is now being seeded to other peers |
| SEEDING | The torrent has been downloaded and is now being seeded to other peers |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_STOPPED | The torrent has stopped downloading, either because the downloading has completed or the user has stopped the download |
| STOPPED | The torrent has stopped downloading, either because the downloading has completed or the user has stopped the download |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_STOPPED_ON_ERROR | The torrent has stopped because an error occurred |
| STOPPED_ON_ERROR | The torrent has stopped because an error occurred |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_METADATA | The torrent information is being fetched from the DHT |
| METADATA | The torrent information is being fetched from the DHT |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+
| DLSTATUS_CIRCUITS | The (anonymous) download is building circuits |
| CIRCUITS | The (anonymous) download is building circuits |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------+

Endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tribler.core.components.metadata_store.db.store import MetadataStore
from tribler.core.utilities.notifier import Notifier
from tribler.core.utilities.pony_utils import run_threaded
from tribler.core.utilities.simpledefs import Status
from tribler.core.utilities.simpledefs import DownloadStatus
from tribler.core.utilities.unicode import hexlify

PROCESS_CHANNEL_DIR = 1
Expand Down Expand Up @@ -107,7 +107,7 @@ async def regenerate_channel_torrent(self, channel_pk, channel_id):

async def check_and_regen_personal_channel_torrent(self, channel_pk, channel_id, channel_download, timeout=60):
try:
await wait_for(channel_download.wait_for_status(Status.DLSTATUS_SEEDING), timeout=timeout)
await wait_for(channel_download.wait_for_status(DownloadStatus.SEEDING), timeout=timeout)
except asyncio.TimeoutError:
self._logger.warning("Time out waiting for personal channel %s %i to seed", hexlify(channel_pk), channel_id)
await self.regenerate_channel_torrent(channel_pk, channel_id)
Expand Down Expand Up @@ -200,7 +200,7 @@ def check_channels_updates(self):
channel.timestamp,
)
self.download_channel(channel)
elif status == Status.DLSTATUS_SEEDING:
elif status == DownloadStatus.SEEDING:
self._logger.info(
"Processing previously downloaded, but unprocessed channel torrent %s ver %i->%i",
channel.dirname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tribler.core.components.metadata_store.db.orm_bindings.channel_node import NEW
from tribler.core.tests.tools.base_test import MockObject
from tribler.core.tests.tools.common import TORRENT_UBUNTU_FILE
from tribler.core.utilities.simpledefs import Status
from tribler.core.utilities.simpledefs import DownloadStatus
from tribler.core.utilities.utilities import random_infohash

update_metainfo = None
Expand Down Expand Up @@ -204,7 +204,7 @@ def fake_get_metainfo(infohash, **_):
gigachannel_manager.download_manager.download_exists = lambda _: True

mock_download = MagicMock()
mock_download.get_state.get_status = Status.DLSTATUS_SEEDING
mock_download.get_state.get_status = DownloadStatus.SEEDING

gigachannel_manager.download_manager.get_download = lambda _: mock_download

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from tribler.core.utilities.notifier import Notifier
from tribler.core.utilities.osutils import fix_filebasename
from tribler.core.utilities.path_util import Path
from tribler.core.utilities.simpledefs import DOWNLOAD, Status
from tribler.core.utilities.simpledefs import DOWNLOAD, DownloadStatus
from tribler.core.utilities.unicode import ensure_unicode, hexlify
from tribler.core.utilities.utilities import bdecode_compat

Expand Down Expand Up @@ -436,7 +436,7 @@ def update_lt_status(self, lt_status: lt.torrent_status):

def _stop_if_finished(self):
state = self.get_state()
if state.get_status() == Status.DLSTATUS_SEEDING:
if state.get_status() == DownloadStatus.SEEDING:
mode = self.download_defaults.seeding_mode
seeding_ratio = self.download_defaults.seeding_ratio
seeding_time = self.download_defaults.seeding_time
Expand Down Expand Up @@ -475,7 +475,7 @@ def move_storage(self, new_dir: Path):
@check_handle()
def force_recheck(self):
if not isinstance(self.tdef, TorrentDefNoMetainfo):
if self.get_state().get_status() == Status.DLSTATUS_STOPPED:
if self.get_state().get_status() == DownloadStatus.STOPPED:
self.pause_after_next_hashcheck = True
self.checkpoint_after_next_hashcheck = True
self.handle.resume()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
url_to_path,
)
from tribler.core.utilities.simpledefs import MAX_LIBTORRENT_RATE_LIMIT, STATEDIR_CHECKPOINT_DIR, \
Status
DownloadStatus
from tribler.core.utilities.unicode import hexlify
from tribler.core.utilities.utilities import bdecode_compat, has_bep33_support, parse_magnetlink
from tribler.core.version import version_id
Expand Down Expand Up @@ -839,7 +839,7 @@ async def sesscb_states_callback(self, states_list):
download = ds.get_download()
infohash = download.get_def().get_infohash()

if ds.get_status() == Status.DLSTATUS_SEEDING:
if ds.get_status() == DownloadStatus.SEEDING:
if download.config.get_hops() == 0 and download.config.get_safe_seeding():
# Re-add the download with anonymity enabled
hops = self.download_defaults.number_hops
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import logging

from tribler.core.utilities.simpledefs import (
Status, UPLOAD,
DownloadStatus, UPLOAD,
)

# Map used to convert libtorrent -> Tribler download status
DLSTATUS_MAP = [
Status.DLSTATUS_WAITING4HASHCHECK,
Status.DLSTATUS_HASHCHECKING,
Status.DLSTATUS_METADATA,
Status.DLSTATUS_DOWNLOADING,
Status.DLSTATUS_SEEDING,
Status.DLSTATUS_SEEDING,
Status.DLSTATUS_ALLOCATING_DISKSPACE,
Status.DLSTATUS_HASHCHECKING,
DOWNLOAD_STATUS_MAP = [
DownloadStatus.WAITING_FOR_HASHCHECK,
DownloadStatus.HASHCHECKING,
DownloadStatus.METADATA,
DownloadStatus.DOWNLOADING,
DownloadStatus.SEEDING,
DownloadStatus.SEEDING,
DownloadStatus.ALLOCATING_DISKSPACE,
DownloadStatus.HASHCHECKING,
]


Expand Down Expand Up @@ -50,27 +50,27 @@ def get_download(self):

def get_progress(self):
""" The general progress of the Download as a percentage. When status is
* DLSTATUS_HASHCHECKING it is the percentage of already downloaded
* HASHCHECKING it is the percentage of already downloaded
content checked for integrity.
* DLSTATUS_DOWNLOADING/SEEDING it is the percentage downloaded.
* DOWNLOADING/SEEDING it is the percentage downloaded.
@return Progress as a float (0..1).
"""
return self.lt_status.progress if self.lt_status else 0

def get_status(self) -> Status:
def get_status(self) -> DownloadStatus:
""" Returns the status of the torrent.
@return DLSTATUS_* """
@return DownloadStatus* """

if self.lt_status:
if self.lt_status.paused:
return Status.DLSTATUS_STOPPED
return DLSTATUS_MAP[self.lt_status.state]
return DownloadStatus.STOPPED
return DOWNLOAD_STATUS_MAP[self.lt_status.state]
if self.get_error():
return Status.DLSTATUS_STOPPED_ON_ERROR
return Status.DLSTATUS_STOPPED
return DownloadStatus.STOPPED_ON_ERROR
return DownloadStatus.STOPPED

def get_error(self):
""" Returns the Exception that caused the download to be moved to DLSTATUS_STOPPED_ON_ERROR status.
""" Returns the Exception that caused the download to be moved to STOPPED_ON_ERROR status.
@return An error message
"""
return self.error or (self.lt_status.error if self.lt_status and self.lt_status.error else None)
Expand All @@ -80,7 +80,7 @@ def get_current_speed(self, direct):
Returns the current up or download speed.
@return The speed in bytes/s.
"""
if not self.lt_status or self.get_status() not in [Status.DLSTATUS_DOWNLOADING, Status.DLSTATUS_SEEDING]:
if not self.lt_status or self.get_status() not in [DownloadStatus.DOWNLOADING, DownloadStatus.SEEDING]:
return 0
if direct == UPLOAD:
return self.lt_status.upload_rate
Expand All @@ -91,7 +91,7 @@ def get_current_payload_speed(self, direct):
Returns the current up or download payload speed.
@return The speed in bytes/s.
"""
if not self.lt_status or self.get_status() not in [Status.DLSTATUS_DOWNLOADING, Status.DLSTATUS_SEEDING]:
if not self.lt_status or self.get_status() not in [DownloadStatus.DOWNLOADING, DownloadStatus.SEEDING]:
return 0
if direct == UPLOAD:
return self.lt_status.upload_payload_rate
Expand Down Expand Up @@ -130,7 +130,7 @@ def get_num_seeds_peers(self):
Returns the sum of the number of seeds and peers.
@return A tuple (num seeds, num peers)
"""
if not self.lt_status or self.get_status() not in [Status.DLSTATUS_DOWNLOADING, Status.DLSTATUS_SEEDING]:
if not self.lt_status or self.get_status() not in [DownloadStatus.DOWNLOADING, DownloadStatus.SEEDING]:
return 0, 0

total = self.lt_status.list_peers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from asyncio import sleep

from tribler.core.components.libtorrent.utils.torrent_utils import check_vod, get_info_from_handle
from tribler.core.utilities.simpledefs import Status
from tribler.core.utilities.simpledefs import DownloadStatus

# 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
Expand Down Expand Up @@ -140,7 +140,7 @@ async def enable(self, fileindex=0, prebufpos=None):
# wait until dlstate is downloading or seeding
while True:
status = self.__lt_state().get_status()
if status in [Status.DLSTATUS_DOWNLOADING, Status.DLSTATUS_SEEDING]:
if status in [DownloadStatus.DOWNLOADING, DownloadStatus.SEEDING]:
break
await sleep(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from tribler.core.utilities.path_util import Path
from tribler.core.utilities.simpledefs import (
DOWNLOAD,
Status, UPLOAD,
DownloadStatus, UPLOAD,
)
from tribler.core.utilities.unicode import ensure_unicode, hexlify
from tribler.core.utilities.utilities import froze_it
Expand Down Expand Up @@ -53,7 +53,7 @@ def _safe_extended_peer_info(ext_peer_info):
return ''.join([chr(c) for c in ext_peer_info])


def get_extended_status(tunnel_community, download) -> Status:
def get_extended_status(tunnel_community, download) -> DownloadStatus:
"""
This function filters the original download status to possibly add tunnel-related status.
Extracted from DownloadState to remove coupling between DownloadState and Tunnels.
Expand All @@ -64,13 +64,13 @@ def get_extended_status(tunnel_community, download) -> Status:
# Nothing to do with tunnels. If stopped - it happened by the user or libtorrent-only reason
stopped_by_user = state.lt_status and state.lt_status.paused

if status == Status.DLSTATUS_STOPPED and not stopped_by_user:
if status == DownloadStatus.STOPPED and not stopped_by_user:
if download.config.get_hops() > 0:
if tunnel_community.get_candidates(PEER_FLAG_EXIT_BT):
return Status.DLSTATUS_CIRCUITS
return DownloadStatus.CIRCUITS
else:
return Status.DLSTATUS_EXIT_NODES
return Status.DLSTATUS_STOPPED
return DownloadStatus.EXIT_NODES
return DownloadStatus.STOPPED
return status


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tribler.core.components.restapi.rest.rest_manager import error_middleware
from tribler.core.tests.tools.common import TESTS_DATA_DIR
from tribler.core.utilities.rest_utils import HTTP_SCHEME, path_to_url
from tribler.core.utilities.simpledefs import Status
from tribler.core.utilities.simpledefs import DownloadStatus
from tribler.core.utilities.unicode import hexlify


Expand Down Expand Up @@ -72,7 +72,7 @@ def test_get_extended_status_downloading_nohops_nocandidates(mock_extended_statu
"""
Testing whether a non-anonymous download with state is considered "DOWNLOADING" without candidates.
"""
assert mock_extended_status == Status.DLSTATUS_DOWNLOADING
assert mock_extended_status == DownloadStatus.DOWNLOADING


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -82,7 +82,7 @@ def test_get_extended_status_downloading_nohops_candidates(mock_extended_status)
"""
Testing whether a non-anonymous download with state is considered "DOWNLOADING" with candidates.
"""
assert mock_extended_status == Status.DLSTATUS_DOWNLOADING
assert mock_extended_status == DownloadStatus.DOWNLOADING


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -92,7 +92,7 @@ def test_get_extended_status_downloading_hops_nocandidates(mock_extended_status)
"""
Testing whether an anonymous download with state is considered "DOWNLOADING" without candidates.
"""
assert mock_extended_status == Status.DLSTATUS_DOWNLOADING
assert mock_extended_status == DownloadStatus.DOWNLOADING


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -102,7 +102,7 @@ def test_get_extended_status_downloading_hops_candidates(mock_extended_status):
"""
Testing whether an anonymous download with state is considered "DOWNLOADING" with candidates.
"""
assert mock_extended_status == Status.DLSTATUS_DOWNLOADING
assert mock_extended_status == DownloadStatus.DOWNLOADING


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -112,7 +112,7 @@ def test_get_extended_status_stopped(mock_extended_status):
"""
Testing whether a non-anonymous download without state is considered "STOPPED" without candidates.
"""
assert mock_extended_status == Status.DLSTATUS_STOPPED
assert mock_extended_status == DownloadStatus.STOPPED


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -122,7 +122,7 @@ def test_get_extended_status_stopped_hascandidates(mock_extended_status):
"""
Testing whether a non-anonymous download without state is considered "STOPPED" with candidates.
"""
assert mock_extended_status == Status.DLSTATUS_STOPPED
assert mock_extended_status == DownloadStatus.STOPPED


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -132,7 +132,7 @@ def test_get_extended_status_exit_nodes(mock_extended_status):
"""
Testing whether an anonymous download without state is considered looking for "EXIT_NODES" without candidates.
"""
assert mock_extended_status == Status.DLSTATUS_EXIT_NODES
assert mock_extended_status == DownloadStatus.EXIT_NODES


@pytest.mark.parametrize("mock_extended_status",
Expand All @@ -142,7 +142,7 @@ def test_get_extended_status_circuits(mock_extended_status):
"""
Testing whether an anonymous download without state is considered looking for "CIRCUITS" with candidates.
"""
assert mock_extended_status == Status.DLSTATUS_CIRCUITS
assert mock_extended_status == DownloadStatus.CIRCUITS


async def test_get_downloads_if_checkpoints_are_not_loaded(mock_dlmgr, rest_api):
Expand Down
Loading

0 comments on commit 504eb18

Please sign in to comment.