summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/ExternalScripts.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-07 01:23:55 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-07 01:23:55 +0200
commitb1759bc440cd6013837697eb8de540914f693ffd (patch)
treed170caf63d7f65e44d23ea2d91a65759a1665928 /module/plugins/hooks/ExternalScripts.py
parent[Plugin] Fix decoding in load method (diff)
downloadpyload-b1759bc440cd6013837697eb8de540914f693ffd.tar.xz
No camelCase style anymore
Diffstat (limited to 'module/plugins/hooks/ExternalScripts.py')
-rw-r--r--module/plugins/hooks/ExternalScripts.py69
1 files changed, 35 insertions, 34 deletions
diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py
index 29b43929e..6bf3cf347 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 as fs_join
class ExternalScripts(Hook):
__name__ = "ExternalScripts"
__type__ = "hook"
- __version__ = "0.42"
+ __version__ = "0.43"
__config__ = [("activated", "bool", "Activated" , True ),
("waitend" , "bool", "Wait script ending", False)]
@@ -32,9 +32,10 @@ class ExternalScripts(Hook):
self.event_list = ["archive_extract_failed", "archive_extracted" ,
"package_extract_failed", "package_extracted" ,
- "all_archives_extracted", "all_archives_processed",
- "allDownloadsFinished" , "allDownloadsProcessed" ,
- "packageDeleted"]
+ "all_archives_extracted", "all_archives_processed"]
+ self.event_map = {'allDownloadsFinished' : "all_downloads_finished" ,
+ 'allDownloadsProcessed': "all_downloads_processed",
+ 'packageDeleted' : "package_deleted" }
folders = ["pyload_start", "pyload_restart", "pyload_stop",
"before_reconnect", "after_reconnect",
@@ -47,22 +48,22 @@ class ExternalScripts(Hook):
for folder in folders:
self.scripts[folder] = []
for dir in (pypath, ''):
- self.initPluginType(folder, os.path.join(dir, 'scripts', folder))
+ self.init_plugin_type(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)))
+ self.log_info(_("Installed scripts for: ") + script_type, ", ".join(map(os.path.basename, names)))
self.pyload_start()
- def initPluginType(self, name, dir):
+ def init_plugin_type(self, name, dir):
if not os.path.isdir(dir):
try:
os.makedirs(dir)
except OSError, e:
- self.logDebug(e)
+ self.log_debug(e)
return
for filename in os.listdir(dir):
@@ -75,54 +76,54 @@ class ExternalScripts(Hook):
continue
if not os.access(file, os.X_OK):
- self.logWarning(_("Script not executable:") + " %s/%s" % (name, filename))
+ self.log_warning(_("Script not executable:") + " %s/%s" % (name, filename))
self.scripts[name].append(file)
- def callScript(self, script, *args):
+ def call_script(self, script, *args):
try:
cmd_args = (fs_encode(x) if isinstande(x, basestring) else str(x) for x in args) #@NOTE: `fs_encode` -> `encode` in 0.4.10
- self.logDebug("Executing: %s" % os.path.abspath(script), "Args: " + ' '.join(cmd_args))
+ self.log_debug("Executing: %s" % os.path.abspath(script), "Args: " + ' '.join(cmd_args))
cmd = (script,) + cmd_args
p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload
- if self.getConfig('waitend'):
+ if self.get_config('waitend'):
p.communicate()
except Exception, e:
try:
- self.logError(_("Runtime error: %s") % os.path.abspath(script), e)
+ self.log_error(_("Runtime error: %s") % os.path.abspath(script), e)
except Exception:
- self.logError(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error"))
+ self.log_error(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error"))
def pyload_start(self):
for script in self.scripts['pyload_start']:
- self.callScript(script)
+ self.call_script(script)
def exit(self):
for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_stop']:
- self.callScript(script)
+ self.call_script(script)
def before_reconnect(self, ip):
for script in self.scripts['before_reconnect']:
- self.callScript(script, ip)
+ self.call_script(script, ip)
self.info['oldip'] = ip
def after_reconnect(self, ip):
for script in self.scripts['after_reconnect']:
- self.callScript(script, ip, self.info['oldip']) #@TODO: Use built-in oldip in 0.4.10
+ self.call_script(script, ip, self.info['oldip']) #@TODO: Use built-in oldip in 0.4.10
def download_preparing(self, pyfile):
for script in self.scripts['download_preparing']:
- self.callScript(script, pyfile.id, pyfile.name, None, pyfile.pluginname, pyfile.url)
+ self.call_script(script, pyfile.id, pyfile.name, None, pyfile.pluginname, pyfile.url)
def download_failed(self, pyfile):
@@ -133,7 +134,7 @@ class ExternalScripts(Hook):
for script in self.scripts['download_failed']:
file = fs_join(download_folder, pyfile.name)
- self.callScript(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url)
+ self.call_script(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url)
def download_finished(self, pyfile):
@@ -144,17 +145,17 @@ class ExternalScripts(Hook):
for script in self.scripts['download_finished']:
file = fs_join(download_folder, pyfile.name)
- self.callScript(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url)
+ self.call_script(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.filename, archive.out, archive.files)
+ self.call_script(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.filename, archive.out, archive.files)
+ self.call_script(script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files)
def package_finished(self, pypack):
@@ -164,10 +165,10 @@ class ExternalScripts(Hook):
download_folder = self.core.config.get("general", "download_folder")
for script in self.scripts['package_finished']:
- self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password)
+ self.call_script(script, pypack.id, pypack.name, download_folder, pypack.password)
- def packageDeleted(self, pid):
+ def package_deleted(self, pid):
pack = self.core.api.getPackageInfo(pid)
if self.core.config.get("general", "folder_per_package"):
@@ -176,7 +177,7 @@ class ExternalScripts(Hook):
download_folder = self.core.config.get("general", "download_folder")
for script in self.scripts['package_deleted']:
- self.callScript(script, pack.id, pack.name, download_folder, pack.password)
+ self.call_script(script, pack.id, pack.name, download_folder, pack.password)
def package_extract_failed(self, pypack):
@@ -186,7 +187,7 @@ class ExternalScripts(Hook):
download_folder = self.core.config.get("general", "download_folder")
for script in self.scripts['package_extract_failed']:
- self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password)
+ self.call_script(script, pypack.id, pypack.name, download_folder, pypack.password)
def package_extracted(self, pypack):
@@ -196,24 +197,24 @@ class ExternalScripts(Hook):
download_folder = self.core.config.get("general", "download_folder")
for script in self.scripts['package_extracted']:
- self.callScript(script, pypack.id, pypack.name, download_folder)
+ self.call_script(script, pypack.id, pypack.name, download_folder)
- def allDownloadsFinished(self):
+ def all_downloads_finished(self):
for script in self.scripts['all_downloads_finished']:
- self.callScript(script)
+ self.call_script(script)
- def allDownloadsProcessed(self):
+ def all_downloads_processed(self):
for script in self.scripts['all_downloads_processed']:
- self.callScript(script)
+ self.call_script(script)
def all_archives_extracted(self):
for script in self.scripts['all_archives_extracted']:
- self.callScript(script)
+ self.call_script(script)
def all_archives_processed(self):
for script in self.scripts['all_archives_processed']:
- self.callScript(script)
+ self.call_script(script)