diff options
author | Walter Purcaro <vuolter@gmail.com> | 2015-03-07 18:33:23 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2015-03-07 18:33:23 +0100 |
commit | 3551cd44c7fad9cf5159d5920b6e8ec7aa3d1b9b (patch) | |
tree | 8b3b2dfad2ba828d5dfb40eaaece76e18a771d66 /module | |
parent | [AntiVirus] Fix quarantine file moving (diff) | |
download | pyload-3551cd44c7fad9cf5159d5920b6e8ec7aa3d1b9b.tar.xz |
Spare code cosmetics
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/AntiVirus.py | 45 | ||||
-rw-r--r-- | module/plugins/hooks/SkipRev.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/SevenZip.py | 9 | ||||
-rw-r--r-- | module/plugins/internal/UnRar.py | 14 |
4 files changed, 39 insertions, 33 deletions
diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index c5d6b8321..5dbc640ee 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -11,13 +11,14 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.02" + __version__ = "0.03" __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), - ("quarpath" , "folder" , "Quarantine folder" , "" ), + ("quardir" , "folder" , "Quarantine folder" , "" ), ("scanfailed", "bool" , "Scan incompleted files (failed downloads)", False ), - ("cmdpath" , "file" , "Antivirus executable" , "" ), - ("cmdargs" , "str" , "Scan options" , "" )] + ("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,46 +33,52 @@ class AntiVirus(Hook): @Expose @threaded def scan(self, pyfile, thread): - name = os.path.basename(pyfile.plugin.lastDownload) - filename = fs_encode(pyfile.plugin.lastDownload) - cmdpath = fs_encode(self.getConfig('cmdpath')) + file = fs_encode(pyfile.plugin.lastDownload) + filename = os.path.basename(pyfile.plugin.lastDownload) + cmdfile = fs_encode(self.getConfig('cmdfile')) cmdargs = fs_encode(self.getConfig('cmdargs').strip()) - if not os.path.isfile(filename) or not os.path.isfile(cmdpath): + if not os.path.isfile(file) or not os.path.isfile(cmdfile): return - pyfile.setCustomStatus(_("virus scanning")) thread.addActive(pyfile) + pyfile.setCustomStatus(_("virus scanning")) try: - p = subprocess.Popen([cmdpath, cmdargs], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen([cmdfile, cmdargs], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = map(str.strip, p.communicate()) if out: - self.logInfo(name, out) + self.logInfo(filename, out) if err: - self.logWarning(name, err) - return + self.logWarning(filename, err) + if not self.getConfig('ignore-err') + self.logDebug("Delete/Quarantine action aborted") + return if p.returncode: + pyfile.error = _("infected file") action = self.getConfig('action') try: if action == "Delete": - os.remove(filename) + os.remove(file) elif action == "Quarantine": - new_filename = save_join(self.getConfig('quarpath'), name) - shutil.move(filename, new_filename) + pyfile.setCustomStatus(_("file moving")) + pyfile.setProgress(0) + new_filename = save_join(self.getConfig('quardir'), filename) + shutil.move(file, new_filename) except (IOError, shutil.Error), e: - self.logError(name, action + " action failed!", e) + self.logError(filename, action + " action failed!", e) - elif not out: - self.logDebug(name, "No virus found") + elif not out and not err: + self.logDebug(filename, "No infected file found") finally: + pyfile.setProgress(100) thread.finishFile(pyfile) diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index a4d46316e..521c2c39e 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -22,8 +22,8 @@ class SkipRev(Hook): __type__ = "hook" __version__ = "0.28" - __config__ = [("mode" , "Auto;Manual", "Choose rev files to keep for package", "Auto"), - ("revtokeep", "int" , "Custom number of files to keep" , 0 )] + __config__ = [("mode" , "Auto;Manual", "Choose rev files to skip for package", "Auto"), + ("revtokeep", "int" , "Number of rev files to keep" , 0 )] __description__ = """Skip files ending with extension rev""" __license__ = "GPLv3" diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index b5b113566..82901f8cc 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -2,8 +2,7 @@ import os import re - -from subprocess import Popen, PIPE +import subprocess from module.plugins.internal.UnRar import ArchiveError, CRCError, PasswordError, UnRar, renice from module.utils import fs_encode, save_join @@ -41,10 +40,10 @@ class SevenZip(UnRar): def isUsable(cls): if os.name == "nt": cls.CMD = os.path.join(pypath, "7z.exe") - p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) + p = subprocess.Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err = p.communicate() else: - p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) + p = subprocess.Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() m = cls.re_version.search(out) @@ -150,5 +149,5 @@ class SevenZip(UnRar): self.manager.logDebug(" ".join(call)) - p = Popen(call, stdout=PIPE, stderr=PIPE) + p = subprocess.Popen(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return p diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 220dd6365..baa5d3115 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -2,10 +2,10 @@ import os import re +import subprocess from glob import glob from string import digits -from subprocess import Popen, PIPE from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError from module.utils import fs_decode, fs_encode, save_join @@ -14,7 +14,7 @@ from module.utils import fs_decode, fs_encode, save_join def renice(pid, value): if value and os.name != "nt": try: - Popen(["renice", str(value), str(pid)], stdout=PIPE, stderr=PIPE, bufsize=-1) + subprocess.Popen(["renice", str(value), str(pid)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1) except Exception: pass @@ -52,24 +52,24 @@ class UnRar(Extractor): if os.name == "nt": try: cls.CMD = os.path.join(pypath, "RAR.exe") - p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) + p = subprocess.Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() cls.__name__ = "RAR" cls.REPAIR = True except OSError: cls.CMD = os.path.join(pypath, "UnRAR.exe") - p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) + p = Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() else: try: - p = Popen(["rar"], stdout=PIPE, stderr=PIPE) + p = Popen(["rar"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() cls.__name__ = "RAR" cls.REPAIR = True except OSError: #: fallback to unrar - p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) + p = Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() m = cls.re_version.search(out) @@ -244,5 +244,5 @@ class UnRar(Extractor): self.manager.logDebug(" ".join(call)) - p = Popen(call, stdout=PIPE, stderr=PIPE) + p = Popen(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return p |