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/pyload/requests/base/request.py b/pyload/requests/base/request.py index 1c1bf7eff6..db879cc63a 100644 --- a/pyload/requests/base/request.py +++ b/pyload/requests/base/request.py @@ -75,7 +75,7 @@ def __init__(self, config, context=None, options=None, logger=None): self.config = config # Create a new context if not given - self.context = self.CONTEXT_CLASS if context is None else context + self.context = self.CONTEXT_CLASS() if context is None else context #instantiate CONTEXT_CLASS # Store options in dict self.options = {} if options is None else options @@ -85,7 +85,7 @@ def __init__(self, config, context=None, options=None, logger=None): # Last response code self.code = 0 self.flags = 0 - self.__abort = False + self._abort = False self.init_context() # TODO: content encoding? Could be handled globally @@ -131,7 +131,7 @@ def remove_auth(self): self.unset_option('auth') def abort(self): - self.__abort = True + self._abort = True def reset(self): """Resets the context to initial state.""" diff --git a/pyload/requests/cookie.py b/pyload/requests/cookie.py index 160f1247ec..0116e93665 100644 --- a/pyload/requests/cookie.py +++ b/pyload/requests/cookie.py @@ -21,7 +21,8 @@ class CookieJar(SimpleCookie): def set(self, domain, name, value, path='/', expires=None, secure=False, tailmatch=False): - self.__dict__[name] = to_str(value) + self.__dict__[name] = dict() + self.__dict__[name]['id'] = to_str(value) self.__dict__[name]['domain'] = to_str(domain) self.__dict__[name]['tailmatch'] = 'TRUE' if tailmatch else 'FALSE' self.__dict__[name]['path'] = to_str(path) diff --git a/pyload/utils/debug.py b/pyload/utils/debug.py index d37d69a300..68c1507f29 100644 --- a/pyload/utils/debug.py +++ b/pyload/utils/debug.py @@ -61,10 +61,10 @@ def print_dump(obj, file=None): print(text) -def _format_framestack(frame=None, limit=None): +def _format_framestack(limit=None): limit = None if not limit else abs(limit) stack = [] - _, value, tb = sys.exc_info(frame) + _, value, tb = sys.exc_info() try: while tb: stack.append(tb.tb_frame) @@ -91,7 +91,7 @@ def _format_framestack(frame=None, limit=None): def format_framestack(frame=None, limit=None): - framestack = _format_framestack(frame, limit) + framestack = _format_framestack(limit) stack_desc = [] for frame_name, frame_dump in framestack: dump = os.linesep.join( diff --git a/pyload/utils/fs.py b/pyload/utils/fs.py index 32e53efe5c..80bef6e618 100644 --- a/pyload/utils/fs.py +++ b/pyload/utils/fs.py @@ -321,10 +321,6 @@ def cleanpy(dirname, recursive=True): def remove(path, trash=False, ignore_errors=False): - trash = True #: test - print('TRASH') - print(path) - if not os.path.exists(path): if ignore_errors: return 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