diff options
author | sraedler <simon.raedler@yahoo.de> | 2015-04-08 01:58:10 +0200 |
---|---|---|
committer | sraedler <simon.raedler@yahoo.de> | 2015-04-08 01:58:10 +0200 |
commit | a59784a64f8afdca1642a0e53a396548a8608d61 (patch) | |
tree | a7eb9914bbc55bbc46f5a5f6929c6c6c95c81244 /module/plugins/hooks | |
parent | Fixed RemixshareCom (diff) | |
parent | [ExtractArchive] Fix https://github.com/pyload/pyload/issues/1322 (diff) | |
download | pyload-a59784a64f8afdca1642a0e53a396548a8608d61.tar.xz |
Merge pull request #1 from pyload/stable
merge with base
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r-- | module/plugins/hooks/AntiVirus.py | 38 | ||||
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 89 | ||||
-rw-r--r-- | module/plugins/hooks/IRCInterface.py | 4 | ||||
-rw-r--r-- | module/plugins/hooks/MergeFiles.py | 5 | ||||
-rw-r--r-- | module/plugins/hooks/UserAgentSwitcher.py | 32 |
5 files changed, 112 insertions, 56 deletions
diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index cc3c5c754..78f5aaa23 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -11,15 +11,16 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" #@TODO: add trash option (use Send2Trash lib) - __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), - ("quardir" , "folder" , "Quarantine folder" , "" ), - ("scanfailed", "bool" , "Scan incompleted files (failed downloads)", False ), - ("cmdfile" , "file" , "Antivirus executable" , "" ), - ("cmdargs" , "str" , "Scan options" , "" ), - ("ignore-err", "bool" , "Ignore scan errors" , False )] + __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), + ("quardir" , "folder" , "Quarantine folder" , "" ), + ("deltotrash", "bool" , "Move to trash (recycle bin) instead delete", True ), + ("scanfailed", "bool" , "Scan incompleted files (failed downloads)" , False ), + ("cmdfile" , "file" , "Antivirus executable" , "" ), + ("cmdargs" , "str" , "Scan options" , "" ), + ("ignore-err", "bool" , "Ignore scan errors" , False )] __description__ = """Scan downloaded files with antivirus program""" __license__ = "GPLv3" @@ -32,6 +33,16 @@ class AntiVirus(Hook): def setup(self): self.info = {} #@TODO: Remove in 0.4.10 + try: + import send2trash + + except ImportError: + self.logDebug(name, _("Send2Trash lib not found")) + self.trashable = False + + else: + self.trashable = True + @Expose @threaded @@ -46,6 +57,7 @@ class AntiVirus(Hook): thread.addActive(pyfile) pyfile.setCustomStatus(_("virus scanning")) + pyfile.setProgress(0) try: p = subprocess.Popen([cmdfile, cmdargs, file], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -66,11 +78,19 @@ class AntiVirus(Hook): action = self.getConfig('action') try: if action == "Delete": - os.remove(file) + if not self.getConfig('deltotrash'): + os.remove(file) + + elif self.trashable: + send2trash.send2trash(file) + + else: + self.logWarning(_("Unable to move file to trash, move to quarantine instead")) + pyfile.setCustomStatus(_("file moving")) + shutil.move(file, self.getConfig('quardir')) elif action == "Quarantine": pyfile.setCustomStatus(_("file moving")) - pyfile.setProgress(0) shutil.move(file, self.getConfig('quardir')) except (IOError, shutil.Error), e: diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 8c40667c2..b418f802f 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -4,9 +4,9 @@ from __future__ import with_statement import os import sys +import traceback from copy import copy -from traceback import print_exc # monkey patch bug in python 2.6 and lower # http://bugs.python.org/issue6122 , http://bugs.python.org/issue1236 , http://bugs.python.org/issue1731717 @@ -106,24 +106,25 @@ class ArchiveQueue(object): class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.38" - - __config__ = [("activated" , "bool" , "Activated" , True ), - ("fullpath" , "bool" , "Extract with full paths" , True ), - ("overwrite" , "bool" , "Overwrite files" , False ), - ("keepbroken" , "bool" , "Try to extract broken archives" , False ), - ("repair" , "bool" , "Repair broken archives (RAR required)" , False ), - ("test" , "bool" , "Test archive before extracting" , False ), - ("usepasswordfile", "bool" , "Use password file" , True ), - ("passwordfile" , "file" , "Password file" , "archive_password.txt" ), - ("delete" , "No;Permanent;Trash", "Delete archive after extraction" , "No" ), - ("subfolder" , "bool" , "Create subfolder for each package" , False ), - ("destination" , "folder" , "Extract files to folder" , "" ), - ("extensions" , "str" , "Extract archives ending with extension", "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"), - ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ), - ("recursive" , "bool" , "Extract archives in archives" , True ), - ("waitall" , "bool" , "Run after all downloads was processed" , False ), - ("renice" , "int" , "CPU priority" , 0 )] + __version__ = "1.40" + + __config__ = [("activated" , "bool" , "Activated" , True ), + ("fullpath" , "bool" , "Extract with full paths" , True ), + ("overwrite" , "bool" , "Overwrite files" , False ), + ("keepbroken" , "bool" , "Try to extract broken archives" , False ), + ("repair" , "bool" , "Repair broken archives (RAR required)" , False ), + ("test" , "bool" , "Test archive before extracting" , False ), + ("usepasswordfile", "bool" , "Use password file" , True ), + ("passwordfile" , "file" , "Password file" , "archive_password.txt" ), + ("delete" , "bool" , "Delete archive after extraction" , True ), + ("deltotrash" , "bool" , "Move to trash (recycle bin) instead delete", True ), + ("subfolder" , "bool" , "Create subfolder for each package" , False ), + ("destination" , "folder" , "Extract files to folder" , "" ), + ("extensions" , "str" , "Extract archives ending with extension" , "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"), + ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ), + ("recursive" , "bool" , "Extract archives in archives" , True ), + ("waitall" , "bool" , "Run after all downloads was processed" , False ), + ("renice" , "int" , "CPU priority" , 0 )] __description__ = """Extract different kind of archives""" __license__ = "GPLv3" @@ -148,7 +149,16 @@ class ExtractArchive(Hook): self.extractors = [] self.passwords = [] self.repair = False - self.trash = False + + try: + import send2trash + + except ImportError: + self.logDebug(name, _("Send2Trash lib not found")) + self.trashable = False + + else: + self.trashable = True def coreReady(self): @@ -167,12 +177,12 @@ class ExtractArchive(Hook): else: self.logWarning(_("Could not activate: %s") % p, e) if self.core.debug: - print_exc() + traceback.print_exc() except Exception, e: self.logWarning(_("Could not activate: %s") % p, e) if self.core.debug: - print_exc() + traceback.print_exc() if self.extractors: self.logInfo(_("Activated") + " " + "|".join("%s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors)) @@ -321,6 +331,7 @@ class ExtractArchive(Hook): new_files = self._extract(pyfile, archive, pypack.password) finally: + pyfile.setProgress(100) thread.finishFile(pyfile) except Exception, e: @@ -449,31 +460,25 @@ class ExtractArchive(Hook): pyfile.setStatus("processing") delfiles = archive.getDeleteFiles() - if self.core.debug: - self.logDebug("Would delete: %s" % ", ".join(delfiles)) + self.logDebug("Would delete: " + ", ".join(delfiles)) - if self.getConfig('delete') != 'No': - try: - from send2trash import send2trash - if self.getConfig('delete') == "Trash": - self.trash = True - self.logInfo(_("Sending %s files to trash") % len(delfiles)) - except ImportError: - self.logError(name, _("Send2Trash not installed, no files deleted")) - self.trash = False - - if self.getConfig('delete') == "Permanent": - self.trash = False - self.logInfo(_("Deleting %s files") % len(delfiles)) + if self.getConfig('delete'): + self.logInfo(_("Deleting %s files") % len(delfiles)) + deltotrash = self.getConfig('deltotrash') for f in delfiles: file = fs_encode(f) - if os.path.exists(file) and self.trash: - send2trash(file) - elif os.path.exists(file): + if not os.path.exists(file): + continue + + if not deltotrash: os.remove(file) + + elif self.trashable: + send2trash.send2trash(file) + else: - self.logDebug("%s does not exists" % f) + self.logWarning(_("Unable to move %s to trash") % os.path.basename(f)) self.logInfo(name, _("Extracting finished")) extracted_files = archive.files or archive.list() @@ -492,7 +497,7 @@ class ExtractArchive(Hook): except Exception, e: self.logError(name, _("Unknown error"), e) if self.core.debug: - print_exc() + traceback.print_exc() self.manager.dispatchEvent("archive_extract_failed", pyfile, archive) diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index d76b9cb85..9e2f670e6 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -4,11 +4,11 @@ import re import socket import ssl import time +import traceback from pycurl import FORM_FILE from select import select from threading import Thread -from traceback import print_exc from module.Api import PackageDoesNotExists, FileDoesNotExists from module.network.RequestFactory import getURL @@ -106,7 +106,7 @@ class IRCInterface(Thread, Hook): except IRCError, ex: self.sock.send("QUIT :byebye\r\n") - print_exc() + traceback.print_exc() self.sock.close() diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 2900b0d29..941938920 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -4,8 +4,7 @@ from __future__ import with_statement import os import re - -from traceback import print_exc +import traceback from module.plugins.Hook import Hook, threaded from module.utils import save_join @@ -75,7 +74,7 @@ class MergeFiles(Hook): self.logDebug("Finished merging part", splitted_file) except Exception, e: - print_exc() + traceback.print_exc() finally: pyfile.setProgress(100) diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py new file mode 100644 index 000000000..31eac9820 --- /dev/null +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +import pycurl + +from module.plugins.Hook import Hook + + +class UserAgentSwitcher(Hook): + __name__ = "UserAgentSwitcher" + __type__ = "hook" + __version__ = "0.02" + + __config__ = [("activated", "bool", "Activated" , True ), + ("ua" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] + + __description__ = """Custom user-agent""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + interval = 0 #@TODO: Remove in 0.4.10 + + + def setup(self): + self.info = {} #@TODO: Remove in 0.4.10 + + + def downloadPreparing(self, pyfile): + ua = self.getConfig('ua') + if ua: + self.logDebug("Use custom user-agent string: " + ua) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua) |