diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-09-18 18:08:15 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-09-18 18:08:15 +0200 |
commit | 5ebf3e854216b4b25e273f8873f7203c5a82fadd (patch) | |
tree | e2c7c30fdcae6c014c00d2262d89ea606bc83309 /module/plugins/addons | |
parent | merged stable into default (diff) | |
parent | Backed out changeset e7db858d5ab2 (diff) | |
download | pyload-5ebf3e854216b4b25e273f8873f7203c5a82fadd.tar.xz |
merge newest changes
Diffstat (limited to 'module/plugins/addons')
-rw-r--r-- | module/plugins/addons/Checksum.py | 21 | ||||
-rw-r--r-- | module/plugins/addons/IRCInterface.py | 28 | ||||
-rw-r--r-- | module/plugins/addons/UnSkipOnFail.py | 97 |
3 files changed, 128 insertions, 18 deletions
diff --git a/module/plugins/addons/Checksum.py b/module/plugins/addons/Checksum.py index cb6f4bfe8..aec4bd0d7 100644 --- a/module/plugins/addons/Checksum.py +++ b/module/plugins/addons/Checksum.py @@ -18,6 +18,7 @@ """ from __future__ import with_statement import hashlib, zlib +from os import remove from os.path import getsize, isfile from module.utils import save_join, fs_encode @@ -49,7 +50,7 @@ def computeChecksum(local_file, algorithm): class Checksum(Hook): __name__ = "Checksum" - __version__ = "0.05" + __version__ = "0.06" __description__ = "Verify downloaded file size and checksum (enable in general preferences)" __config__ = [("activated", "bool", "Activated", True), ("action", "fail;retry;nothing", "What to do if check fails?", "retry"), @@ -80,11 +81,15 @@ class Checksum(Hook): self.logDebug(data) - download_folder = self.config['general']['download_folder'] - local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name)) + if not pyfile.plugin.lastDownload: + self.checkFailed(pyfile, None, "No file downloaded") + + local_file = fs_encode(pyfile.plugin.lastDownload) + #download_folder = self.config['general']['download_folder'] + #local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name)) if not isfile(local_file): - self.checkFailed(pyfile, "File does not exist") + self.checkFailed(pyfile, None, "File does not exist") # validate file size if "size" in data: @@ -92,7 +97,7 @@ class Checksum(Hook): file_size = getsize(local_file) if api_size != file_size: self.logWarning("File %s has incorrect size: %d B (%d expected)" % (pyfile.name, file_size, api_size)) - self.checkFailed(pyfile, "Incorrect file size") + self.checkFailed(pyfile, local_file, "Incorrect file size") del data['size'] # validate checksum @@ -109,15 +114,17 @@ class Checksum(Hook): return else: self.logWarning("%s checksum for file %s does not match (%s != %s)" % (key.upper(), pyfile.name, checksum, data[key])) - self.checkFailed(pyfile, "Checksums do not match") + self.checkFailed(pyfile, local_file, "Checksums do not match") else: self.logWarning("Unsupported hashing algorithm: %s" % key.upper()) else: self.logWarning("Unable to validate checksum for file %s" % (pyfile.name)) - def checkFailed(self, pyfile, msg): + def checkFailed(self, pyfile, local_file, msg): action = self.getConfig("action") if action == "fail": pyfile.plugin.fail(reason = msg) elif action == "retry": + if local_file: + remove(local_file) pyfile.plugin.retry(reason = msg, max_tries = self.getConfig("max_tries"))
\ No newline at end of file diff --git a/module/plugins/addons/IRCInterface.py b/module/plugins/addons/IRCInterface.py index ddaa40613..c261fc6f3 100644 --- a/module/plugins/addons/IRCInterface.py +++ b/module/plugins/addons/IRCInterface.py @@ -30,6 +30,7 @@ import re from module.plugins.Addon import Addon from module.network.RequestFactory import getURL from module.utils import formatSize +from module.Api import PackageDoesNotExists, FileDoesNotExists from pycurl import FORM_FILE @@ -236,25 +237,25 @@ class IRCInterface(Thread, Addon): return lines def event_queue(self, args): - ps = self.api.getQueue() + ps = self.api.getQueueData() if not ps: return ["INFO: There are no packages in queue."] lines = [] for pack in ps: - lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.fids) )) + lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links) )) return lines def event_collector(self, args): - ps = self.api.getCollector() + ps = self.api.getCollectorData() if not ps: return ["INFO: No packages in collector!"] lines = [] for pack in ps: - lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.fids) )) + lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links) )) return lines @@ -262,12 +263,14 @@ class IRCInterface(Thread, Addon): if not args: return ['ERROR: Use info like this: info <id>'] - info = self.api.getFileData(int(args[0])) + info = None + try: + info = self.api.getFileData(int(args[0])) - if not info: + except FileDoesNotExists: return ["ERROR: Link doesn't exists."] - return ['LINK #%s: %s (%s) [%s][%s]' % (info.fid, info.name, info.format_size, info.status_msg, + return ['LINK #%s: %s (%s) [%s][%s]' % (info.fid, info.name, info.format_size, info.statusmsg, info.plugin)] def event_packinfo(self, args): @@ -275,9 +278,11 @@ class IRCInterface(Thread, Addon): return ['ERROR: Use packinfo like this: packinfo <id>'] lines = [] - pack = self.api.getPackageData(int(args[0])) + pack = None + try: + pack = self.api.getPackageData(int(args[0])) - if not pack: + except PackageDoesNotExists: return ["ERROR: Package doesn't exists."] id = args[0] @@ -369,7 +374,9 @@ class IRCInterface(Thread, Addon): return ["ERROR: Push package to queue like this: push <package id>"] id = int(args[0]) - if not self.api.getPackage_data(id): + try: + info = self.api.getPackageInfo(id) + except PackageDoesNotExists: return ["ERROR: Package #%d does not exist." % id] self.api.pushToQueue(id) @@ -419,7 +426,6 @@ class IRCInterface(Thread, Addon): class IRCError(Exception): def __init__(self, value): - Exception.__init__(value) self.value = value def __str__(self): return repr(self.value) diff --git a/module/plugins/addons/UnSkipOnFail.py b/module/plugins/addons/UnSkipOnFail.py new file mode 100644 index 000000000..4b7a58be8 --- /dev/null +++ b/module/plugins/addons/UnSkipOnFail.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: hgg +""" +from os.path import basename + +from module.utils import fs_encode +from module.plugins.Hook import Hook +from module.PyFile import PyFile + +class UnSkipOnFail(Hook): + __name__ = 'UnSkipOnFail' + __version__ = '0.01' + __description__ = 'When a download fails, restart "skipped" duplicates.' + __config__ = [('activated', 'bool', 'Activated', True),] + __author_name__ = ('hagg',) + __author_mail__ = ('') + + def downloadFailed(self, pyfile): + pyfile_name = basename(pyfile.name) + pid = pyfile.package().id + msg = 'look for skipped duplicates for %s (pid:%s)...' + self.logInfo(msg % (pyfile_name, pid)) + dups = self.findDuplicates(pyfile) + for link in dups: + # check if link is "skipped"(=4) + if link.status == 4: + lpid = link.packageID + self.logInfo('restart "%s" (pid:%s)...' % (pyfile_name, lpid)) + self.setLinkStatus(link, "queued") + + def findDuplicates(self, pyfile): + """ Search all packages for duplicate links to "pyfile". + Duplicates are links that would overwrite "pyfile". + To test on duplicity the package-folder and link-name + of twolinks are compared (basename(link.name)). + So this method returns a list of all links with equal + package-folders and filenames as "pyfile", but except + the data for "pyfile" iotselöf. + It does MOT check the link's status. + """ + dups = [] + pyfile_name = fs_encode(basename(pyfile.name)) + # get packages (w/o files, as most file data is useless here) + queue = self.core.api.getQueue() + for package in queue: + # check if package-folder equals pyfile's package folder + if fs_encode(package.folder) == fs_encode(pyfile.package().folder): + # now get packaged data w/ files/links + pdata = self.core.api.getPackageData(package.pid) + if pdata.links: + for link in pdata.links: + link_name = fs_encode(basename(link.name)) + # check if link name collides with pdata's name + if link_name == pyfile_name: + # at last check if it is not pyfile itself + if link.fid != pyfile.id: + dups.append(link) + return dups + + def setLinkStatus(self, link, new_status): + """ Change status of "link" to "new_status". + "link" has to be a valid FileData object, + "new_status" has to be a valid status name + (i.e. "queued" for this Plugin) + It creates a temporary PyFile object using + "link" data, changes its status, and tells + the core.files-manager to save its data. + """ + pyfile = PyFile(self.core.files, + link.fid, + link.url, + link.name, + link.size, + link.status, + link.error, + link.plugin, + link.packageID, + link.order) + pyfile.setStatus(new_status) + self.core.files.save() + pyfile.release() + |