From 184ea88c7322399a04ab80a6d509ce446b83d966 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 11 Jan 2015 21:52:22 +0100 Subject: [ExternalScripts] Fixup --- module/plugins/hooks/ExternalScripts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index a35e47c03..fc0cae44f 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -13,7 +13,7 @@ from module.utils import save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.25" + __version__ = "0.26" __config__ = [("activated", "bool", "Activated", True)] @@ -136,11 +136,11 @@ class ExternalScripts(Hook): self.callScript(script) - def allDownloadsFinished(self): + def allDownloadsFinished(self, thread): for script in chain(self.scripts['all_downloads_finished'], self.scripts['all_dls_finished']): self.callScript(script) - def allDownloadsProcessed(self): + def allDownloadsProcessed(self, thread): for script in chain(self.scripts['all_downloads_processed'], self.scripts['all_dls_processed']): self.callScript(script) -- cgit v1.2.3 From e1baccf1ec914563d3b2b845906cce024e7cd3b1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 13 Jan 2015 23:14:50 +0100 Subject: Replace 'except' with 'except Exception' --- module/plugins/hooks/ExternalScripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index fc0cae44f..f4d2cb69c 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -59,7 +59,7 @@ class ExternalScripts(Hook): if not exists(path): try: makedirs(path) - except: + except Exception: self.logDebug("Script folder %s not created" % folder) return -- cgit v1.2.3 From e2d8d605aeb4fd3477a8d681e16cd0b17500a648 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 16 Jan 2015 01:36:04 +0100 Subject: Fix allDownloadsFinished and allDownloadsProcessed defs --- module/plugins/hooks/ExternalScripts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index f4d2cb69c..b2b4548a2 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -13,7 +13,7 @@ from module.utils import save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.26" + __version__ = "0.27" __config__ = [("activated", "bool", "Activated", True)] @@ -136,11 +136,11 @@ class ExternalScripts(Hook): self.callScript(script) - def allDownloadsFinished(self, thread): + def allDownloadsFinished(self): for script in chain(self.scripts['all_downloads_finished'], self.scripts['all_dls_finished']): self.callScript(script) - def allDownloadsProcessed(self, thread): + def allDownloadsProcessed(self): for script in chain(self.scripts['all_downloads_processed'], self.scripts['all_dls_processed']): self.callScript(script) -- cgit v1.2.3 From cb9e67a5437ddfafd6a93f5a208b9faf3f2d5575 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 29 Jan 2015 15:56:57 +0100 Subject: Some file encoding fixup + optimizations --- module/plugins/hooks/ExternalScripts.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') 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): -- cgit v1.2.3 From 79725268402043906f619f7c09e848e02ab8a17b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 31 Jan 2015 22:00:59 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/ExternalScripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 3d9a1e811..bbd442963 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -51,7 +51,7 @@ class ExternalScripts(Hook): for script_type, names in self.scripts.iteritems(): if names: - self.logInfo(_("Installed scripts for"), script_type, ", ".join([os.path.basename(x) for x in names])) + self.logInfo(_("Installed scripts for"), script_type, ", ".join(map(os.path.basename, names))) def initPluginType(self, folder, path): -- cgit v1.2.3 From 3cea8ed5afb68060951cb20a6e07e3d0dca01e24 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 8 Feb 2015 02:10:34 +0100 Subject: [ExternalScripts] Wait option --- module/plugins/hooks/ExternalScripts.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index bbd442963..42f4ec481 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -12,9 +12,10 @@ from module.utils import save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.27" + __version__ = "0.28" - __config__ = [("activated", "bool", "Activated", True)] + __config__ = [("activated", "bool", "Activated" , True), + ("wait" , "bool", "Wait script ending", True)] __description__ = """Run external scripts""" __license__ = "GPLv3" @@ -58,6 +59,7 @@ class ExternalScripts(Hook): if not os.path.exists(path): try: os.makedirs(path) + except Exception: self.logDebug("Script folder %s not created" % folder) return @@ -75,9 +77,13 @@ class ExternalScripts(Hook): def callScript(self, script, *args): try: cmd = [script] + [str(x) if not isinstance(x, basestring) else x for x in args] + self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) - #output goes to pyload - subprocess.Popen(cmd, bufsize=-1) + + p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload + if self.getConfig('wait'): + p.communicate() + except Exception, e: self.logError(_("Error in %(script)s: %(error)s") % {"script": os.path.basename(script), "error": e}) -- cgit v1.2.3 From 45295be158d77aa38e7803fbcd90d7ad4ddc7961 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 8 Feb 2015 14:08:55 +0100 Subject: [ExternalScripts] Wait option (2) --- module/plugins/hooks/ExternalScripts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 42f4ec481..8bd803308 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -12,10 +12,10 @@ from module.utils import save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.28" + __version__ = "0.29" - __config__ = [("activated", "bool", "Activated" , True), - ("wait" , "bool", "Wait script ending", True)] + __config__ = [("activated", "bool", "Activated" , True ), + ("wait" , "bool", "Wait script ending", False)] __description__ = """Run external scripts""" __license__ = "GPLv3" -- cgit v1.2.3 From ed9bbe7332d8f6e2bf33b09ae5382a4925d2eac3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 24 Feb 2015 23:57:38 +0100 Subject: [ExternalScripts] Code cosmetics --- module/plugins/hooks/ExternalScripts.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 8bd803308..3b9c9ca05 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -3,8 +3,6 @@ import os import subprocess -from itertools import chain - from module.plugins.Hook import Hook from module.utils import save_join @@ -142,10 +140,10 @@ class ExternalScripts(Hook): def allDownloadsFinished(self): - for script in chain(self.scripts['all_downloads_finished'], self.scripts['all_dls_finished']): + for script in self.scripts['all_downloads_finished'] + self.scripts['all_dls_finished']): self.callScript(script) def allDownloadsProcessed(self): - for script in chain(self.scripts['all_downloads_processed'], self.scripts['all_dls_processed']): + for script in self.scripts['all_downloads_processed'] + self.scripts['all_dls_processed']: self.callScript(script) -- cgit v1.2.3 From 808d8036fc8cc13c4b26240818bd86ac82567e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=B6rnlein?= Date: Wed, 25 Feb 2015 20:25:20 +0100 Subject: [ExternalScripts] Code cosmetics - cosmetics --- module/plugins/hooks/ExternalScripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 3b9c9ca05..f49220c2a 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -140,7 +140,7 @@ class ExternalScripts(Hook): def allDownloadsFinished(self): - for script in self.scripts['all_downloads_finished'] + self.scripts['all_dls_finished']): + for script in self.scripts['all_downloads_finished'] + self.scripts['all_dls_finished']: self.callScript(script) -- cgit v1.2.3 From 5f4b7afb0bf8f770032ee21ce67c76194d8d6cb0 Mon Sep 17 00:00:00 2001 From: jellysheep Date: Fri, 6 Mar 2015 14:24:22 +0100 Subject: [ExternalScripts] Encode unicode characters If a file with unicode characters in the filename is downloaded ExternalScripts.py fails with e.g. this error: ExternalScripts: Error in download_finished.sh: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128) This commit makes the plugin encode unicode characters to UTF-8. --- module/plugins/hooks/ExternalScripts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index f49220c2a..76a9d9c52 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -74,7 +74,8 @@ class ExternalScripts(Hook): def callScript(self, script, *args): try: - cmd = [script] + [str(x) if not isinstance(x, basestring) else x for x in args] + cmd = [script] + [x.encode("UTF-8") if isinstance(x, unicode) else + str(x) if not isinstance(x, basestring) else x for x in args] self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) -- cgit v1.2.3 From acc20db31c63ed03ce3e0c530a0b0bc24444e980 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 6 Mar 2015 22:31:52 +0100 Subject: [ExternalScripts] Version up --- module/plugins/hooks/ExternalScripts.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 76a9d9c52..a09d5e92e 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.29" + __version__ = "0.30" __config__ = [("activated", "bool", "Activated" , True ), ("wait" , "bool", "Wait script ending", False)] @@ -74,8 +74,7 @@ class ExternalScripts(Hook): def callScript(self, script, *args): try: - cmd = [script] + [x.encode("UTF-8") if isinstance(x, unicode) else - str(x) if not isinstance(x, basestring) else x for x in args] + cmd = [script] + [(str(x) if not isinstance(x, basestring) else x).encode('utf-8') for x in args] self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) -- cgit v1.2.3 From af353df35ef05b699f464ad2dca1b7b2bfe732e4 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 8 Mar 2015 01:14:57 +0100 Subject: [ExternalScripts] Improve --- module/plugins/hooks/ExternalScripts.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index a09d5e92e..76444d4b3 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -4,16 +4,16 @@ import os import subprocess from module.plugins.Hook import Hook -from module.utils import save_join +from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.30" + __version__ = "0.31" __config__ = [("activated", "bool", "Activated" , True ), - ("wait" , "bool", "Wait script ending", False)] + ("waitend" , "bool", "Wait script ending", False)] __description__ = """Run external scripts""" __license__ = "GPLv3" @@ -50,7 +50,7 @@ class ExternalScripts(Hook): for script_type, names in self.scripts.iteritems(): if names: - self.logInfo(_("Installed scripts for"), script_type, ", ".join(map(os.path.basename, names))) + self.logInfo(_("Installed scripts for ") + script_type, ", ".join(map(os.path.basename, names))) def initPluginType(self, folder, path): @@ -58,28 +58,33 @@ class ExternalScripts(Hook): try: os.makedirs(path) - except Exception: - self.logDebug("Script folder %s not created" % folder) + except IOError, e: + self.logDebug(e) return - for f in os.listdir(path): - if f.startswith("#") or f.startswith(".") or f.startswith("_") or f.endswith("~") or f.endswith(".swp"): + for filename in os.listdir(path): + file = os.path.join(path, filename) + + if not os.path.isfile(file): + continue + + if filename[0] in ("#", "_") or filename.endswith("~") or filename.endswith(".swp"): continue - if not os.access(os.path.join(path, f), os.X_OK): - self.logWarning(_("Script not executable:") + " %s/%s" % (folder, f)) + if not os.access(file, os.X_OK): + self.logWarning(_("Script not executable:") + " %s/%s" % (folder, filename)) - self.scripts[folder].append(os.path.join(path, f)) + self.scripts[folder].append(file) def callScript(self, script, *args): try: - cmd = [script] + [(str(x) if not isinstance(x, basestring) else x).encode('utf-8') for x in args] + cmd = [(str(x) if not isinstance(x, basestring) else x).encode('utf-8') for x in args] self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) - p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload - if self.getConfig('wait'): + p = subprocess.Popen([script, fs_encode(cmd)], bufsize=-1) #@NOTE: output goes to pyload + if self.getConfig('waitend'): p.communicate() except Exception, e: -- cgit v1.2.3 From 6f7002bcc3520c47fafe5122b0e0cbada313887d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 8 Mar 2015 23:39:59 +0100 Subject: Whitespace cosmetics --- module/plugins/hooks/ExternalScripts.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 76444d4b3..14387e234 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -17,9 +17,9 @@ class ExternalScripts(Hook): __description__ = """Run external scripts""" __license__ = "GPLv3" - __authors__ = [("mkaay", "mkaay@mkaay.de"), - ("RaNaN", "ranan@pyload.org"), - ("spoob", "spoob@pyload.org"), + __authors__ = [("mkaay" , "mkaay@mkaay.de" ), + ("RaNaN" , "ranan@pyload.org" ), + ("spoob" , "spoob@pyload.org" ), ("Walter Purcaro", "vuolter@gmail.com")] @@ -67,7 +67,7 @@ class ExternalScripts(Hook): if not os.path.isfile(file): continue - + if filename[0] in ("#", "_") or filename.endswith("~") or filename.endswith(".swp"): continue -- cgit v1.2.3 From 04f2d0f9a377fcbabebd99c98ffc0638459acd6d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 9 Mar 2015 04:06:15 +0100 Subject: [ExternalScripts] Fixup --- module/plugins/hooks/ExternalScripts.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 14387e234..5f2790656 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.31" + __version__ = "0.32" __config__ = [("activated", "bool", "Activated" , True ), ("waitend" , "bool", "Wait script ending", False)] @@ -79,11 +79,11 @@ class ExternalScripts(Hook): def callScript(self, script, *args): try: - cmd = [(str(x) if not isinstance(x, basestring) else x).encode('utf-8') for x in args] + cmd = [script] + [(str(x) if not isinstance(x, basestring) else x).encode('utf-8') for x in args] self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) - p = subprocess.Popen([script, fs_encode(cmd)], bufsize=-1) #@NOTE: output goes to pyload + p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload if self.getConfig('waitend'): p.communicate() @@ -99,8 +99,8 @@ class ExternalScripts(Hook): def downloadFinished(self, pyfile): download_folder = self.config['general']['download_folder'] for script in self.scripts['download_finished']: - filename = save_join(download_folder, pyfile.package().folder, pyfile.name) - self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, filename, pyfile.id) + file = save_join(download_folder, pyfile.package().folder, pyfile.name) + self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, file, pyfile.id) def packageFinished(self, pypack): -- cgit v1.2.3 From 7beb65e991bc6d1913c3b5bb2ef69e659d5b8342 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 10 Mar 2015 01:55:52 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/ExternalScripts.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 5f2790656..d17e4740c 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -44,26 +44,25 @@ class ExternalScripts(Hook): for folder in folders: self.scripts[folder] = [] - - self.initPluginType(folder, os.path.join(pypath, 'scripts', folder)) - self.initPluginType(folder, os.path.join('scripts', folder)) + for dir in (pypath, ''): + self.initPluginType(folder, os.path.join(dir, 'scripts', folder)) for script_type, names in self.scripts.iteritems(): if names: self.logInfo(_("Installed scripts for ") + script_type, ", ".join(map(os.path.basename, names))) - def initPluginType(self, folder, path): - if not os.path.exists(path): + def initPluginType(self, name, dir): + if not os.path.isdir(dir): try: - os.makedirs(path) + os.makedirs(dir) except IOError, e: self.logDebug(e) return - for filename in os.listdir(path): - file = os.path.join(path, filename) + for filename in os.listdir(dir): + file = os.path.join(dir, filename) if not os.path.isfile(file): continue @@ -72,9 +71,9 @@ class ExternalScripts(Hook): continue if not os.access(file, os.X_OK): - self.logWarning(_("Script not executable:") + " %s/%s" % (folder, filename)) + self.logWarning(_("Script not executable:") + " %s/%s" % (name, filename)) - self.scripts[folder].append(file) + self.scripts[name].append(file) def callScript(self, script, *args): -- cgit v1.2.3 From a54c4268e402a3a1509c33d0b2de6f4336583416 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 18 Mar 2015 15:39:11 +0100 Subject: [ExternalScripts] Fix https://github.com/pyload/pyload/issues/1233 --- module/plugins/hooks/ExternalScripts.py | 132 +++++++++++++++++++++----------- 1 file changed, 86 insertions(+), 46 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index d17e4740c..435ab618c 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.32" + __version__ = "0.35" __config__ = [("activated", "bool", "Activated" , True ), ("waitend" , "bool", "Wait script ending", False)] @@ -23,8 +23,10 @@ class ExternalScripts(Hook): ("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["archive_extracted", "package_extracted", "all_archives_extracted", "all_archives_processed", - "allDownloadsFinished", "allDownloadsProcessed"] + event_list = ["archive_extract_failed", "archive_extracted" , + "package_extract_failed", "package_extracted" , + "all_archives_extracted", "all_archives_processed", + "allDownloadsFinished" , "allDownloadsProcessed" ] #@TODO: Remove in 0.4.10 @@ -33,14 +35,15 @@ class ExternalScripts(Hook): def setup(self): + self.info = {} #@TODO: Remove in 0.4.10 self.scripts = {} - folders = ["download_preparing", "download_finished", "all_downloads_finished", "all_downloads_processed", - "before_reconnect", "after_reconnect", - "package_finished", "package_extracted", - "archive_extracted", "all_archives_extracted", "all_archives_processed", - # deprecated folders - "unrar_finished", "all_dls_finished", "all_dls_processed"] + folders = ["before_reconnect", "after_reconnect", + "download_preparing", "download_failed", "download_finished", + "archive_extract_failed", "archive_extracted", + "package_finished", "package_extract_failed", "package_extracted", + "all_downloads_processed", "all_downloads_finished", #@TODO: Invert `all_downloads_processed`, `all_downloads_finished` order in 0.4.10 + "all_archives_extracted", "all_archives_processed"] for folder in folders: self.scripts[folder] = [] @@ -49,7 +52,7 @@ class ExternalScripts(Hook): for script_type, names in self.scripts.iteritems(): if names: - self.logInfo(_("Installed scripts for ") + script_type, ", ".join(map(os.path.basename, names))) + self.logInfo(_("Installed scripts for: ") + script_type, ", ".join(map(os.path.basename, names))) def initPluginType(self, name, dir): @@ -57,12 +60,12 @@ class ExternalScripts(Hook): try: os.makedirs(dir) - except IOError, e: + except OSError, e: self.logDebug(e) return for filename in os.listdir(dir): - file = os.path.join(dir, filename) + file = save_join(dir, filename) if not os.path.isfile(file): continue @@ -78,76 +81,113 @@ class ExternalScripts(Hook): def callScript(self, script, *args): try: - cmd = [script] + [(str(x) if not isinstance(x, basestring) else x).encode('utf-8') for x in args] + cmd_args = [fs_encode(str(x) if not isinstance(x, basestring) else x) for x in args] + cmd = [script] + cmd_args - self.logDebug("Executing", os.path.abspath(script), " ".join(cmd)) + self.logDebug("Executing: %s" % os.path.abspath(script), "Args: " + ' '.join(cmd_args)) p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload if self.getConfig('waitend'): p.communicate() except Exception, e: - self.logError(_("Error in %(script)s: %(error)s") % {"script": os.path.basename(script), "error": e}) + try: + self.logError(_("Runtime error: %s") % os.path.abspath(script), e) + except Exception: + self.logError(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error")) + + def beforeReconnecting(self, ip): + for script in self.scripts['before_reconnect']: + self.callScript(script, ip) + + + def afterReconnecting(self, ip): + for script in self.scripts['after_reconnect']: + self.callScript(script, ip) def downloadPreparing(self, pyfile): for script in self.scripts['download_preparing']: - self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.id) + self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, None) + + + def downloadFailed(self, pyfile): + if self.config['general']['folder_per_package']: + download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + else: + download_folder = self.config['general']['download_folder'] + + for script in self.scripts['download_failed']: + file = save_join(download_folder, pyfile.name) + self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file) def downloadFinished(self, pyfile): - download_folder = self.config['general']['download_folder'] + if self.config['general']['folder_per_package']: + download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + else: + download_folder = self.config['general']['download_folder'] + for script in self.scripts['download_finished']: - file = save_join(download_folder, pyfile.package().folder, pyfile.name) - self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, file, pyfile.id) + file = save_join(download_folder, pyfile.name) + self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file) - def packageFinished(self, pypack): - download_folder = self.config['general']['download_folder'] - for script in self.scripts['package_finished']: - folder = save_join(download_folder, pypack.folder) - self.callScript(script, pypack.name, folder, pypack.password, pypack.id) + def archive_extract_failed(self, pyfile, archive): + for script in self.scripts['archive_extract_failed']: + self.callScript(script, pyfile.id, pyfile.name, archive.out, archive.filename, archive.files) - def beforeReconnecting(self, ip): - for script in self.scripts['before_reconnect']: - self.callScript(script, ip) + def archive_extracted(self, pyfile, archive): + for script in self.scripts['archive_extracted']: + self.callScript(script, pyfile.id, pyfile.name, archive.out, archive.filename, archive.files) - def afterReconnecting(self, ip): - for script in self.scripts['after_reconnect']: - self.callScript(script, ip) + def packageFinished(self, pypack): + if self.config['general']['folder_per_package']: + download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + else: + download_folder = self.config['general']['download_folder'] + for script in self.scripts['package_finished']: + self.callScript(script, pypack.id, pypack.name, download_folder) - def archive_extracted(self, pyfile, folder, filename, files): - for script in self.scripts['archive_extracted']: - self.callScript(script, folder, filename, files) - for script in self.scripts['unrar_finished']: #: deprecated - self.callScript(script, folder, filename) + + def package_extract_failed(self, pypack): + if self.config['general']['folder_per_package']: + download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + else: + download_folder = self.config['general']['download_folder'] + + for script in self.scripts['package_extract_failed']: + self.callScript(script, pypack.id, pypack.name, download_folder) def package_extracted(self, pypack): - download_folder = self.config['general']['download_folder'] + if self.config['general']['folder_per_package']: + download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + else: + download_folder = self.config['general']['download_folder'] + for script in self.scripts['package_extracted']: - folder = save_join(download_folder, pypack.folder) - self.callScript(script, pypack.name, folder, pypack.password, pypack.id) + self.callScript(script, pypack.id, pypack.name, download_folder) - def all_archives_extracted(self): - for script in self.scripts['all_archives_extracted']: + def allDownloadsFinished(self): + for script in self.scripts['all_downloads_finished']: self.callScript(script) - def all_archives_processed(self): - for script in self.scripts['all_archives_processed']: + def allDownloadsProcessed(self): + for script in self.scripts['all_downloads_processed']: self.callScript(script) - def allDownloadsFinished(self): - for script in self.scripts['all_downloads_finished'] + self.scripts['all_dls_finished']: + def all_archives_extracted(self): + for script in self.scripts['all_archives_extracted']: self.callScript(script) - def allDownloadsProcessed(self): - for script in self.scripts['all_downloads_processed'] + self.scripts['all_dls_processed']: + def all_archives_processed(self): + for script in self.scripts['all_archives_processed']: self.callScript(script) -- cgit v1.2.3 From 241d6fcca23656cf9690df455a0b7f9a44b472dd Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 20 Mar 2015 01:37:20 +0100 Subject: [ExtractArchive] Update dispatchEvent --- module/plugins/hooks/ExternalScripts.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 435ab618c..16049ae9b 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -96,6 +96,7 @@ class ExternalScripts(Hook): except Exception: self.logError(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error")) + def beforeReconnecting(self, ip): for script in self.scripts['before_reconnect']: self.callScript(script, ip) -- cgit v1.2.3 From 6fddff6b1c154ce1a34680bc22b6e39260f6a38c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 20 Mar 2015 03:16:32 +0100 Subject: [ExternalScripts] New events support --- module/plugins/hooks/ExternalScripts.py | 39 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 16049ae9b..dffa3649f 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.35" + __version__ = "0.36" __config__ = [("activated", "bool", "Activated" , True ), ("waitend" , "bool", "Wait script ending", False)] @@ -26,7 +26,8 @@ class ExternalScripts(Hook): event_list = ["archive_extract_failed", "archive_extracted" , "package_extract_failed", "package_extracted" , "all_archives_extracted", "all_archives_processed", - "allDownloadsFinished" , "allDownloadsProcessed" ] + "allDownloadsFinished" , "allDownloadsProcessed" , + "packageDeleted"] #@TODO: Remove in 0.4.10 @@ -35,13 +36,14 @@ class ExternalScripts(Hook): def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + self.info = {'oldip': None} self.scripts = {} - folders = ["before_reconnect", "after_reconnect", + folders = ["pyload_start", "pyload_restart", "pyload_shutdown", + "before_reconnect", "after_reconnect", "download_preparing", "download_failed", "download_finished", "archive_extract_failed", "archive_extracted", - "package_finished", "package_extract_failed", "package_extracted", + "package_finished", "package_deleted", "package_extract_failed", "package_extracted", "all_downloads_processed", "all_downloads_finished", #@TODO: Invert `all_downloads_processed`, `all_downloads_finished` order in 0.4.10 "all_archives_extracted", "all_archives_processed"] @@ -54,6 +56,8 @@ class ExternalScripts(Hook): if names: self.logInfo(_("Installed scripts for: ") + script_type, ", ".join(map(os.path.basename, names))) + self.pyload_start() + def initPluginType(self, name, dir): if not os.path.isdir(dir): @@ -97,14 +101,25 @@ class ExternalScripts(Hook): self.logError(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error")) + def pyload_start(self): + for script in self.scripts['pyload_start']: + self.callScript(script) + + + def coreExiting(self): + for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_shutdown']: + self.callScript(script) + + def beforeReconnecting(self, ip): for script in self.scripts['before_reconnect']: self.callScript(script, ip) + self.info['oldip'] = ip def afterReconnecting(self, ip): for script in self.scripts['after_reconnect']: - self.callScript(script, ip) + self.callScript(script, ip, self.info['oldip']) #@TODO: Use built-in oldip in 0.4.10 def downloadPreparing(self, pyfile): @@ -154,6 +169,18 @@ class ExternalScripts(Hook): self.callScript(script, pypack.id, pypack.name, download_folder) + def packageDeleted(self, pid): + pack = self.core.api.getPackageInfo(pid) + + if self.config['general']['folder_per_package']: + download_folder = save_join(self.config['general']['download_folder'], pack.folder) + else: + download_folder = self.config['general']['download_folder'] + + for script in self.scripts['package_deleted']: + self.callScript(script, pack.id, pack.name, download_folder) + + def package_extract_failed(self, pypack): if self.config['general']['folder_per_package']: download_folder = save_join(self.config['general']['download_folder'], pypack.folder) -- cgit v1.2.3 From c4b30b08857225e6a70aa3171b6663d84e78b22f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 20 Mar 2015 11:22:16 +0100 Subject: [ExternalScripts] Rename pyload_shutdown to pyload_stop --- module/plugins/hooks/ExternalScripts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index dffa3649f..8f6c405fd 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.36" + __version__ = "0.37" __config__ = [("activated", "bool", "Activated" , True ), ("waitend" , "bool", "Wait script ending", False)] @@ -39,7 +39,7 @@ class ExternalScripts(Hook): self.info = {'oldip': None} self.scripts = {} - folders = ["pyload_start", "pyload_restart", "pyload_shutdown", + folders = ["pyload_start", "pyload_restart", "pyload_stop", "before_reconnect", "after_reconnect", "download_preparing", "download_failed", "download_finished", "archive_extract_failed", "archive_extracted", @@ -107,7 +107,7 @@ class ExternalScripts(Hook): def coreExiting(self): - for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_shutdown']: + for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_stop']: self.callScript(script) -- cgit v1.2.3 From f1ce338ed31e49373cea5453a2fbdb6c686ca510 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 26 Mar 2015 10:16:04 +0100 Subject: interval code cosmetics --- module/plugins/hooks/ExternalScripts.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 8f6c405fd..8ab7af55c 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -28,11 +28,7 @@ class ExternalScripts(Hook): "all_archives_extracted", "all_archives_processed", "allDownloadsFinished" , "allDownloadsProcessed" , "packageDeleted"] - - - #@TODO: Remove in 0.4.10 - def initPeriodical(self): - pass + interval = 0 #@TODO: Remove in 0.4.10 def setup(self): -- cgit v1.2.3 From 031cc3a5f5b842698c0323fbec7d7a33f3ca99f8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 29 Mar 2015 18:45:11 +0200 Subject: [ExternalScripts] Update --- module/plugins/hooks/ExternalScripts.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 8ab7af55c..9324e306e 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.37" + __version__ = "0.38" __config__ = [("activated", "bool", "Activated" , True ), ("waitend" , "bool", "Wait script ending", False)] @@ -120,7 +120,7 @@ class ExternalScripts(Hook): def downloadPreparing(self, pyfile): for script in self.scripts['download_preparing']: - self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, None) + self.callScript(script, pyfile.id, pyfile.name, None, pyfile.pluginname, pyfile.url) def downloadFailed(self, pyfile): @@ -131,7 +131,7 @@ class ExternalScripts(Hook): for script in self.scripts['download_failed']: file = save_join(download_folder, pyfile.name) - self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file) + self.callScript(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url) def downloadFinished(self, pyfile): @@ -142,17 +142,17 @@ class ExternalScripts(Hook): for script in self.scripts['download_finished']: file = save_join(download_folder, pyfile.name) - self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file) + self.callScript(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url) def archive_extract_failed(self, pyfile, archive): for script in self.scripts['archive_extract_failed']: - self.callScript(script, pyfile.id, pyfile.name, archive.out, archive.filename, archive.files) + self.callScript(script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files) def archive_extracted(self, pyfile, archive): for script in self.scripts['archive_extracted']: - self.callScript(script, pyfile.id, pyfile.name, archive.out, archive.filename, archive.files) + self.callScript(script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files) def packageFinished(self, pypack): @@ -162,7 +162,7 @@ class ExternalScripts(Hook): download_folder = self.config['general']['download_folder'] for script in self.scripts['package_finished']: - self.callScript(script, pypack.id, pypack.name, download_folder) + self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password) def packageDeleted(self, pid): @@ -174,7 +174,7 @@ class ExternalScripts(Hook): download_folder = self.config['general']['download_folder'] for script in self.scripts['package_deleted']: - self.callScript(script, pack.id, pack.name, download_folder) + self.callScript(script, pack.id, pack.name, download_folder, pack.password) def package_extract_failed(self, pypack): @@ -184,7 +184,7 @@ class ExternalScripts(Hook): download_folder = self.config['general']['download_folder'] for script in self.scripts['package_extract_failed']: - self.callScript(script, pypack.id, pypack.name, download_folder) + self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password) def package_extracted(self, pypack): -- cgit v1.2.3 From ec093a83368aeb80691e08b5cb86e87352d5ad60 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 3 Apr 2015 14:24:14 +0200 Subject: [ExternalScripts] Fix https://github.com/pyload/pyload/issues/1307 --- module/plugins/hooks/ExternalScripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 9324e306e..be0857009 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -10,7 +10,7 @@ from module.utils import fs_encode, save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.38" + __version__ = "0.39" __config__ = [("activated", "bool", "Activated" , True ), ("waitend" , "bool", "Wait script ending", False)] -- cgit v1.2.3 From 9f3ab57ec994deb24cd31a1dfbd338eb71bffc8c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 27 May 2015 23:46:29 +0200 Subject: Spare code cosmetics --- module/plugins/hooks/ExternalScripts.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/ExternalScripts.py') diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index be0857009..a0815499b 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -23,11 +23,6 @@ class ExternalScripts(Hook): ("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["archive_extract_failed", "archive_extracted" , - "package_extract_failed", "package_extracted" , - "all_archives_extracted", "all_archives_processed", - "allDownloadsFinished" , "allDownloadsProcessed" , - "packageDeleted"] interval = 0 #@TODO: Remove in 0.4.10 @@ -35,6 +30,12 @@ class ExternalScripts(Hook): self.info = {'oldip': None} self.scripts = {} + self.event_list = ["archive_extract_failed", "archive_extracted" , + "package_extract_failed", "package_extracted" , + "all_archives_extracted", "all_archives_processed", + "allDownloadsFinished" , "allDownloadsProcessed" , + "packageDeleted"] + folders = ["pyload_start", "pyload_restart", "pyload_stop", "before_reconnect", "after_reconnect", "download_preparing", "download_failed", "download_finished", -- cgit v1.2.3