summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/ExtractArchive.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks/ExtractArchive.py')
-rw-r--r--module/plugins/hooks/ExtractArchive.py94
1 files changed, 42 insertions, 52 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index eab196160..9c662a897 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -4,11 +4,10 @@ from __future__ import with_statement
import os
import sys
-import traceback
# monkey patch bug in python 2.6 and lower
# http://bugs.python.org/issue6122 , http://bugs.python.org/issue1236 , http://bugs.python.org/issue1731717
-if sys.version_info < (2, 7) and os.name != "nt":
+if sys.version_info < (2, 7) and os.name is not "nt":
import errno
import subprocess
@@ -51,7 +50,7 @@ except ImportError:
pass
from module.plugins.internal.Addon import Addon, Expose, threaded
-from module.plugins.internal.Plugin import replace_patterns
+from module.plugins.internal.Plugin import exists, replace_patterns
from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError
from module.utils import fs_encode, save_join as fs_join, uniqify
@@ -66,6 +65,7 @@ class ArchiveQueue(object):
def get(self):
try:
return [int(pid) for pid in self.plugin.retrieve("ExtractArchive:%s" % self.storage, "").decode('base64').split()]
+
except Exception:
return []
@@ -107,26 +107,25 @@ class ArchiveQueue(object):
class ExtractArchive(Addon):
__name__ = "ExtractArchive"
__type__ = "hook"
- __version__ = "1.49"
+ __version__ = "1.51"
__status__ = "testing"
- __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" , "passwords.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 )]
+ __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 ),
+ ("usepasswordfile", "bool" , "Use password file" , True ),
+ ("passwordfile" , "file" , "Password file" , "passwords.txt" ),
+ ("delete" , "bool" , "Delete archive after extraction" , True ),
+ ("deltotrash" , "bool" , "Move to trash 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"
@@ -167,13 +166,9 @@ class ExtractArchive(Addon):
self.log_warning(_("No %s installed") % p)
else:
self.log_warning(_("Could not activate: %s") % p, e)
- if self.pyload.debug:
- traceback.print_exc()
except Exception, e:
self.log_warning(_("Could not activate: %s") % p, e)
- if self.pyload.debug:
- traceback.print_exc()
if self.extractors:
self.log_debug(*["Found %s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors])
@@ -288,7 +283,7 @@ class ExtractArchive(Addon):
if subfolder:
out = fs_join(out, pypack.folder)
- if not os.path.exists(out):
+ if not exists(out):
os.makedirs(out)
matched = False
@@ -313,7 +308,7 @@ class ExtractArchive(Addon):
for fname, fid, fout in targets:
name = os.path.basename(fname)
- if not os.path.exists(fname):
+ if not exists(fname):
self.log_debug(name, "File not found")
continue
@@ -348,7 +343,7 @@ class ExtractArchive(Addon):
#: Remove processed file and related multiparts from list
files_ids = [(fname, fid, fout) for fname, fid, fout in files_ids \
- if fname not in archive.get_delete_files()]
+ if fname not in archive.items()]
self.log_debug("Extracted files: %s" % new_files)
for file in new_files:
@@ -356,7 +351,7 @@ class ExtractArchive(Addon):
for filename in new_files:
file = fs_encode(fs_join(os.path.dirname(archive.filename), filename))
- if not os.path.exists(file):
+ if not exists(file):
self.log_debug("New file %s does not exists" % filename)
continue
@@ -403,18 +398,10 @@ class ExtractArchive(Addon):
passwords = uniqify([password] + self.get_passwords(False)) if self.get_config('usepasswordfile') else [password]
for pw in passwords:
try:
- if self.get_config('test') or self.repair:
- pyfile.setCustomStatus(_("archive testing"))
- if pw:
- self.log_debug("Testing with password: %s" % pw)
- pyfile.setProgress(0)
- archive.verify(pw)
- pyfile.setProgress(100)
- else:
- archive.check(pw)
-
- self.add_password(pw)
- break
+ pyfile.setCustomStatus(_("archive testing"))
+ pyfile.setProgress(0)
+ archive.verify(pw)
+ pyfile.setProgress(100)
except PasswordError:
if not encrypted:
@@ -425,9 +412,11 @@ class ExtractArchive(Addon):
self.log_debug(name, e)
self.log_info(name, _("CRC Error"))
- if self.repair:
- self.log_warning(name, _("Repairing..."))
+ if not self.repair:
+ raise CRCError("Archive damaged")
+ else:
+ self.log_warning(name, _("Repairing..."))
pyfile.setCustomStatus(_("archive repairing"))
pyfile.setProgress(0)
repaired = archive.repair()
@@ -436,15 +425,18 @@ class ExtractArchive(Addon):
if not repaired and not self.get_config('keepbroken'):
raise CRCError("Archive damaged")
- self.add_password(pw)
- break
-
- raise CRCError("Archive damaged")
+ else:
+ self.add_password(pw)
+ break
except ArchiveError, e:
raise ArchiveError(e)
- pyfile.setCustomStatus(_("extracting"))
+ else:
+ self.add_password(pw)
+ break
+
+ pyfile.setCustomStatus(_("archive extracting"))
pyfile.setProgress(0)
if not encrypted or not self.get_config('usepasswordfile'):
@@ -467,7 +459,7 @@ class ExtractArchive(Addon):
pyfile.setProgress(100)
pyfile.setStatus("processing")
- delfiles = archive.get_delete_files()
+ delfiles = archive.items()
self.log_debug("Would delete: " + ", ".join(delfiles))
if self.get_config('delete'):
@@ -476,7 +468,7 @@ class ExtractArchive(Addon):
deltotrash = self.get_config('deltotrash')
for f in delfiles:
file = fs_encode(f)
- if not os.path.exists(file):
+ if not exists(file):
continue
if not deltotrash:
@@ -513,8 +505,6 @@ class ExtractArchive(Addon):
except Exception, e:
self.log_error(name, _("Unknown error"), e)
- if self.pyload.debug:
- traceback.print_exc()
self.manager.dispatchEvent("archive_extract_failed", pyfile, archive)