diff options
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/Account.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/Captcha.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/Container.py | 8 | ||||
-rw-r--r-- | module/plugins/internal/Crypter.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/Hook.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/OCR.py | 8 | ||||
-rw-r--r-- | module/plugins/internal/Plugin.py | 44 | ||||
-rw-r--r-- | module/plugins/internal/SevenZip.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/UnRar.py | 10 |
9 files changed, 43 insertions, 47 deletions
diff --git a/module/plugins/internal/Account.py b/module/plugins/internal/Account.py index 27a040e24..aa472f297 100644 --- a/module/plugins/internal/Account.py +++ b/module/plugins/internal/Account.py @@ -5,7 +5,7 @@ import threading import time import traceback -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin from module.utils import compare_time, lock, parseFileSize @@ -13,7 +13,7 @@ class WrongPassword(Exception): pass -class Account(Base): +class Account(Plugin): __name__ = "Account" __type__ = "account" __version__ = "0.03" diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index e5a44d750..8d040515c 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin #@TODO: Extend (new) Plugin class; remove all `html` args -class Captcha(Base): +class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" __version__ = "0.30" diff --git a/module/plugins/internal/Container.py b/module/plugins/internal/Container.py index 3b3eb88aa..097b04ac7 100644 --- a/module/plugins/internal/Container.py +++ b/module/plugins/internal/Container.py @@ -6,7 +6,7 @@ import os import re from module.plugins.internal.Crypter import Crypter -from module.utils import save_join +from module.utils import save_join as fs_join class Container(Crypter): @@ -43,7 +43,7 @@ class Container(Crypter): if self.pyfile.url.startswith("http"): self.pyfile.name = re.findall("([^\/=]+)", self.pyfile.url)[-1] content = self.load(self.pyfile.url) - self.pyfile.url = save_join(self.core.config.get("general", "download_folder"), self.pyfile.name) + self.pyfile.url = fs_join(self.core.config.get("general", "download_folder"), self.pyfile.name) try: with open(self.pyfile.url, "wb") as f: f.write(content) @@ -53,8 +53,8 @@ class Container(Crypter): else: self.pyfile.name = os.path.basename(self.pyfile.url) if not os.path.exists(self.pyfile.url): - if os.path.exists(save_join(pypath, self.pyfile.url)): - self.pyfile.url = save_join(pypath, self.pyfile.url) + if os.path.exists(fs_join(pypath, self.pyfile.url)): + self.pyfile.url = fs_join(pypath, self.pyfile.url) else: self.fail(_("File not exists")) diff --git a/module/plugins/internal/Crypter.py b/module/plugins/internal/Crypter.py index 5fb9bc5c2..39b09129f 100644 --- a/module/plugins/internal/Crypter.py +++ b/module/plugins/internal/Crypter.py @@ -3,7 +3,7 @@ import urlparse from module.plugins.internal.Plugin import Plugin -from module.utils import decode, save_path +from module.utils import decode, save_path as safe_filename class Crypter(Plugin): @@ -98,7 +98,7 @@ class Crypter(Plugin): if not folder: folder = urlparse.urlparse(name).path.split("/")[-1] - setFolder(save_path(folder)) + setFolder(safe_filename(folder)) self.logDebug("Set package %(name)s folder to: %(folder)s" % {"name": name, "folder": folder}) elif folder_per_package: diff --git a/module/plugins/internal/Hook.py b/module/plugins/internal/Hook.py index 7d785ded0..8d620e794 100644 --- a/module/plugins/internal/Hook.py +++ b/module/plugins/internal/Hook.py @@ -2,7 +2,7 @@ import traceback -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin class Expose(object): @@ -21,7 +21,7 @@ def threaded(fn): return run -class Hook(Base): +class Hook(Plugin): __name__ = "Hook" __type__ = "hook" __version__ = "0.08" diff --git a/module/plugins/internal/OCR.py b/module/plugins/internal/OCR.py index 2349d32af..1782e17f0 100644 --- a/module/plugins/internal/OCR.py +++ b/module/plugins/internal/OCR.py @@ -13,7 +13,7 @@ import os import subprocess #import tempfile -from module.utils import save_join +from module.utils import save_join as fs_join class OCR(object): @@ -59,11 +59,11 @@ class OCR(object): def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True): #tmpTif = tempfile.NamedTemporaryFile(suffix=".tif") try: - tmpTif = open(save_join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") + tmpTif = open(fs_join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") tmpTif.close() #tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt") - tmpTxt = open(save_join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") + tmpTxt = open(fs_join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") tmpTxt.close() except IOError, e: @@ -82,7 +82,7 @@ class OCR(object): if subset and (digits or lowercase or uppercase): #tmpSub = tempfile.NamedTemporaryFile(suffix=".subset") - with open(save_join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: + with open(fs_join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: tmpSub.write("tessedit_char_whitelist ") if digits: diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 16aa9cc45..da597ef42 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -32,7 +32,7 @@ if os.name != "nt": from itertools import islice from module.plugins.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload as Skip #@TODO: Remove in 0.4.10 -from module.utils import save_join, save_path, fs_encode, fs_decode +from module.utils import save_join as fs_join, save_path as safe_filename, fs_encode, fs_decode def chunks(iterable, size): it = iter(iterable) @@ -50,10 +50,6 @@ class Base(object): def __init__(self, core): #: Core instance self.core = core - #: logging instance - self.log = core.log - #: core config - self.config = core.config #: Log functions @@ -183,7 +179,7 @@ class Plugin(Base): def __init__(self, pyfile): - Base.__init__(self, pyfile.m.core) + super(Plugin, self).__init__(pyfile.m.core) self.wantReconnect = False #: enables simultaneous processing of multiple downloads @@ -239,8 +235,8 @@ class Plugin(Base): def getChunkCount(self): if self.chunkLimit <= 0: - return self.config["download"]["chunks"] - return min(self.config["download"]["chunks"], self.chunkLimit) + return self.core.config["download"]["chunks"] + return min(self.core.config["download"]["chunks"], self.chunkLimit) def __call__(self): return self.__name__ @@ -416,7 +412,7 @@ class Plugin(Base): self.fail(_("No captcha result obtained in appropiate time by any of the plugins.")) result = task.result - self.log.debug("Received captcha result: %s" % str(result)) + self.core.log.debug("Received captcha result: %s" % str(result)) if not self.core.debug: try: @@ -504,25 +500,25 @@ class Plugin(Base): self.pyfile.setStatus("downloading") - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] - location = save_join(download_folder, self.pyfile.package().folder) + location = fs_join(download_folder, self.pyfile.package().folder) if not exists(location): makedirs(location, int(self.core.config["permission"]["folder"], 8)) if self.core.config["permission"]["change_dl"] and os.name != "nt": try: - uid = getpwnam(self.config["permission"]["user"])[2] - gid = getgrnam(self.config["permission"]["group"])[2] + uid = getpwnam(self.core.config["permission"]["user"])[2] + gid = getgrnam(self.core.config["permission"]["group"])[2] chown(location, uid, gid) except Exception, e: - self.log.warning(_("Setting User and Group failed: %s") % str(e)) + self.core.log.warning(_("Setting User and Group failed: %s") % str(e)) # convert back to unicode location = fs_decode(location) - name = save_path(self.pyfile.name) + name = safe_filename(self.pyfile.name) filename = join(location, name) @@ -536,7 +532,7 @@ class Plugin(Base): self.pyfile.size = self.req.size if disposition and newname and newname != name: #triple check, just to be sure - self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname}) + self.core.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname}) self.pyfile.name = newname filename = join(location, newname) @@ -547,12 +543,12 @@ class Plugin(Base): if self.core.config["permission"]["change_dl"] and os.name != "nt": try: - uid = getpwnam(self.config["permission"]["user"])[2] - gid = getgrnam(self.config["permission"]["group"])[2] + uid = getpwnam(self.core.config["permission"]["user"])[2] + gid = getgrnam(self.core.config["permission"]["group"])[2] chown(fs_filename, uid, gid) except Exception, e: - self.log.warning(_("Setting User and Group failed: %s") % str(e)) + self.core.log.warning(_("Setting User and Group failed: %s") % str(e)) self.lastDownload = filename return self.lastDownload @@ -575,12 +571,12 @@ class Plugin(Base): if api_size and api_size <= size: return None elif size > max_size and not read_size: return None - self.log.debug("Download Check triggered") + self.core.log.debug("Download Check triggered") f = open(lastDownload, "rb") content = f.read(read_size if read_size else -1) f.close() #produces encoding errors, better log to other file in the future? - #self.log.debug("Content: %s" % content) + #self.core.log.debug("Content: %s" % content) for name, rule in rules.iteritems(): if type(rule) in (str, unicode): if rule in content: @@ -620,8 +616,8 @@ class Plugin(Base): 5, 7) and starting: #a download is waiting/starting and was appenrently started before self.skip(pyfile.pluginname) - download_folder = self.config['general']['download_folder'] - location = save_join(download_folder, pack.folder, self.pyfile.name) + download_folder = self.core.config['general']['download_folder'] + location = fs_join(download_folder, pack.folder, self.pyfile.name) if starting and self.core.config['download']['skip_existing'] and exists(location): size = os.stat(location).st_size @@ -633,7 +629,7 @@ class Plugin(Base): if exists(location): self.skip(pyfile[0]) - self.log.debug("File %s not skipped, because it does not exists" % self.pyfile.name) + self.core.log.debug("File %s not skipped, because it does not exists" % self.pyfile.name) def clean(self): """ clean everything and remove references """ diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index 624f6c939..cad4cfa1c 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -5,7 +5,7 @@ import re import subprocess from module.plugins.internal.UnRar import ArchiveError, CRCError, PasswordError, UnRar, renice -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class SevenZip(UnRar): @@ -126,7 +126,7 @@ class SevenZip(UnRar): result = set() for groups in self.re_filelist.findall(out): f = groups[-1].strip() - result.add(save_join(self.out, f)) + result.add(fs_join(self.out, f)) return list(result) diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 5b9f2e1c3..85e939b6a 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -8,7 +8,7 @@ from glob import glob from string import digits from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -from module.utils import fs_decode, fs_encode, save_join +from module.utils import fs_decode, fs_encode, save_join as fs_join def renice(pid, value): @@ -175,7 +175,7 @@ class UnRar(Extractor): files = [self.filename] # eventually Multipart Files - files.extend(save_join(dir, os.path.basename(file)) for file in filter(self.isMultipart, os.listdir(dir)) + files.extend(fs_join(dir, os.path.basename(file)) for file in filter(self.isMultipart, os.listdir(dir)) if re.sub(self.re_multipart,".rar",name) == re.sub(self.re_multipart,".rar",file)) return files @@ -197,13 +197,13 @@ class UnRar(Extractor): if not self.fullpath and self.VERSION.startswith('5'): # NOTE: Unrar 5 always list full path for f in fs_decode(out).splitlines(): - f = save_join(self.out, os.path.basename(f.strip())) + f = fs_join(self.out, os.path.basename(f.strip())) if os.path.isfile(f): - result.add(save_join(self.out, os.path.basename(f))) + result.add(fs_join(self.out, os.path.basename(f))) else: for f in fs_decode(out).splitlines(): f = f.strip() - result.add(save_join(self.out, f)) + result.add(fs_join(self.out, f)) return list(result) |