diff options
Diffstat (limited to 'module/plugins/hooks/ExtractArchive.py')
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 173 |
1 files changed, 87 insertions, 86 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 925976bc6..73782ed95 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -70,7 +70,7 @@ class ArchiveQueue(object): def get(self): try: - return [int(pid) for pid in self.plugin.getStorage("ExtractArchive:%s" % self.storage, "").decode('base64').split()] + return [int(pid) for pid in self.plugin.retrieve("ExtractArchive:%s" % self.storage, "").decode('base64').split()] except Exception: return [] @@ -80,11 +80,11 @@ class ArchiveQueue(object): item = str(value)[1:-1].replace(' ', '').replace(',', ' ') else: item = str(value).strip() - return self.plugin.setStorage("ExtractArchive:%s" % self.storage, item.encode('base64')[:-1]) + return self.plugin.store("ExtractArchive:%s" % self.storage, item.encode('base64')[:-1]) def delete(self): - return self.plugin.delStorage("ExtractArchive:%s" % self.storage) + return self.plugin.delete("ExtractArchive:%s" % self.storage) def add(self, item): @@ -112,7 +112,7 @@ class ArchiveQueue(object): class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.45" + __version__ = "1.46" __config__ = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract with full paths" , True ), @@ -143,14 +143,15 @@ class ExtractArchive(Hook): def setup(self): self.info = {} #@TODO: Remove in 0.4.10 - self.event_list = ["allDownloadsProcessed","packageDeleted"] + self.event_map = {'allDownloadsProcessed': "all_downloads_processed", + 'packageDeleted' : "package_deleted" } self.queue = ArchiveQueue(self, "Queue") self.failed = ArchiveQueue(self, "Failed") self.interval = 60 self.extracting = False - self.lastPackage = False + self.last_package = False self.extractors = [] self.passwords = [] self.repair = False @@ -164,30 +165,30 @@ class ExtractArchive(Hook): if klass.isUsable(): self.extractors.append(klass) if klass.REPAIR: - self.repair = self.getConfig('repair') + self.repair = self.get_config('repair') except OSError, e: if e.errno == 2: - self.logWarning(_("No %s installed") % p) + self.log_warning(_("No %s installed") % p) else: - self.logWarning(_("Could not activate: %s") % p, e) + self.log_warning(_("Could not activate: %s") % p, e) if self.core.debug: traceback.print_exc() except Exception, e: - self.logWarning(_("Could not activate: %s") % p, e) + self.log_warning(_("Could not activate: %s") % p, e) if self.core.debug: traceback.print_exc() if self.extractors: - self.logDebug(*["Found %s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors]) - self.extractQueued() #: Resume unfinished extractions + self.log_debug(*["Found %s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors]) + self.extract_queued() #: Resume unfinished extractions else: - self.logInfo(_("No Extract plugins activated")) + self.log_info(_("No Extract plugins activated")) @threaded - def extractQueued(self, thread): + def extract_queued(self, thread): if self.extracting: #@NOTE: doing the check here for safty (called by coreReady) return @@ -195,8 +196,8 @@ class ExtractArchive(Hook): packages = self.queue.get() while packages: - if self.lastPackage: #: called from allDownloadsProcessed - self.lastPackage = False + if self.last_package: #: called from allDownloadsProcessed + self.last_package = False if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now self.manager.dispatchEvent("all_archives_extracted") self.manager.dispatchEvent("all_archives_processed") @@ -210,30 +211,30 @@ class ExtractArchive(Hook): @Expose - def extractPackage(self, *ids): + def extract_package(self, *ids): """ Extract packages with given id """ for id in ids: self.queue.add(id) - if not self.getConfig('waitall') and not self.extracting: - self.extractQueued() + if not self.get_config('waitall') and not self.extracting: + self.extract_queued() - def packageDeleted(self, pid): + def package_deleted(self, pid): self.queue.remove(pid) def package_finished(self, pypack): self.queue.add(pypack.id) - if not self.getConfig('waitall') and not self.extracting: - self.extractQueued() + if not self.get_config('waitall') and not self.extracting: + self.extract_queued() - def allDownloadsProcessed(self): - self.lastPackage = True - if self.getConfig('waitall') and not self.extracting: - self.extractQueued() + def all_downloads_processed(self): + self.last_package = True + if self.get_config('waitall') and not self.extracting: + self.extract_queued() @Expose @@ -247,23 +248,23 @@ class ExtractArchive(Hook): toList = lambda string: string.replace(' ', '').replace(',', '|').replace(';', '|').split('|') - destination = self.getConfig('destination') - subfolder = self.getConfig('subfolder') - fullpath = self.getConfig('fullpath') - overwrite = self.getConfig('overwrite') - renice = self.getConfig('renice') - recursive = self.getConfig('recursive') - delete = self.getConfig('delete') - keepbroken = self.getConfig('keepbroken') + destination = self.get_config('destination') + subfolder = self.get_config('subfolder') + fullpath = self.get_config('fullpath') + overwrite = self.get_config('overwrite') + renice = self.get_config('renice') + recursive = self.get_config('recursive') + delete = self.get_config('delete') + keepbroken = self.get_config('keepbroken') - extensions = [x.lstrip('.').lower() for x in toList(self.getConfig('extensions'))] - excludefiles = toList(self.getConfig('excludefiles')) + extensions = [x.lstrip('.').lower() for x in toList(self.get_config('extensions'))] + excludefiles = toList(self.get_config('excludefiles')) if extensions: - self.logDebug("Use for extensions: %s" % "|.".join(extensions)) + self.log_debug("Use for extensions: %s" % "|.".join(extensions)) #: reload from txt file - self.reloadPasswords() + self.reload_passwords() download_folder = self.core.config.get("general", "download_folder") @@ -275,7 +276,7 @@ class ExtractArchive(Hook): self.queue.remove(pid) continue - self.logInfo(_("Check package: %s") % pypack.name) + self.log_info(_("Check package: %s") % pypack.name) #: determine output folder out = fs_join(download_folder, pypack.folder, destination, "") #: force trailing slash @@ -302,17 +303,17 @@ class ExtractArchive(Hook): for Extractor in self.extractors: targets = Extractor.getTargets(files_ids) if targets: - self.logDebug("Targets for %s: %s" % (Extractor.__name__, targets)) + self.log_debug("Targets for %s: %s" % (Extractor.__name__, targets)) matched = True for fname, fid, fout in targets: name = os.path.basename(fname) if not os.path.exists(fname): - self.logDebug(name, "File not found") + self.log_debug(name, "File not found") continue - self.logInfo(name, _("Extract to: %s") % fout) + self.log_info(name, _("Extract to: %s") % fout) try: pyfile = self.core.files.getFile(fid) archive = Extractor(self, @@ -337,20 +338,20 @@ class ExtractArchive(Hook): thread.finishFile(pyfile) except Exception, e: - self.logError(name, e) + self.log_error(name, e) success = False continue #: 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.getDeleteFiles()] - self.logDebug("Extracted files: %s" % new_files) - self.setPermissions(new_files) + self.log_debug("Extracted files: %s" % new_files) + self.set_permissions(new_files) for filename in new_files: file = fs_encode(fs_join(os.path.dirname(archive.filename), filename)) if not os.path.exists(file): - self.logDebug("New file %s does not exists" % filename) + self.log_debug("New file %s does not exists" % filename) continue if recursive and os.path.isfile(file): @@ -371,7 +372,7 @@ class ExtractArchive(Hook): self.failed.add(pid) else: - self.logInfo(_("No files found to extract")) + self.log_info(_("No files found to extract")) if not matched or not success and subfolder: try: @@ -392,44 +393,44 @@ class ExtractArchive(Hook): encrypted = False try: - self.logDebug("Password: %s" % (password or "None provided")) - passwords = uniqify([password] + self.getPasswords(False)) if self.getConfig('usepasswordfile') else [password] + self.log_debug("Password: %s" % (password or "None provided")) + passwords = uniqify([password] + self.get_passwords(False)) if self.get_config('usepasswordfile') else [password] for pw in passwords: try: - if self.getConfig('test') or self.repair: + if self.get_config('test') or self.repair: pyfile.setCustomStatus(_("archive testing")) if pw: - self.logDebug("Testing with password: %s" % pw) + self.log_debug("Testing with password: %s" % pw) pyfile.setProgress(0) archive.verify(pw) pyfile.setProgress(100) else: archive.check(pw) - self.addPassword(pw) + self.add_password(pw) break except PasswordError: if not encrypted: - self.logInfo(name, _("Password protected")) + self.log_info(name, _("Password protected")) encrypted = True except CRCError, e: - self.logDebug(name, e) - self.logInfo(name, _("CRC Error")) + self.log_debug(name, e) + self.log_info(name, _("CRC Error")) if self.repair: - self.logWarning(name, _("Repairing...")) + self.log_warning(name, _("Repairing...")) pyfile.setCustomStatus(_("archive repairing")) pyfile.setProgress(0) repaired = archive.repair() pyfile.setProgress(100) - if not repaired and not self.getConfig('keepbroken'): + if not repaired and not self.get_config('keepbroken'): raise CRCError("Archive damaged") - self.addPassword(pw) + self.add_password(pw) break raise CRCError("Archive damaged") @@ -440,20 +441,20 @@ class ExtractArchive(Hook): pyfile.setCustomStatus(_("extracting")) pyfile.setProgress(0) - if not encrypted or not self.getConfig('usepasswordfile'): - self.logDebug("Extracting using password: %s" % (password or "None")) + if not encrypted or not self.get_config('usepasswordfile'): + self.log_debug("Extracting using password: %s" % (password or "None")) archive.extract(password) else: - for pw in filter(None, uniqify([password] + self.getPasswords(False))): + for pw in filter(None, uniqify([password] + self.get_passwords(False))): try: - self.logDebug("Extracting using password: %s" % pw) + self.log_debug("Extracting using password: %s" % pw) archive.extract(pw) - self.addPassword(pw) + self.add_password(pw) break except PasswordError: - self.logDebug("Password was wrong") + self.log_debug("Password was wrong") else: raise PasswordError @@ -461,12 +462,12 @@ class ExtractArchive(Hook): pyfile.setStatus("processing") delfiles = archive.getDeleteFiles() - self.logDebug("Would delete: " + ", ".join(delfiles)) + self.log_debug("Would delete: " + ", ".join(delfiles)) - if self.getConfig('delete'): - self.logInfo(_("Deleting %s files") % len(delfiles)) + if self.get_config('delete'): + self.log_info(_("Deleting %s files") % len(delfiles)) - deltotrash = self.getConfig('deltotrash') + deltotrash = self.get_config('deltotrash') for f in delfiles: file = fs_encode(f) if not os.path.exists(file): @@ -480,30 +481,30 @@ class ExtractArchive(Hook): send2trash.send2trash(file) except NameError: - self.logWarning(_("Unable to move %s to trash: Send2Trash lib not found") % os.path.basename(f)) + self.log_warning(_("Unable to move %s to trash: Send2Trash lib not found") % os.path.basename(f)) except Exception, e: - self.logWarning(_("Unable to move %s to trash: %s") % (os.path.basename(f), e.message)) + self.log_warning(_("Unable to move %s to trash: %s") % (os.path.basename(f), e.message)) else: - self.logDebug("Successfully moved %s to trash" % os.path.basename(f)) + self.log_debug("Successfully moved %s to trash" % os.path.basename(f)) - self.logInfo(name, _("Extracting finished")) + self.log_info(name, _("Extracting finished")) extracted_files = archive.files or archive.list() return extracted_files except PasswordError: - self.logError(name, _("Wrong password" if password else "No password found")) + self.log_error(name, _("Wrong password" if password else "No password found")) except CRCError, e: - self.logError(name, _("CRC mismatch"), e) + self.log_error(name, _("CRC mismatch"), e) except ArchiveError, e: - self.logError(name, _("Archive error"), e) + self.log_error(name, _("Archive error"), e) except Exception, e: - self.logError(name, _("Unknown error"), e) + self.log_error(name, _("Unknown error"), e) if self.core.debug: traceback.print_exc() @@ -513,50 +514,50 @@ class ExtractArchive(Hook): @Expose - def getPasswords(self, reload=True): + def get_passwords(self, reload=True): """ List of saved passwords """ if reload: - self.reloadPasswords() + self.reload_passwords() return self.passwords - def reloadPasswords(self): + def reload_passwords(self): try: passwords = [] - file = fs_encode(self.getConfig('passwordfile')) + file = fs_encode(self.get_config('passwordfile')) with open(file) as f: for pw in f.read().splitlines(): passwords.append(pw) except IOError, e: - self.logError(e) + self.log_error(e) else: self.passwords = passwords @Expose - def addPassword(self, password): + def add_password(self, password): """ Adds a password to saved list """ try: self.passwords = uniqify([password] + self.passwords) - file = fs_encode(self.getConfig('passwordfile')) + file = fs_encode(self.get_config('passwordfile')) with open(file, "wb") as f: for pw in self.passwords: f.write(pw + '\n') except IOError, e: - self.logError(e) + self.log_error(e) - def setPermissions(self, files): + def set_permissions(self, files): for f in files: if not os.path.exists(f): continue @@ -575,4 +576,4 @@ class ExtractArchive(Hook): os.chown(f, uid, gid) except Exception, e: - self.logWarning(_("Setting User and Group failed"), e) + self.log_warning(_("Setting User and Group failed"), e) |