Skip to content

Commit

Permalink
Merge pull request #6494 from drew2a/refactoring/remove_unused_code
Browse files Browse the repository at this point in the history
Remove unused code
  • Loading branch information
drew2a authored Oct 27, 2021
2 parents 74db8c0 + 527aa60 commit b77b642
Show file tree
Hide file tree
Showing 25 changed files with 22 additions and 259 deletions.
2 changes: 2 additions & 0 deletions src/tribler-common/tribler_common/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import yaml


# note: this class is used by src/tribler-common/tribler_common/logger/config.yaml
class InfoFilter(logging.Filter):
def filter(self, rec):
return rec.levelno == logging.INFO


# note: this class is used by src/tribler-common/tribler_common/logger/config.yaml
class ErrorFilter(logging.Filter):
def filter(self, rec):
return rec.levelno == logging.ERROR
Expand Down
20 changes: 0 additions & 20 deletions src/tribler-common/tribler_common/simpledefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@
# Infohashes are always 20 byte binary strings
INFOHASH_LENGTH = 20

# SIGNALS (for internal use)
SIGNAL_ALLCHANNEL_COMMUNITY = 'signal_allchannel_community'
SIGNAL_CHANNEL_COMMUNITY = 'signal_channel_community'
SIGNAL_SEARCH_COMMUNITY = 'signal_search_community'
SIGNAL_GIGACHANNEL_COMMUNITY = 'signal_gigachannel_community'

SIGNAL_ON_SEARCH_RESULTS = 'signal_on_search_results'
SIGNAL_ON_TORRENT_UPDATED = 'signal_on_torrent_updated'

# SIGNALS (for common use, like APIs)
SIGNAL_TORRENT = 'signal_torrent'
SIGNAL_CHANNEL = 'signal_channel'
SIGNAL_RSS_FEED = 'signal_rss_feed'

SIGNAL_ON_CREATED = 'signal_on_created'
SIGNAL_ON_UPDATED = 'signal_on_updated'

SIGNAL_RESOURCE_CHECK = 'signal_resource_check'
SIGNAL_LOW_SPACE = 'signal_low_space'

# Tribler Core states
STATE_STARTING = "STARTING"
STATE_UPGRADING = "UPGRADING"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class SearchRequestCache(RandomNumberCache):
def __init__(self, request_cache, uuid, peers):
super().__init__(request_cache, "remote-search-request")
self.request_cache = request_cache
self.requested_peers = {hexlify(peer.mid): False for peer in peers}
self.uuid = uuid

@property
Expand All @@ -21,25 +20,6 @@ def timeout_delay(self):
def on_timeout(self):
pass

def process_peer_response(self, peer):
"""
Returns whether to process this response from the given peer in the community. If the peer response has
already been processed then it is skipped. Moreover, if all the responses from the expected peers are received,
the request is removed from the request cache.
:param peer: Peer
:return: True if peer has not been processed before, else False
"""
mid = hexlify(peer.mid)
if mid in self.requested_peers and not self.requested_peers[mid]:
self.requested_peers[mid] = True

# Check if all expected responses are received
if all(self.requested_peers.values()):
self.remove_request()

return True
return False

def remove_request(self):
if self.request_cache.has(self.prefix, self.number):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from tribler_common.osutils import get_home_dir

from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.exceptions import InvalidConfigException
from tribler_core.utilities.install_dir import get_lib_path
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

Expand All @@ -34,7 +34,7 @@ def validate(self):
validator = Validator()
validation_result = self.config.validate(validator)
if validation_result is not True:
raise InvalidConfigException(msg=f"DownloadConfig is invalid: {str(validation_result)}")
raise InvalidConfigException(f"DownloadConfig is invalid: {str(validation_result)}")

