summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-07-04 23:11:15 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-07-04 23:11:15 +0200
commit850c373f1a61b135cf71d13b9cde9c4d41463f9b (patch)
treed6c0bd18be3818ae1244b8b52516f03bc3c53c53 /module/plugins
parentclosed #338 (diff)
downloadpyload-850c373f1a61b135cf71d13b9cde9c4d41463f9b.tar.xz
fixed some bugs, new externalscripts plugin
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Hook.py4
-rw-r--r--module/plugins/crypter/SerienjunkiesOrg.py4
-rw-r--r--module/plugins/hooks/ExternalScripts.py110
-rw-r--r--module/plugins/hooks/UpdateManager.py29
4 files changed, 81 insertions, 66 deletions
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index 8a6355fcd..5e4b192ea 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -57,7 +57,9 @@ class Hook():
self.log = core.log
self.config = core.config
- self.interval = 60
+ self.interval = 60 #: periodic call interval in seconds
+
+ self.info = None #: Provide information in dict here, usable by API `getInfo`
self.setup()
diff --git a/module/plugins/crypter/SerienjunkiesOrg.py b/module/plugins/crypter/SerienjunkiesOrg.py
index c907c5682..1e322a3a3 100644
--- a/module/plugins/crypter/SerienjunkiesOrg.py
+++ b/module/plugins/crypter/SerienjunkiesOrg.py
@@ -11,7 +11,7 @@ class SerienjunkiesOrg(Crypter):
__name__ = "SerienjunkiesOrg"
__type__ = "container"
__pattern__ = r"http://.*?serienjunkies.org/.*?"
- __version__ = "0.3"
+ __version__ = "0.31"
__config__ = [ ("preferredHoster", "str", "preferred hoster" , "RapidshareCom,UploadedTo,NetloadIn,FilefactoryCom,FreakshareNet,FilebaseTo,MegauploadCom,HotfileCom,DepositfilesCom,EasyshareCom,KickloadCom"),
("changeName", "bool", "Take SJ.org episode name", "True") ]
__description__ = """serienjunkies.org Container Plugin"""
@@ -133,7 +133,7 @@ class SerienjunkiesOrg(Crypter):
result = self.decryptCaptcha(str(captchaUrl), imgtype="png")
sinp = form.find(attrs={"name":"s"})
- self.req.lastUrl = url
+ self.req.lastURL = url
sj = self.req.load(str(url), post={'s': sinp["value"], 'c': result, 'action': "Download"})
soup = BeautifulSoup(sj)
diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py
index 63ff2b170..bbf5acde3 100644
--- a/module/plugins/hooks/ExternalScripts.py
+++ b/module/plugins/hooks/ExternalScripts.py
@@ -18,98 +18,92 @@
@interface-version: 0.1
"""
-from module.plugins.Hook import Hook
import subprocess
-from os import listdir
-from os.path import join
-import sys
+from os import listdir, access, X_OK, makedirs
+from os.path import join, exists, basename
+
+from module.plugins.Hook import Hook
+from module.utils import save_join
class ExternalScripts(Hook):
__name__ = "ExternalScripts"
- __version__ = "0.1"
+ __version__ = "0.2"
__description__ = """run external scripts"""
- __config__ = [ ("activated", "bool", "Activated" , "True") ]
+ __config__ = [("activated", "bool", "Activated", "True")]
__author_name__ = ("mkaay", "RaNaN", "spoob")
__author_mail__ = ("mkaay@mkaay.de", "ranan@pyload.org", "spoob@pyload.org")
- def __init__(self, core):
- Hook.__init__(self, core)
+
+ def setup(self):
self.scripts = {}
- script_folders = [join(pypath, 'scripts','download_preparing'),
- join(pypath,'scripts','download_finished'),
- join(pypath,'scripts','package_finished'),
- join(pypath,'scripts','before_reconnect'),
- join(pypath,'scripts','after_reconnect'),
- join(pypath,'scripts','unrar_finished')]
+ folders = ['download_preparing', 'download_finished', 'package_finished',
+ 'before_reconnect', 'after_reconnect', 'unrar_finished']
+
- folder = core.path("scripts")
+ for folder in folders:
- self.core.check_file(folder, _("folders for scripts"), True)
- self.core.check_file(script_folders, _("folders for scripts"), True)
+ self.scripts[folder] = []
+
+ self.initPluginType(folder, join(pypath, 'scripts', folder))
+ self.initPluginType(folder, join('scripts', folder))
+
+ for script_type, names in self.scripts.iteritems():
+ if names:
+ self.logInfo(_("Installed scripts for %s : %s") % (script_type, ", ".join([basename(x) for x in names])))
+
+ def initPluginType(self, folder, path):
+ if not exists(path):
+ try:
+ makedirs(path)
+ except :
+ self.logDebug("Script folder %s not created" % folder)
- f = lambda x: False if x.startswith("#") or x.endswith("~") else True
- self.scripts = {'download_preparing': filter(f, listdir(join(folder, 'download_preparing'))),
- 'download_finished': filter(f, listdir(join(folder, 'download_finished'))),
- 'package_finished': filter(f, listdir(join(folder, 'package_finished'))),
- 'before_reconnect': filter(f, listdir(join(folder, 'before_reconnect'))),
- 'after_reconnect': filter(f, listdir(join(folder, 'after_reconnect'))),
- 'unrar_finished': filter(f, listdir(join(folder, 'unrar_finished')))}
+ for f in listdir(path):
+ if f.startswith("#") or f.startswith(".") or f.startswith("_") or f.endswith("~") or f.endswith(".swp"):
+ continue
- for script_type, script_name in self.scripts.iteritems():
- if script_name:
- self.log.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name)))
+ if not access(join(path,f), X_OK):
+ self.logWarning(_("Script not executable: %s/%s") % (folder, f))
- #~ self.core.logger.info("Installed Scripts: %s" % str(self.scripts))
+ self.scripts[folder].append(join(path, f))
- self.folder = folder
+ def callScript(self, script, *args):
+ try:
+ cmd = [script] + [str(x) if type(x) != basestring else x for x in args]
+ #output goes to pyload
+ out = subprocess.Popen(cmd, bufsize=-1)
+ out.wait()
+ except Exception, e:
+ self.logError(_("Error in %s: %s") % (basename(script), str(e)))
def downloadStarts(self, pyfile):
for script in self.scripts['download_preparing']:
- try:
- cmd = [join(self.folder, 'download_preparing', script), pyfile.pluginname, pyfile.url]
- out = subprocess.Popen(cmd, stdout=subprocess.PIPE)
- out.wait()
- except:
- pass
+ self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.id)
def downloadFinished(self, pyfile):
for script in self.scripts['download_finished']:
- try:
- out = subprocess.Popen([join(self.folder, 'download_finished', script), pyfile.pluginname, pyfile.url, pyfile.name, join(self.core.config['general']['download_folder'], pyfile.package().folder, pyfile.name)], stdout=subprocess.PIPE)
- except:
- pass
+ self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, pyfile.id,
+ save_join(self.core.config['general']['download_folder'], pyfile.package().folder, pyfile.name),
+ pyfile.id)
+
def packageFinished(self, pypack):
for script in self.scripts['package_finished']:
folder = self.core.config['general']['download_folder']
if self.core.config.get("general", "folder_per_package"):
- folder = join(folder.decode(sys.getfilesystemencoding()), pypack.folder.decode(sys.getfilesystemencoding()))
+ folder = save_join(folder. pypack.folder)
- try:
- out = subprocess.Popen([join(self.folder, 'package_finished', script), pypack.name, folder], stdout=subprocess.PIPE)
- except:
- pass
+ self.callScript(script, pypack.name, folder, pypack.id)
def beforeReconnecting(self, ip):
for script in self.scripts['before_reconnect']:
- try:
- out = subprocess.Popen([join(self.folder, 'before_reconnect', script), ip], stdout=subprocess.PIPE)
- out.wait()
- except:
- pass
+ self.callScript(script, ip)
def afterReconnecting(self, ip):
for script in self.scripts['after_reconnect']:
- try:
- out = subprocess.Popen([join(self.folder, 'after_reconnect', script), ip], stdout=subprocess.PIPE)
- except:
- pass
+ self.callScript(script, ip)
def unrarFinished(self, folder, fname):
for script in self.scripts["unrar_finished"]:
- try:
- out = subprocess.Popen([join(self.folder, 'unrar_finished', script), folder, fname], stdout=subprocess.PIPE)
- except:
- pass
-
+ self.callScript(script, folder, fname)
diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py
index 026cd0c9f..10f50d1f0 100644
--- a/module/plugins/hooks/UpdateManager.py
+++ b/module/plugins/hooks/UpdateManager.py
@@ -17,6 +17,7 @@
@author: RaNaN
@interface-version: 0.1
"""
+import re
from os.path import join
from module.network.RequestFactory import getURL
@@ -27,7 +28,7 @@ class UpdateManager(Hook):
__version__ = "0.1"
__description__ = """checks for updates"""
__config__ = [("activated", "bool", "Activated", "True"),
- ("interval", "int", "Check interval in minutes", "180")]
+ ("interval", "int", "Check interval in minutes", "360")]
__author_name__ = ("RaNaN")
__author_mail__ = ("ranan@pyload.org")
@@ -36,12 +37,19 @@ class UpdateManager(Hook):
self.updated = False
self.reloaded = True
+ self.info = {"pyload": False, "plugins": False}
+
@threaded
def periodical(self):
update = self.checkForUpdate()
- if not update:
+ if update:
+ self.info["pyload"] = True
+ else:
+ self.log.info(_("No Updates for pyLoad"))
self.checkPlugins()
+
if self.updated and not self.reloaded:
+ self.info["plugins"] = True
self.log.info(_("*** Plugins have been updated, please restart pyLoad ***"))
elif self.updated and self.reloaded:
self.log.info(_("Plugins updated and reloaded"))
@@ -59,7 +67,6 @@ class UpdateManager(Hook):
try:
version_check = getURL("http://get.pyload.org/check/%s/" % self.core.server_methods.get_server_version())
if version_check == "":
- self.log.info(_("No Updates for pyLoad"))
return False
else:
self.log.info(_("*** New pyLoad Version %s available ***") % version_check)
@@ -81,6 +88,8 @@ class UpdateManager(Hook):
updates = updates.splitlines()
+ vre = re.compile(r'__version__.*=.*("|\')([0-9.]+)')
+
for plugin in updates:
path, version = plugin.split(":")
prefix, name = path.split("/")
@@ -107,11 +116,21 @@ class UpdateManager(Hook):
"version": float(version)
})
- content = getURL("http://get.pyload.org/plugins/get/" + path)
+ try:
+ content = getURL("http://get.pyload.org/plugins/get/" + path)
+ except:
+ self.logWarning(_("Error when updating %s") % name)
+ continue
+
+ m = vre.search(content)
+ if not m or m.group(2) != version:
+ self.logWarning(_("Error when updating %s") % name)
+ continue
+
f = open(join("userplugins", prefix, name), "wb")
f.write(content)
f.close()
self.updated = True
self.reloaded = False
- self.core.pluginManager.reloadPlugins() \ No newline at end of file
+ self.core.pluginManager.reloadPlugins()