Skip to content

Commit

Permalink
Rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Apr 20, 2022
1 parent 98dcfe8 commit 4b7e5c2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 61 deletions.
13 changes: 10 additions & 3 deletions src/tribler/core/config/tests/test_tribler_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import shutil

from configobj import ParseError

import pytest
from configobj import ParseError

from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.tests.tools.common import TESTS_DATA_DIR
Expand Down Expand Up @@ -94,7 +93,15 @@ async def test_get_path_relative(tmpdir):
async def test_get_path_absolute(tmpdir):
config = TriblerConfig(state_dir=tmpdir)
config.general.log_dir = str(Path(tmpdir).parent)
assert config.general.get_path_as_absolute(property_name='log_dir', state_dir=tmpdir) == Path(tmpdir).parent
state_dir = Path(tmpdir)
assert config.general.get_path_as_absolute(property_name='log_dir', state_dir=state_dir) == Path(tmpdir).parent


def test_get_path_absolute_none(tmpdir):
config = TriblerConfig(state_dir=tmpdir)
config.general.log_dir = None
state_dir = Path(tmpdir)
assert config.general.get_path_as_absolute(property_name='log_dir', state_dir=state_dir) is None


@pytest.mark.asyncio
Expand Down
59 changes: 48 additions & 11 deletions src/tribler/core/config/tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,62 @@

import configobj
from configobj import ParseError

from pydantic import PrivateAttr

from tribler.core.config.tribler_config_sections import TriblerConfigSections
from pydantic import BaseSettings, Extra, PrivateAttr

from tribler.core.components.bandwidth_accounting.settings import BandwidthAccountingSettings
from tribler.core.components.gigachannel.community.settings import ChantSettings
from tribler.core.components.ipv8.settings import (
BootstrapSettings,
DHTSettings,
DiscoveryCommunitySettings,
Ipv8Settings,
)
from tribler.core.components.key.settings import TrustchainSettings
from tribler.core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings
from tribler.core.components.metadata_store.remote_query_community.settings import RemoteQueryCommunitySettings
from tribler.core.components.popularity.settings import PopularityCommunitySettings
from tribler.core.components.resource_monitor.settings import ResourceMonitorSettings
from tribler.core.components.restapi.rest.settings import APISettings
from tribler.core.components.torrent_checker.settings import TorrentCheckerSettings
from tribler.core.components.tunnel.settings import TunnelCommunitySettings
from tribler.core.components.watch_folder.settings import WatchFolderSettings
from tribler.core.settings import GeneralSettings

logger = logging.getLogger('Tribler Config')


class TriblerConfig(TriblerConfigSections):
""" Tribler config class that contains common logic for manipulating with a config.
"""
_state_dir: Path = PrivateAttr()
_file: Optional[Path] = PrivateAttr() # a last file saved during write-load operations
_error: Optional[Exception] = PrivateAttr()
class TriblerConfig(BaseSettings):
""" Tribler config class that contains common logic for manipulating with a config."""

class Config:
extra = Extra.ignore # ignore extra attributes during model initialization

general: GeneralSettings = GeneralSettings()
tunnel_community: TunnelCommunitySettings = TunnelCommunitySettings()
bandwidth_accounting: BandwidthAccountingSettings = BandwidthAccountingSettings()
bootstrap: BootstrapSettings = BootstrapSettings()
ipv8: Ipv8Settings = Ipv8Settings()
discovery_community: DiscoveryCommunitySettings = DiscoveryCommunitySettings()
dht: DHTSettings = DHTSettings()
trustchain: TrustchainSettings = TrustchainSettings()
watch_folder: WatchFolderSettings = WatchFolderSettings()
chant: ChantSettings = ChantSettings()
torrent_checking: TorrentCheckerSettings = TorrentCheckerSettings()
libtorrent: LibtorrentSettings = LibtorrentSettings()
download_defaults: DownloadDefaultsSettings = DownloadDefaultsSettings()
api: APISettings = APISettings()
resource_monitor: ResourceMonitorSettings = ResourceMonitorSettings()
popularity_community: PopularityCommunitySettings = PopularityCommunitySettings()
remote_query_community: RemoteQueryCommunitySettings = RemoteQueryCommunitySettings()

# Special configuration options related to the operation mode of the Core
upgrader_enabled: bool = True
gui_test_mode: bool = False

_state_dir: Path = PrivateAttr()
_file: Optional[Path] = PrivateAttr() # a last file saved during write-load operations
_error: Optional[Exception] = PrivateAttr()

def __init__(self, *args, state_dir: Path = None, file: Path = None, error: str = None, **kwargs):
""" Constructor
Expand All @@ -45,7 +82,7 @@ def __init__(self, *args, state_dir: Path = None, file: Path = None, error: str
self._error = error

@staticmethod
def load(file: Path, state_dir: Path, reset_config_on_error: bool = False) -> TriblerConfig:
def load(file: Path, state_dir: Path, reset_config_on_error: bool = False) -> Config:
""" Load a config from a file
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import BaseSettings, Extra, root_validator


class TriblerBaseSettings(BaseSettings):
class TriblerConfigSection(BaseSettings):
"""Base Class that defines Tribler Config Section
We are waiting https://github.com/samuelcolvin/pydantic/pull/2625
Expand Down
46 changes: 0 additions & 46 deletions src/tribler/core/config/tribler_config_sections.py

This file was deleted.

0 comments on commit 4b7e5c2

Please sign in to comment.