summaryrefslogtreecommitdiffstats
path: root/module/ThreadManager.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-02 20:42:13 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-02 20:42:13 +0200
commit113a7c42c94953a9491e7aad501269f476a79af4 (patch)
treef478f367f5a820772e4a87cf4881da35c88b10e1 /module/ThreadManager.py
parentwebif: log+download page (diff)
downloadpyload-113a7c42c94953a9491e7aad501269f476a79af4.tar.xz
new dlc plugins
Diffstat (limited to 'module/ThreadManager.py')
-rw-r--r--module/ThreadManager.py50
1 files changed, 39 insertions, 11 deletions
diff --git a/module/ThreadManager.py b/module/ThreadManager.py
index a49885297..a48d7e729 100644
--- a/module/ThreadManager.py
+++ b/module/ThreadManager.py
@@ -19,10 +19,13 @@
"""
from threading import Event
-import PluginThread
-
+from subprocess import Popen
+from os.path import exists
from time import sleep
+from module.network.Request import getURL
+import PluginThread
+
########################################################################
class ThreadManager:
"""manages the download threads, assign jobs, reconnect etc"""
@@ -68,33 +71,58 @@ class ThreadManager:
def work(self):
"""run all task which have to be done (this is for repetivive call by core)"""
- self.checkReconnect()
+ self.tryReconnect()
self.checkThreadCount()
self.assignJob()
#----------------------------------------------------------------------
- def checkReconnect(self):
+ def tryReconnect(self):
"""checks if reconnect needed"""
if not (self.core.server_methods.is_time_reconnect() and self.core.config["reconnect"]["activated"] ):
return False
-
+
active = [x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.threads if x.active]
- print active
+
if active.count(True) > 0 and len(active) == active.count(True):
+
+ if not exists(self.core.config['reconnect']['method']):
+ if exists(join(pypath, self.core.config['reconnect']['method'])):
+ self.core.config['reconnect']['method'] = join(pypath, self.core.config['reconnect']['method'])
+ else:
+ self.core.config["reconnect"]["activated"] = False
+ self.log.warning(_("Reconnect script not found!"))
+ return
+
+
self.reconnecting.set()
#Do reconnect
- self.log.info(_("Reconnecting"))
+ self.log.info(_("Starting reconnect"))
+
while [x.active.plugin.waiting for x in self.threads if x.active].count(True) != 0:
sleep(0.25)
-
- print "wating finsihed"
+
+ ip = re.match(".*Current IP Address: (.*)</body>.*", getURL("http://checkip.dyndns.org/")).group(1)
- print "do reconnect"
-
+ self.core.hookManager.beforeReconnecting(ip)
+ reconn = Popen(self.core.config['reconnect']['method'])#, stdout=subprocess.PIPE)
+ reconn.wait()
+ sleep(1)
+ ip = ""
+ while ip == "":
+ try:
+ ip = re.match(".*Current IP Address: (.*)</body>.*", getURL("http://checkip.dyndns.org/")).group(1) #get new ip
+ except:
+ ip = ""
+ sleep(1)
+ self.core.hookManager.afterReconnecting(ip)
+
+ self.log.info(_("Reconnected, new IP: %s") % ip)
+
+
self.reconnecting.clear()
#----------------------------------------------------------------------