Adblock import handles local directories and paths
Fixes #464 * Handles local Directories * Handles local paths without file://
This commit is contained in:
parent
6293bc5178
commit
bdc41db601
@ -174,15 +174,14 @@ class HostBlocker:
|
||||
for url in config.val.content.host_blocking.lists:
|
||||
if url.scheme() == 'file':
|
||||
filename = url.toLocalFile()
|
||||
try:
|
||||
fileobj = open(filename, 'rb')
|
||||
except OSError as e:
|
||||
message.error("adblock: Error while reading {}: {}".format(
|
||||
filename, e.strerror))
|
||||
continue
|
||||
download = FakeDownload(fileobj)
|
||||
self._in_progress.append(download)
|
||||
self.on_download_finished(download)
|
||||
if os.path.isdir(filename):
|
||||
for filenames in os.scandir(filename):
|
||||
if not filenames.name.startswith('.')\
|
||||
and filenames.is_file():
|
||||
print( filenames.name )
|
||||
self._import_local(filenames.path)
|
||||
else:
|
||||
self._import_local(filename)
|
||||
else:
|
||||
fobj = io.BytesIO()
|
||||
fobj.name = 'adblock: ' + url.host()
|
||||
@ -193,6 +192,22 @@ class HostBlocker:
|
||||
download.finished.connect(
|
||||
functools.partial(self.on_download_finished, download))
|
||||
|
||||
def _import_local(self, filename):
|
||||
"""Adds the contents of a file to the blocklist.
|
||||
|
||||
Args:
|
||||
filename: path to a local file to import.
|
||||
"""
|
||||
try:
|
||||
fileobj = open(filename, 'rb')
|
||||
except OSError as e:
|
||||
message.error("adblock: Error while reading {}: {}".format(
|
||||
filename, e.strerror))
|
||||
return
|
||||
download = FakeDownload(fileobj)
|
||||
self._in_progress.append(download)
|
||||
self.on_download_finished(download)
|
||||
|
||||
def _parse_line(self, line):
|
||||
"""Parse a line from a host file.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user