From 126e3b40f2e8a1edac7b7cd07ecbf0adc49d0de6 Mon Sep 17 00:00:00 2001 From: pyblub Date: Thu, 16 Nov 2017 16:20:56 +0000 Subject: [PATCH] many minor fixes listed below parser.py set store default value to False to only save config when explicitely requested. Otherwise the config is written as many times as parameters are read from the config.ini database/backend.py temp fix to have pyload and not get an exception while handling exceptions in process_job datatype/file.py initial plugin after creating file and fix problem with id -> fid datatype/package.py add Package to __slots__ manager/event.py while debugging log events manager/file.py correct documentation network/hoster.py small fixes network/loader.py change read string instead of bytes from file thread/download.py return event instead of boolean thread/plugin.py write string instead of bytes requirements/install.txt add requirement for enum34 for python 2.7 --- pyload/config/parser.py | 5 ++--- pyload/core/database/backend.py | 2 ++ pyload/core/datatype/file.py | 16 ++++++++++------ pyload/core/datatype/package.py | 4 ++-- pyload/core/manager/event.py | 1 + pyload/core/manager/file.py | 2 +- pyload/core/network/hoster.py | 3 ++- pyload/core/network/loader.py | 2 +- pyload/core/thread/download.py | 6 ++++-- pyload/core/thread/plugin.py | 2 +- requirements/install.txt | 1 + 11 files changed, 27 insertions(+), 17 deletions(-) diff --git a/pyload/config/parser.py b/pyload/config/parser.py index 8dd56386ef..ee4b8c7203 100644 --- a/pyload/config/parser.py +++ b/pyload/config/parser.py @@ -100,7 +100,7 @@ def get(self): def get_default(self): return self.default - def set(self, value, store=True): + def set(self, value, store=False): norm_value = self._normalize_value(value) if self.allowed_values and norm_value not in self.allowed_values: raise InvalidValueError(value) @@ -254,10 +254,9 @@ def __init__( pass else: + self.store() return - self.store() - def _backup_fileconfig(self): path = self.path name, ext = os.path.splitext(path) diff --git a/pyload/core/database/backend.py b/pyload/core/database/backend.py index ad73da66be..bef2e3e4cb 100644 --- a/pyload/core/database/backend.py +++ b/pyload/core/database/backend.py @@ -84,6 +84,8 @@ def __init__(self, func, *args, **kwargs): self.result = None self.exception = False + self.pyload = self.args[0].pyload # self.args[0] is DatabaseBackend + # import inspect # self.frame = inspect.currentframe() diff --git a/pyload/core/datatype/file.py b/pyload/core/datatype/file.py index 23339525da..43d758f6d1 100644 --- a/pyload/core/datatype/file.py +++ b/pyload/core/datatype/file.py @@ -125,7 +125,8 @@ class File(BaseObject): __slots__ = ['_name', '_size', 'abort', 'added', 'error', 'fid', 'fileorder', 'filestatus', 'hash', 'lock', 'manager', 'media', 'owner', 'packageid', 'plugin', 'pluginclass', 'pluginname', - 'reconnected', 'status', 'statusname', 'url', 'wait_until'] + 'pyload', 'reconnected', 'status', 'statusname', 'url', + 'wait_until'] @staticmethod def from_info_data(m, info): @@ -138,6 +139,8 @@ def from_info_data(m, info): file.hash = info.download.hash file.status = info.download.status file.error = info.download.error + + file.init_plugin() return file def __init__( @@ -177,8 +180,9 @@ def __init__( def get_size(self): """Get size of download.""" - if self.plugin.dl.size is not None: - self.self._size(self.plugin.dl.size) + if self.plugin is not None and self.plugin.dl is not None \ + and self.plugin.dl.size is not None: + self.set_size(self.plugin.dl.size) return self._size # NOTE: convert size to int @@ -209,7 +213,7 @@ def set_name(self, name): def __repr__(self): return ''.format( - self.id, self.name, self.pluginname) + self.fid, self.name, self.pluginname) @lock def init_plugin(self): @@ -299,7 +303,7 @@ def finish_if_done(self): """Set status to finish and release file if every thread is finished with it.""" # TODO: this is wrong now, it should check if addons are using it - if self.id in self.pyload.tsm.processing_ids(): + if self.fid in self.pyload.tsm.processing_ids(): return False self.set_status('finished') @@ -308,7 +312,7 @@ def finish_if_done(self): return True def check_if_processed(self): - self.manager.check_all_links_processed(self.id) + self.manager.check_all_links_processed(self.fid) @trycatch(0) def get_speed(self): diff --git a/pyload/core/datatype/package.py b/pyload/core/datatype/package.py index b27c162d57..24829dc104 100644 --- a/pyload/core/datatype/package.py +++ b/pyload/core/datatype/package.py @@ -80,8 +80,8 @@ class Package(BaseObject): """Represents a package object at runtime.""" __slots__ = ['added', 'comment', 'comment', 'folder', 'manager', 'name', 'ownerid', 'packageorder', 'password', 'password', 'pid', - 'root', 'set_finished', 'shared', 'site', 'site', 'status', - 'tags', 'timestamp'] + 'pyload', 'root', 'set_finished', 'shared', 'site', 'site', + 'status', 'tags', 'timestamp'] @staticmethod def from_info_data(m, info): diff --git a/pyload/core/manager/event.py b/pyload/core/manager/event.py index f0e30eb267..85d2eff279 100644 --- a/pyload/core/manager/event.py +++ b/pyload/core/manager/event.py @@ -67,6 +67,7 @@ def fire(self, event, *args, **kwargs): """Dispatches event with args.""" # dispatch the meta event if event != 'event': + self.pyload.log.debug(event) self.fire('event', *(event,) + args, **kwargs) if event in self.events: diff --git a/pyload/core/manager/file.py b/pyload/core/manager/file.py index c2756eaef2..f5c874e46c 100644 --- a/pyload/core/manager/file.py +++ b/pyload/core/manager/file.py @@ -102,7 +102,7 @@ def get_collector(self): @invalidate def add_links(self, data, pid, owner): """ - Add links, data = (url, plugin) tuple. Internal method should use API. + Add links, data = [(url, plugin)] list of tuples. Internal method should use API. """ self.db.add_links(data, pid, owner) self.pyload.evm.fire('package:updated', pid) diff --git a/pyload/core/network/hoster.py b/pyload/core/network/hoster.py index 0dc048aec6..818a275ad5 100644 --- a/pyload/core/network/hoster.py +++ b/pyload/core/network/hoster.py @@ -61,6 +61,7 @@ def get_info(urls): def __init__(self, file): # TODO: file.owner, but it's not correct yet super(Hoster, self).__init__(file.manager.pyload) + self._ = self.pyload._ self.want_reconnect = False # enables simultaneous processing of multiple downloads @@ -94,7 +95,7 @@ def __init__(self, file): self.dl = None # associated file instance, see `File` - self.filename = file + self.file = file self.thread = None # holds thread in future # location where the last call to download was saved diff --git a/pyload/core/network/loader.py b/pyload/core/network/loader.py index 4b306ef67e..37e8e81faa 100644 --- a/pyload/core/network/loader.py +++ b/pyload/core/network/loader.py @@ -146,7 +146,7 @@ def parse(self, folder): def parse_attributes(self, filename, name, folder=''): """Parse attribute dict from plugin.""" - with io.open(filename, mode='rb') as fp: + with io.open(filename, mode='r') as fp: content = fp.read() attrs = BaseAttributes() diff --git a/pyload/core/thread/download.py b/pyload/core/thread/download.py index 315c9f9ab2..af81ceeea8 100644 --- a/pyload/core/thread/download.py +++ b/pyload/core/thread/download.py @@ -34,7 +34,7 @@ def __init__(self, manager): @property def running(self): - return self.__running.is_set() + return self.__running def _handle_abort(self, file): self.pyload.log.info( @@ -190,7 +190,9 @@ def _run(self, file): def _finalize(self, file): self.pyload.files.save() file.check_if_processed() - sys.exc_clear() + if sys.version_info[0] < 3: + # not available in python 3 + sys.exc_clear() # manager could still be waiting for it self.__running.set() # only done when job was not put back diff --git a/pyload/core/thread/plugin.py b/pyload/core/thread/plugin.py index 4da354b6ec..1eb9408ccf 100644 --- a/pyload/core/thread/plugin.py +++ b/pyload/core/thread/plugin.py @@ -79,7 +79,7 @@ def _gen_reports(self, file): def _zip(self, filepath, reports, dumpdir): filename = os.path.basename(filepath) - with zipfile.ZipFile(filepath, 'wb') as zip: + with zipfile.ZipFile(filepath, 'w') as zip: for fname in os.listdir(dumpdir): try: arcname = os.path.join(filename, fname) diff --git a/requirements/install.txt b/requirements/install.txt index 8228ac373c..33ce4eb027 100644 --- a/requirements/install.txt +++ b/requirements/install.txt @@ -12,3 +12,4 @@ semver setuptools>=0.6.39 tld validators +enum34;python_version<="2.7" \ No newline at end of file