mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-26 10:05:19 +00:00
Detect now handles creating a reader.
Finished writing detect_format and hence auto_detect (could it really be?) is_valid() doesn't need to take in a filename (already has it).
This commit is contained in:
parent
d6597bdc22
commit
0952f84d6c
@ -48,9 +48,7 @@ import deluge.component as component
|
|||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
from deluge.core.rpcserver import export
|
from deluge.core.rpcserver import export
|
||||||
from deluge.httpdownloader import download_file
|
from deluge.httpdownloader import download_file
|
||||||
from decompressers import Zipped, GZipped, BZipped2
|
from detect import detect_compression, detect_format, create_reader, UnknownFormatError
|
||||||
from readers import EmuleReader, SafePeerReader, PeerGuardianReader
|
|
||||||
from detect import detect_compression, detect_format, UnknownFormatError
|
|
||||||
|
|
||||||
# TODO: check return values for deferred callbacks
|
# TODO: check return values for deferred callbacks
|
||||||
# TODO: review class attributes for redundancy
|
# TODO: review class attributes for redundancy
|
||||||
@ -67,18 +65,6 @@ DEFAULT_PREFS = {
|
|||||||
"try_times": 3,
|
"try_times": 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
DECOMPRESSERS = {
|
|
||||||
"Zip" : Zipped,
|
|
||||||
"GZip" : GZipped,
|
|
||||||
"BZip2" : BZipped2
|
|
||||||
}
|
|
||||||
|
|
||||||
READERS = {
|
|
||||||
"Emule" : EmuleReader,
|
|
||||||
"SafePeer" : SafePeerReader,
|
|
||||||
"PeerGuardian" : PeerGuardianReader
|
|
||||||
}
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
BLOCK_RANGE = 1
|
BLOCK_RANGE = 1
|
||||||
|
|
||||||
@ -96,9 +82,7 @@ class Core(CorePluginBase):
|
|||||||
self.core = component.get("Core")
|
self.core = component.get("Core")
|
||||||
self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS)
|
self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS)
|
||||||
|
|
||||||
self.reader = READERS.get(self.config["list_type"])
|
self.reader = create_reader(self.config["list_type"], self.config["list_compression"])
|
||||||
if self.config["list_compression"]:
|
|
||||||
self.reader = DECOMPRESSERS.get(self.config["list_compression"])(self.reader)
|
|
||||||
|
|
||||||
update_now = False
|
update_now = False
|
||||||
if self.config["load_on_start"]:
|
if self.config["load_on_start"]:
|
||||||
|
@ -33,12 +33,27 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from decompressers import Zipped, GZipped, BZipped2
|
||||||
|
from readers import EmuleReader, SafePeerReader, PeerGuardianReader
|
||||||
|
|
||||||
COMPRESSION_TYPES = {
|
COMPRESSION_TYPES = {
|
||||||
"PK" : "zip",
|
"PK" : "zip",
|
||||||
"\x1f\x8b" : "gzip",
|
"\x1f\x8b" : "gzip",
|
||||||
"BZ" : "bzip2"
|
"BZ" : "bzip2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DECOMPRESSERS = {
|
||||||
|
"Zip" : Zipped,
|
||||||
|
"GZip" : GZipped,
|
||||||
|
"BZip2" : BZipped2
|
||||||
|
}
|
||||||
|
|
||||||
|
READERS = {
|
||||||
|
"Emule" : EmuleReader,
|
||||||
|
"SafePeer" : SafePeerReader,
|
||||||
|
"PeerGuardian" : PeerGuardianReader
|
||||||
|
}
|
||||||
|
|
||||||
class UnknownFormatError(Exception):
|
class UnknownFormatError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -49,5 +64,15 @@ def detect_compression(filename):
|
|||||||
return COMPRESSION_TYPES.get(magic_number, "")
|
return COMPRESSION_TYPES.get(magic_number, "")
|
||||||
|
|
||||||
def detect_format(filename, compression=""):
|
def detect_format(filename, compression=""):
|
||||||
# TODO: implement this function
|
format = ""
|
||||||
return ""
|
for reader in READERS:
|
||||||
|
if create_reader(reader, compression)(filename).is_valid():
|
||||||
|
format = reader
|
||||||
|
break
|
||||||
|
return format
|
||||||
|
|
||||||
|
def create_reader(format, compression=""):
|
||||||
|
reader = READERS.get(format)
|
||||||
|
if compression:
|
||||||
|
reader = DECOMPRESSERS.get(compression)(reader)
|
||||||
|
return reader
|
||||||
|
@ -60,7 +60,7 @@ class BaseReader(object):
|
|||||||
"""Ignore commented lines and blank lines"""
|
"""Ignore commented lines and blank lines"""
|
||||||
return line.startswith('#') or not line.strip()
|
return line.startswith('#') or not line.strip()
|
||||||
|
|
||||||
def is_valid(self, file):
|
def is_valid(self):
|
||||||
"""Determines whether file is valid for this reader"""
|
"""Determines whether file is valid for this reader"""
|
||||||
blocklist = self.open()
|
blocklist = self.open()
|
||||||
valid = True
|
valid = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user