diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-07 19:36:10 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-07 19:36:10 +0200 |
commit | 0d2ae48fae0abb4274e477f54235d4f389b5e6b2 (patch) | |
tree | 061d13ca5bffdbb28df3cceb1d11dfebd7a8be02 /module/plugins/hooks/AntiVirus.py | |
parent | New plugin: UserAgentSwitcher (diff) | |
download | pyload-0d2ae48fae0abb4274e477f54235d4f389b5e6b2.tar.xz |
[AntiVirus] Recycle bin support
Diffstat (limited to 'module/plugins/hooks/AntiVirus.py')
-rw-r--r-- | module/plugins/hooks/AntiVirus.py | 38 |
1 files changed, 29 insertions, 9 deletions
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: |