From 9b8bd41059d87e120d2d64bc0e01e0a521ec1082 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 7 Mar 2015 03:32:50 +0100 Subject: New addon: AntiVirus --- module/plugins/hooks/AntiVirus.py | 85 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 module/plugins/hooks/AntiVirus.py (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py new file mode 100644 index 000000000..4bb2396d9 --- /dev/null +++ b/module/plugins/hooks/AntiVirus.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- + +import os +import subprocess + +from module.plugins.Hook import Hook, Expose, threaded +from module.utils import fs_encode, save_join + + +class AntiVirus(Hook): + __name__ = "AntiVirus" + __type__ = "hook" + __version__ = "0.01" + + __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), + ("quarpath" , "folder" , "Quarantine folder" , "" ), + ("scanfailed", "bool" , "Scan incompleted files (failed downloads)", False ), + ("cmdpath" , "file" , "Antivirus executable" , "" ), + ("cmdargs" , "str" , "Scan options" , "" )] + + __description__ = """Scan downloaded files with antivirus program""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + + @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')) + cmdargs = fs_encode(self.getConfig('cmdargs').strip()) + + if not os.path.isfile(filename) or not os.path.isfile(cmdpath): + return + + pyfile.setCustomStatus(_("virus scanning")) + thread.addActive(pyfile) + + try: + p = subprocess.Popen([cmdpath, cmdargs], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + out, err = map(str.strip, p.communicate()) + + if out: + self.logInfo(name, out) + + if err: + self.logWarning(name, err) + return + + if p.returncode: + action = self.getConfig('action') + try: + if action == "Delete": + os.remove(filename) + + elif action == "Quarantine": + new_filename = save_join(self.getConfig('quarpath'), name) + os.rename(filename, new_filename) + + except IOError, e: + self.logError(name, action + " action failed!", e) + + elif not out: + self.logDebug(name, "No virus found") + + finally: + thread.finishFile(pyfile) + + + def downloadFinished(self, pyfile): + return self.scan(pyfile) + + + def downloadFailed(self, pyfile): + #: Check if pyfile is still "failed", + # maybe might has been restarted in meantime + if pyfile.status == 8 and self.getConfig('scanfailed'): + return self.scan(pyfile) -- cgit v1.2.3 From c4f3a79f8ce19eab13ea7e53ff7a58fad43c6698 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 7 Mar 2015 03:39:08 +0100 Subject: [AntiVirus] Fix quarantine file moving --- module/plugins/hooks/AntiVirus.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 4bb2396d9..c5d6b8321 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import os +import shutil import subprocess from module.plugins.Hook import Hook, Expose, threaded @@ -10,7 +11,7 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.01" + __version__ = "0.02" __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), ("quarpath" , "folder" , "Quarantine folder" , "" ), @@ -62,9 +63,9 @@ class AntiVirus(Hook): elif action == "Quarantine": new_filename = save_join(self.getConfig('quarpath'), name) - os.rename(filename, new_filename) + shutil.move(filename, new_filename) - except IOError, e: + except (IOError, shutil.Error), e: self.logError(name, action + " action failed!", e) elif not out: -- cgit v1.2.3 From 3551cd44c7fad9cf5159d5920b6e8ec7aa3d1b9b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 7 Mar 2015 18:33:23 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/AntiVirus.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') 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) -- cgit v1.2.3 From 696ae23db1192f919961685f4026bb917b15868d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 7 Mar 2015 21:06:53 +0100 Subject: [AntiVirus] Missed something big! :P --- module/plugins/hooks/AntiVirus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 5dbc640ee..695852683 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -11,7 +11,7 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), ("quardir" , "folder" , "Quarantine folder" , "" ), @@ -45,7 +45,7 @@ class AntiVirus(Hook): pyfile.setCustomStatus(_("virus scanning")) try: - p = subprocess.Popen([cmdfile, cmdargs], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen([cmdfile, cmdargs, file], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = map(str.strip, p.communicate()) -- cgit v1.2.3 From 7beb65e991bc6d1913c3b5bb2ef69e659d5b8342 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 10 Mar 2015 01:55:52 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/AntiVirus.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 695852683..b8a659f99 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -13,7 +13,7 @@ class AntiVirus(Hook): __type__ = "hook" __version__ = "0.04" - __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), + __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), #@TODO: add trash option (use Send2Trash lib) ("quardir" , "folder" , "Quarantine folder" , "" ), ("scanfailed", "bool" , "Scan incompleted files (failed downloads)", False ), ("cmdfile" , "file" , "Antivirus executable" , "" ), @@ -55,7 +55,7 @@ class AntiVirus(Hook): if err: self.logWarning(filename, err) if not self.getConfig('ignore-err') - self.logDebug("Delete/Quarantine action aborted") + self.logDebug("Delete/Quarantine task is aborted") return if p.returncode: @@ -68,8 +68,7 @@ class AntiVirus(Hook): elif action == "Quarantine": pyfile.setCustomStatus(_("file moving")) pyfile.setProgress(0) - new_filename = save_join(self.getConfig('quardir'), filename) - shutil.move(file, new_filename) + shutil.move(file, self.getConfig('quardir')) except (IOError, shutil.Error), e: self.logError(filename, action + " action failed!", e) -- cgit v1.2.3 From 2bc144adb6bc2759b635e09687b27bf96074827f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 18 Mar 2015 13:39:07 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/AntiVirus.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index b8a659f99..ffed86836 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -30,6 +30,10 @@ class AntiVirus(Hook): pass + def setup(self): + self.info = {} #@TODO: Remove in 0.4.10 + + @Expose @threaded def scan(self, pyfile, thread): -- cgit v1.2.3 From 25d7ae217d675d51110da5225e3d5c52202e8e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=B6rnlein?= Date: Sun, 22 Mar 2015 16:13:48 +0100 Subject: [AntiVirus] Typo & Remove Comment within Array --- module/plugins/hooks/AntiVirus.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index ffed86836..6f88b982a 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -11,9 +11,10 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" - __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), #@TODO: add trash option (use Send2Trash lib) + #@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" , "" ), @@ -58,7 +59,7 @@ class AntiVirus(Hook): if err: self.logWarning(filename, err) - if not self.getConfig('ignore-err') + if not self.getConfig('ignore-err'): self.logDebug("Delete/Quarantine task is aborted") return -- cgit v1.2.3 From f1ce338ed31e49373cea5453a2fbdb6c686ca510 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 26 Mar 2015 10:16:04 +0100 Subject: interval code cosmetics --- module/plugins/hooks/AntiVirus.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 6f88b982a..cc3c5c754 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -26,9 +26,7 @@ class AntiVirus(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - #@TODO: Remove in 0.4.10 - def initPeriodical(self): - pass + interval = 0 #@TODO: Remove in 0.4.10 def setup(self): -- cgit v1.2.3 From 0d2ae48fae0abb4274e477f54235d4f389b5e6b2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 7 Apr 2015 19:36:10 +0200 Subject: [AntiVirus] Recycle bin support --- module/plugins/hooks/AntiVirus.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index cc3c5c754..f94d8d205 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: -- cgit v1.2.3 From 034d87c836f9fba82142a06b5f666c84ca10bd50 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 7 Apr 2015 21:26:23 +0200 Subject: [YadiSk] Fix https://github.com/pyload/pyload/issues/1321 --- module/plugins/hooks/AntiVirus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index f94d8d205..78f5aaa23 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -85,7 +85,7 @@ class AntiVirus(Hook): send2trash.send2trash(file) else: - self.logWarning("Unable to move file to trash, move to quarantine instead") + self.logWarning(_("Unable to move file to trash, move to quarantine instead")) pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) -- cgit v1.2.3 From c5bd9e25f08248834aa6192b60ab968e95a10dc1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 8 Apr 2015 04:32:51 +0200 Subject: [AntiVirus][ExtractArchive] Fixup --- module/plugins/hooks/AntiVirus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 78f5aaa23..27e3801b5 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -11,7 +11,7 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.06" + __version__ = "0.07" #@TODO: add trash option (use Send2Trash lib) __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), @@ -37,7 +37,7 @@ class AntiVirus(Hook): import send2trash except ImportError: - self.logDebug(name, _("Send2Trash lib not found")) + self.logDebug("Send2Trash lib not found") self.trashable = False else: -- cgit v1.2.3 From 711621f3d3a59f7ec5c2684dfac921e2c5902563 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 May 2015 02:54:22 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1351 --- module/plugins/hooks/AntiVirus.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 27e3801b5..ac9373a37 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -4,6 +4,11 @@ import os import shutil import subprocess +try: + import send2trash +except ImportError: + pass + from module.plugins.Hook import Hook, Expose, threaded from module.utils import fs_encode, save_join @@ -11,7 +16,7 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.07" + __version__ = "0.08" #@TODO: add trash option (use Send2Trash lib) __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), @@ -33,16 +38,6 @@ class AntiVirus(Hook): def setup(self): self.info = {} #@TODO: Remove in 0.4.10 - try: - import send2trash - - except ImportError: - self.logDebug("Send2Trash lib not found") - self.trashable = False - - else: - self.trashable = True - @Expose @threaded @@ -81,13 +76,14 @@ class AntiVirus(Hook): 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')) + try: + send2trash.send2trash(file) + + except Exception: + 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")) -- cgit v1.2.3 From fc36aa1a426fb8c75897debdc6cb4104dbff8200 Mon Sep 17 00:00:00 2001 From: GammaC0de Date: Sat, 2 May 2015 22:36:02 +0300 Subject: [AntiVirus] report missing send2trash --- module/plugins/hooks/AntiVirus.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index ac9373a37..69dffbe73 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -16,7 +16,7 @@ from module.utils import fs_encode, save_join class AntiVirus(Hook): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.08" + __version__ = "0.09" #@TODO: add trash option (use Send2Trash lib) __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), @@ -80,8 +80,13 @@ class AntiVirus(Hook): try: send2trash.send2trash(file) - except Exception: - self.logWarning(_("Unable to move file to trash, move to quarantine instead")) + except NameError: + self.logWarning(_("Send2Trash lib not found, moving to quarantine instead")) + pyfile.setCustomStatus(_("file moving")) + shutil.move(file, self.getConfig('quardir')) + + except Exception: + self.logWarning(_("Unable to move file to trash, moving to quarantine instead")) pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) -- cgit v1.2.3 From dc7c81b6ab0813745ee03116c27f870138b3fc7f Mon Sep 17 00:00:00 2001 From: GammaC0de Date: Mon, 4 May 2015 01:36:23 +0300 Subject: more verbose --- module/plugins/hooks/AntiVirus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 69dffbe73..6823729af 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -85,8 +85,8 @@ class AntiVirus(Hook): pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) - except Exception: - self.logWarning(_("Unable to move file to trash, moving to quarantine instead")) + except Exception, e: + self.logWarning(_("Unable to move file to trash: %s, moving to quarantine instead") % e.message) pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) -- cgit v1.2.3 From ee360021434803991226d1cc36e7221fb9cbc418 Mon Sep 17 00:00:00 2001 From: GammaC0de Date: Mon, 4 May 2015 02:24:23 +0300 Subject: even more --- module/plugins/hooks/AntiVirus.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/AntiVirus.py') diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 6823729af..c620f556d 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -85,11 +85,14 @@ class AntiVirus(Hook): pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) - except Exception, e: + except Exception, e: self.logWarning(_("Unable to move file to trash: %s, moving to quarantine instead") % e.message) pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) + else: + self.logDebug(_("Successfully moved file to trash")) + elif action == "Quarantine": pyfile.setCustomStatus(_("file moving")) shutil.move(file, self.getConfig('quardir')) -- cgit v1.2.3