summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-07 21:12:09 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-07 21:12:09 +0200
commita01a2dcb91bb2020aa4c7548a52ba98dbe43ceef (patch)
tree052c9c2605f3200615415ca07404d23509a645b7 /module/plugins/hooks
parent[AntiVirus] Recycle bin support (diff)
downloadpyload-a01a2dcb91bb2020aa4c7548a52ba98dbe43ceef.tar.xz
[ExtractArchive] Improve send2trash feature
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r--module/plugins/hooks/ExtractArchive.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index 8c40667c2..8b6a140cd 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -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.39"
+
+ __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):
@@ -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()