@staticmethod
def load(config_path=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

from marshmallow.fields import String

from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.restapi.rest.rest_endpoint import HTTP_BAD_REQUEST, RESTEndpoint, RESTResponse
from tribler_core.components.restapi.rest.schema import HandledErrorSchema
from tribler_core.components.restapi.rest.util import return_handled_exception
from tribler_core.exceptions import DuplicateDownloadException
from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.utilities.path_util import Path
from tribler_core.utilities.unicode import ensure_unicode, recursive_bytes
from tribler_core.utilities.utilities import bdecode_compat, froze_it
Expand Down Expand Up @@ -114,9 +113,6 @@ async def create_torrent(self, request):
download_config = DownloadConfig()
download_config.set_dest_dir(result['base_path'] if len(file_path_list) == 1 else result['base_dir'])
download_config.set_hops(self.download_manager.download_defaults.number_hops)
try:
self.download_manager.start_download(tdef=TorrentDef(metainfo_dict), config=download_config)
except DuplicateDownloadException:
self._logger.warning("The created torrent is already being downloaded.")
self.download_manager.start_download(tdef=TorrentDef(metainfo_dict), config=download_config)

return RESTResponse(json.dumps({"torrent": base64.b64encode(result['metainfo']).decode('utf-8')}))
15 changes: 0 additions & 15 deletions src/tribler-core/tribler_core/components/metadata_store/config.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from lz4.frame import LZ4FrameCompressor

from pony import orm
from pony.orm import db_session, desc, raw_sql, select
from pony.orm import db_session, raw_sql, select

from tribler_common.simpledefs import CHANNEL_STATE

from tribler_core.components.metadata_store.db.orm_bindings.discrete_clock import clock
from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler_core.components.metadata_store.db.orm_bindings.channel_node import (
CHANNEL_DESCRIPTION_FLAG,
CHANNEL_THUMBNAIL_FLAG,
Expand All @@ -20,12 +20,12 @@
TODELETE,
UPDATED,
)
from tribler_core.components.metadata_store.db.orm_bindings.discrete_clock import clock
from tribler_core.components.metadata_store.db.serialization import (
CHANNEL_TORRENT,
ChannelMetadataPayload,
HealthItemsPayload,
)
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
Expand Down Expand Up @@ -447,11 +447,6 @@ def get_channels_by_title(cls, title):
def get_channel_with_infohash(cls, infohash):
return cls.get(infohash=infohash)

@classmethod
@db_session
def get_recent_channel_with_public_key(cls, public_key):
return cls.select(lambda g: g.public_key == public_key).sort_by(lambda g: desc(g.id_)).first() or None

@classmethod
@db_session
def get_channel_with_dirname(cls, dirname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from pony.orm import db_session, select

from tribler_common.simpledefs import CHANNEL_STATE

from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import chunks
from tribler_core.components.metadata_store.db.orm_bindings.channel_node import (
CHANNEL_DESCRIPTION_FLAG,
Expand All @@ -17,13 +19,13 @@
)
from tribler_core.components.metadata_store.db.orm_bindings.discrete_clock import clock
from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import tdef_to_metadata_dict
from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, \
CollectionNodePayload
from tribler_core.exceptions import DuplicateTorrentFileError
from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.metadata_store.db.serialization import (
CHANNEL_TORRENT,
COLLECTION_NODE,
CollectionNodePayload,
)
from tribler_core.utilities.random_utils import random_infohash


# pylint: disable=too-many-statements


Expand Down Expand Up @@ -126,10 +128,6 @@ def contents(self):
def actual_contents(self):
return self.contents.where(lambda g: g.status != TODELETE)

@db_session
def get_random_contents(self, limit):
return self.contents.where(lambda g: g.status not in [NEW, TODELETE]).random(limit)

@property
@db_session
def contents_list(self):
Expand Down Expand Up @@ -215,8 +213,6 @@ def rec_gen(dir_):
for f in chunk:
try:
self.add_torrent_to_channel(TorrentDef.load(f))
except DuplicateTorrentFileError:
pass
except Exception: # pylint: disable=W0703
# Have to use the broad exception clause because Py3 versions of libtorrent
# generate generic Exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ def read_payload_with_offset(data, offset=0):
raise UnknownBlobTypeException


def read_payload(data):
return read_payload_with_offset(data)[0]


class SignedPayload(Payload):
"""
Payload for metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from tribler_core.utilities.unicode import hexlify

BINARY_FIELDS = ("infohash", "channel_pk")
NO_RESPONSE = unhexlify("7ca1e9e922895a477a52cc9d6031020355eb172735bf83c058cb03ddcc9c6408")


def sanitize_query(query_dict, cap=100):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

from pony.orm import db_session

from tribler_core.components.metadata_store.db.store import MetadataStore
from tribler_core.components.metadata_store.restapi.metadata_endpoint import MetadataEndpointBase
from tribler_core.components.metadata_store.restapi.metadata_schema import MetadataParameters, MetadataSchema
from tribler_core.components.metadata_store.db.store import MetadataStore
from tribler_core.components.restapi.rest.rest_endpoint import HTTP_BAD_REQUEST, RESTResponse
from tribler_core.utilities.utilities import froze_it

Expand All @@ -24,10 +24,6 @@ class SearchEndpoint(MetadataEndpointBase):
def setup_routes(self):
self.app.add_routes([web.get('', self.search), web.get('/completions', self.completions)])

@staticmethod
def get_uuid(parameters):
return parameters['uuid'] if 'uuid' in parameters else None

@classmethod
def sanitize_parameters(cls, parameters):
sanitized = super().sanitize_parameters(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
This package contains code for the Tribler HTTP API.
"""

VOTE_UNSUBSCRIBE = 0
VOTE_SUBSCRIBE = 2


def has_param(parameters, name):
return name in parameters and len(parameters[name]) > 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
HTTP_BAD_REQUEST = 400
HTTP_UNAUTHORIZED = 401
HTTP_NOT_FOUND = 404
HTTP_CONFLICT = 409
HTTP_INTERNAL_SERVER_ERROR = 500


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,3 @@ def setup_routes(self):
for path, (ep_cls, enabled) in endpoints.items():
if enabled:
self.add_endpoint(path, ep_cls())

def set_ipv8_session(self, ipv8_session):
if '/ipv8' in self.endpoints:
self.endpoints['/ipv8'].initialize(ipv8_session)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@

class HandledErrorSchema(Schema):
error = String(description='Optional field describing any failures that may have occurred', required=True)


class UnhandledErrorSchema(Schema):
error = schema(DetailedErrorSchema={'handled': Boolean, 'code': Integer, 'message': String})
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@

import pytest

from tribler_core.config.tribler_config import TriblerConfig
from tribler_core.exceptions import TriblerException
from tribler_core.components.restapi.rest.base_api_test import do_real_request
from tribler_core.components.restapi.rest.rest_endpoint import HTTP_UNAUTHORIZED
from tribler_core.components.restapi.rest.rest_manager import ApiKeyMiddleware, RESTManager, error_middleware
from tribler_core.components.restapi.rest.root_endpoint import RootEndpoint
from tribler_core.config.tribler_config import TriblerConfig
from tribler_core.tests.tools.common import TESTS_DIR


def RaiseException(*args, **kwargs):
raise TriblerException("Oops! Something went wrong. Please restart Tribler")


@pytest.fixture()
def tribler_config():
return TriblerConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from tribler_core.components.restapi.restapi_component import RESTComponent
from tribler_core.components.tag.tag_component import TagComponent

# pylint: disable=protected-access

COMPONENTS = []
# pylint: disable=protected-access


@pytest.mark.asyncio
Expand Down
Loading

0 comments on commit b77b642

Please sign in to comment.