summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
Diffstat (limited to 'module')
-rw-r--r--module/HookManager.py73
-rw-r--r--module/plugins/hooks/ContainerDownload.py42
-rw-r--r--module/plugins/hooks/Hook.py51
-rw-r--r--module/plugins/hooks/__init__.py1
-rw-r--r--module/thread_list.py23
5 files changed, 172 insertions, 18 deletions
diff --git a/module/HookManager.py b/module/HookManager.py
new file mode 100644
index 000000000..a0caae728
--- /dev/null
+++ b/module/HookManager.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+"""
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+ @author: mkaay
+ @interface-version: 0.1
+"""
+import logging
+
+from os.path import basename, join
+from glob import glob
+
+from threading import Lock
+
+class HookManager():
+ def __init__(self, core):
+ self.core = core
+ self.logger = logging.getLogger("log")
+ self.plugins = []
+ self.lock = Lock()
+ self.createIndex()
+
+ def createIndex(self):
+ self.lock.acquire()
+ pluginFiles = glob(join(self.core.plugin_folder, "hooks", "*.py"))
+ plugins = []
+ for pluginFile in pluginFiles:
+ pluginName = basename(pluginFile).replace(".py", "")
+ if pluginName == "Hook" or pluginName == "__init__":
+ continue
+ module = __import__("module.plugins.hooks."+pluginName, globals(), locals(), [pluginName], -1)
+ pluginClass = getattr(module, pluginName)
+ plugins.append(pluginClass(self.core))
+
+ self.logger.info("Installed Hook: %s" % pluginName)
+ self.plugins = plugins
+ self.lock.release()
+
+ def downloadStarts(self, pyfile):
+ self.lock.acquire()
+ for plugin in self.plugins:
+ plugin.downloadStarts(pyfile)
+ self.lock.release()
+
+ def downloadFinished(self, pyfile):
+ self.lock.acquire()
+ for plugin in self.plugins:
+ plugin.downloadFinished(pyfile)
+ self.lock.release()
+
+ def beforeReconnecting(self, ip):
+ self.lock.acquire()
+ for plugin in self.plugins:
+ plugin.beforeReconnecting(ip)
+ self.lock.release()
+
+ def afterReconnecting(self, ip):
+ self.lock.acquire()
+ for plugin in self.plugins:
+ plugin.afterReconnecting(ip)
+ self.lock.release()
diff --git a/module/plugins/hooks/ContainerDownload.py b/module/plugins/hooks/ContainerDownload.py
new file mode 100644
index 000000000..d031cdf69
--- /dev/null
+++ b/module/plugins/hooks/ContainerDownload.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+
+"""
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+ @author: mkaay
+ @interface-version: 0.1
+"""
+
+from module.plugins.hooks.Hook import Hook
+
+from os.path import join, abspath
+
+class ContainerDownload(Hook):
+ def __init__(self, core):
+ Hook.__init__(self, core)
+ props = {}
+ props['name'] = "ContainerDownload"
+ props['version'] = "0.1"
+ props['description'] = """add the downloaded container to current package"""
+ props['author_name'] = ("mkaay")
+ props['author_mail'] = ("mkaay@mkaay.de")
+ self.props = props
+
+ def downloadFinished(self, pyfile):
+ filename = pyfile.status.filename
+ if filename.endswith(".dlc") or filename.endswith(".ccf") or filename.endswith(".rsdf"):
+ self.logger.info("ContainerDownload hook: adding container file")
+ location = abspath(join(pyfile.folder, filename))
+ newFile = self.core.file_list.collector.addLink(location)
+ self.core.file_list.packager.addFileToPackage(pyfile.package.data["id"], self.core.file_list.collector.popFile(newFile))
diff --git a/module/plugins/hooks/Hook.py b/module/plugins/hooks/Hook.py
new file mode 100644
index 000000000..f02432718
--- /dev/null
+++ b/module/plugins/hooks/Hook.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+"""
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+ @author: mkaay
+ @interface-version: 0.1
+"""
+
+import logging
+
+class Hook():
+ def __init__(self, core):
+ self.logger = logging.getLogger("log")
+ props = {}
+ props['name'] = "Hook"
+ props['version'] = "0.1"
+ props['description'] = """interface for hook"""
+ props['author_name'] = ("mkaay")
+ props['author_mail'] = ("mkaay@mkaay.de")
+ self.props = props
+ self.core = core
+
+ def downloadStarts(self, pyfile):
+ pass
+
+ def downloadFinished(self, pyfile):
+ pass
+
+ def packageFinished(self, pypack):
+ """
+ not implemented!
+ """
+ pass
+
+ def beforeReconnecting(self, ip):
+ pass
+
+ def afterReconnecting(self, ip):
+ pass
diff --git a/module/plugins/hooks/__init__.py b/module/plugins/hooks/__init__.py
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/module/plugins/hooks/__init__.py
@@ -0,0 +1 @@
+
diff --git a/module/thread_list.py b/module/thread_list.py
index 5d0bcf53a..55b21093f 100644
--- a/module/thread_list.py
+++ b/module/thread_list.py
@@ -76,7 +76,7 @@ class Thread_List(object):
if pyfile:
self.py_downloading.append(pyfile)
- self.scripts_download_preparing(pyfile.modul.__name__, pyfile.url)
+ self.parent.hookManager.downloadStarts(pyfile)
if not pyfile.plugin.multi_dl:
self.occ_plugins.append(pyfile.modul.__name__)
pyfile.active = True
@@ -153,7 +153,7 @@ class Thread_List(object):
self.list.save()
- self.scripts_download_finished(pyfile.modul.__name__, pyfile.url, pyfile.status.filename, pyfile.folder)
+ self.parent.hookManager.downloadFinished(pyfile)
self.lock.release()
return True
@@ -200,6 +200,8 @@ class Thread_List(object):
def reconnect(self):
self.parent.logger.info("Start reconnect")
+ ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1)
+ self.parent.hookManager.beforeReconnecting(ip)
reconn = subprocess.Popen(self.parent.config['activated']['method'])#, stdout=subprocess.PIPE)
reconn.wait()
time.sleep(1)
@@ -210,23 +212,8 @@ class Thread_List(object):
except:
ip = ""
time.sleep(1)
- self.scripts_reconnected(ip)
+ self.parent.hookManager.afterReconnecting(ip)
self.parent.logger.info("Reconnected, new IP: " + ip)
-
-
- def scripts_download_preparing(self, pluginname, url):
- for script in self.parent.scripts['download_preparing']:
- out = subprocess.Popen([script, pluginname, url], stdout=subprocess.PIPE)
- out.wait()
-
- def scripts_download_finished(self, pluginname, url, filename, location):
- map(lambda script: subprocess.Popen([script, pluginname, url, filename, location], stdout=subprocess.PIPE), self.parent.scripts['download_finished'])
-
- def scripts_package_finished(self, name, location): #@TODO Implement!
- map(lambda script: subprocess.Popen([script, name, location], stdout=subprocess.PIPE), self.parent.scripts['download_finished'])
-
- def scripts_reconnected(self, ip):
- map(lambda script: subprocess.Popen([script, ip], stdout=subprocess.PIPE), self.parent.scripts['download_finished'])
def stopAllDownloads(self):
for pyfile in self.py_downloading: