Use bool instead of passing args

This commit is contained in:
Florian Bruhin 2018-12-10 16:07:40 +01:00
parent 35a3fe029d
commit 8508928f3d

View File

@ -27,7 +27,6 @@ import zipfile
import logging import logging
import typing import typing
import pathlib import pathlib
import argparse
from PyQt5.QtCore import QUrl from PyQt5.QtCore import QUrl
@ -93,11 +92,12 @@ class HostBlocker:
_done_count: How many files have been read successfully. _done_count: How many files have been read successfully.
_local_hosts_file: The path to the blocked-hosts file. _local_hosts_file: The path to the blocked-hosts file.
_config_hosts_file: The path to a blocked-hosts in ~/.config _config_hosts_file: The path to a blocked-hosts in ~/.config
_has_basedir: Whether a custom --basedir is set.
""" """
def __init__(self, *, data_dir: pathlib.Path, config_dir: pathlib.Path, def __init__(self, *, data_dir: pathlib.Path, config_dir: pathlib.Path,
args: argparse.Namespace) -> None: has_basedir: bool = False) -> None:
self._args = args self._has_basedir = has_basedir
self._blocked_hosts = set() # type: typing.Set[str] self._blocked_hosts = set() # type: typing.Set[str]
self._config_blocked_hosts = set() # type: typing.Set[str] self._config_blocked_hosts = set() # type: typing.Set[str]
self._in_progress = [] # type: typing.List[downloads.TempDownload] self._in_progress = [] # type: typing.List[downloads.TempDownload]
@ -165,7 +165,7 @@ class HostBlocker:
if not found: if not found:
if (config.val.content.host_blocking.lists and if (config.val.content.host_blocking.lists and
self._args.basedir is None and not self._has_basedir and
config.val.content.host_blocking.enabled): config.val.content.host_blocking.enabled):
message.info("Run :adblock-update to get adblock lists.") message.info("Run :adblock-update to get adblock lists.")
@ -342,6 +342,6 @@ def init(context: apitypes.InitContext) -> None:
global _host_blocker global _host_blocker
_host_blocker = HostBlocker(data_dir=context.data_dir, _host_blocker = HostBlocker(data_dir=context.data_dir,
config_dir=context.config_dir, config_dir=context.config_dir,
args=context.args) has_basedir=context.args.basedir is not None)
_host_blocker.read_hosts() _host_blocker.read_hosts()
requests.register_filter(_host_blocker.filter_request) requests.register_filter(_host_blocker.filter_request)