diff options
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r-- | module/plugins/hooks/ExternalScripts.py | 23 | ||||
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 9 | ||||
-rw-r--r-- | module/plugins/hooks/HotFolder.py | 3 | ||||
-rw-r--r-- | module/plugins/hooks/MergeFiles.py | 6 |
4 files changed, 22 insertions, 19 deletions
diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index b2b4548a2..3d9a1e811 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- +import os import subprocess from itertools import chain -from os import listdir, access, X_OK, makedirs -from os.path import join, exists, basename, abspath from module.plugins.Hook import Hook from module.utils import save_join @@ -47,40 +46,40 @@ class ExternalScripts(Hook): for folder in folders: self.scripts[folder] = [] - self.initPluginType(folder, join(pypath, 'scripts', folder)) - self.initPluginType(folder, join('scripts', folder)) + self.initPluginType(folder, os.path.join(pypath, 'scripts', folder)) + self.initPluginType(folder, os.path.join('scripts', folder)) for script_type, names in self.scripts.iteritems(): if names: - self.logInfo(_("Installed scripts for"), script_type, ", ".join([basename(x) for x in names])) + self.logInfo(_("Installed scripts for"), script_type, ", ".join([os.path.basename(x) for x in names])) def initPluginType(self, folder, path): - if not exists(path): + if not os.path.exists(path): try: - makedirs(path) + os.makedirs(path) except Exception: self.logDebug("Script folder %s not created" % folder) return - for f in listdir(path): + for f in os.listdir(path): if f.startswith("#") or f.startswith(".") or f.startswith("_") or f.endswith("~") or f.endswith(".swp"): continue - if not access(join(path, f), X_OK): + if not os.access(os.path.join(path, f), os.X_OK): self.logWarning(_("Script not executable:") + " %s/%s" % (folder, f)) - self.scripts[folder].append(join(path, f)) + self.scripts[folder].append(os.path.join(path, f)) def callScript(self, script, *args): try: cmd = [script] + [str(x) if not isinstance(x, basestring) else x for x in args] - self.logDebug("Executing", abspath(script), " ".join(cmd)) + self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) #output goes to pyload subprocess.Popen(cmd, bufsize=-1) except Exception, e: - self.logError(_("Error in %(script)s: %(error)s") % {"script": basename(script), "error": e}) + self.logError(_("Error in %(script)s: %(error)s") % {"script": os.path.basename(script), "error": e}) def downloadPreparing(self, pyfile): diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index c24173964..11427109b 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -49,7 +49,7 @@ if os.name != "nt": from module.plugins.Hook import Hook, threaded, Expose from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError -from module.utils import fs_decode, save_join, uniqify +from module.utils import fs_decode, fs_encode, save_join, uniqify class ExtractArchive(Hook): @@ -371,7 +371,9 @@ class ExtractArchive(Hook): def reloadPasswords(self): try: passwords = [] - with open(self.getConfig("passwordfile")) as f: + + file = fs_encode(self.getConfig("passwordfile")) + with open(file) as f: for pw in f.read().splitlines(): passwords.append(pw) @@ -388,7 +390,8 @@ class ExtractArchive(Hook): try: self.passwords = uniqify([password] + self.passwords) - with open(self.getConfig("passwordfile"), "wb") as f: + file = fs_encode(self.getConfig("passwordfile")) + with open(file, "wb") as f: for pw in self.passwords: f.write(pw + '\n') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index b0b59e2ba..1ff02c319 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -39,7 +39,8 @@ class HotFolder(Hook): makedirs(join(folder, "finished")) if self.getConfig("watch_file"): - with open(fs_encode(self.getConfig("file")), "a+") as f: + file = fs_encode(self.getConfig("file")) + with open(file, "a+") as f: content = f.read().strip() if content: diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 4de45f958..9f1348485 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -8,13 +8,13 @@ import re from traceback import print_exc from module.plugins.Hook import Hook, threaded -from module.utils import save_join, fs_encode +from module.utils import save_join class MergeFiles(Hook): __name__ = "MergeFiles" __type__ = "hook" - __version__ = "0.13" + __version__ = "0.14" __config__ = [("activated", "bool", "Activated", True)] @@ -65,7 +65,7 @@ class MergeFiles(Hook): pyfile.setStatus("processing") try: - with open(os.path.join(download_folder, splitted_file), "rb") as s_file: + with open(save_join(download_folder, splitted_file), "rb") as s_file: size_written = 0 s_file_size = int(os.path.getsize(os.path.join(download_folder, splitted_file))) while True: |