summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-01 19:55:47 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-01 19:55:47 +0200
commit9ff7fe5187f9b481847019ac3a30fe29ba4359ff (patch)
tree24d735ca92e49c4f7b0f7e5c20647f68533e1f09
parentmyvideo.de download plugin added (diff)
downloadpyload-9ff7fe5187f9b481847019ac3a30fe29ba4359ff.tar.xz
reconnect, not working, dont try it out
-rw-r--r--Plugins/Plugin.py2
-rw-r--r--Plugins/XupIn.py3
-rw-r--r--config2
-rw-r--r--module/download_thread.py18
-rw-r--r--module/remote/ClientHandler.py7
-rw-r--r--module/remote/ClientSocket.py7
-rw-r--r--module/remote/RequestHandler.py2
-rw-r--r--module/remote/RequestObject.py1
-rw-r--r--module/remote/SocketServer.py1
-rw-r--r--module/thread_list.py69
10 files changed, 80 insertions, 32 deletions
diff --git a/Plugins/Plugin.py b/Plugins/Plugin.py
index c941cc0c5..fdf33d3f8 100644
--- a/Plugins/Plugin.py
+++ b/Plugins/Plugin.py
@@ -24,7 +24,7 @@ class Plugin():
self.req = Request()
self.html = None
self.time_plus_wait = None #time() + wait in seconds
- self.want_reconnect = None
+ self.want_reconnect = False
self.multi_dl = True
def set_parent_status(self):
diff --git a/Plugins/XupIn.py b/Plugins/XupIn.py
index 14c8d02ee..534be2e94 100644
--- a/Plugins/XupIn.py
+++ b/Plugins/XupIn.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import re
-from time import time
from Plugin import Plugin
class XupIn(Plugin):
@@ -23,7 +22,7 @@ class XupIn(Plugin):
self.time_plus_wait = None #time() + wait in seconds
self.posts = {}
self.want_reconnect = None
- self.multi_dl = False
+ self.multi_dl = False
def set_parent_status(self):
""" sets all available Statusinfos about a File in self.parent.status
diff --git a/config b/config
index fb6db7792..98201ac97 100644
--- a/config
+++ b/config
@@ -14,6 +14,6 @@ fullLog = True
start = 0:00
end = 6:00
[remote]
-remote_activated = False
+remote_activated = True
port = 7272
remotePassword = pwhere
diff --git a/module/download_thread.py b/module/download_thread.py
index f8786c810..cced6508a 100644
--- a/module/download_thread.py
+++ b/module/download_thread.py
@@ -34,9 +34,9 @@ class Status(object):
self.expected_time = 0
self.filename = None
self.url = None
- self.exists = None
+ self.exists = False
self.waituntil = None
- self.want_reconnect = None
+ self.want_reconnect = False
# def __call__(self, blocks_read, block_size, total_size):
# if self.status_queue == None:
@@ -99,15 +99,19 @@ class Download_Thread(threading.Thread):
raise "FileDontExists" #i know its deprecated, who cares^^
if status.want_reconnect:
- print "handle reconnect"
+ reconnect = self.parent.init_reconnect(pyfile)
+ if reconnect:
+ status.type = "reconnected"
+ return False
while (time() < status.waituntil):
- if status.want_reconnect and self.reconnected:
- status = "reconnected"
+ if status.want_reconnect and self.parent.reconnecting:
+ status.type = "reconnected"
return False
status.type = "waiting"
- sleep(1) #eventuell auf genaue zeit warten
-
+ sleep(1)
+
+ status.want_reconnect = False
try:
status.type = "downloading"
diff --git a/module/remote/ClientHandler.py b/module/remote/ClientHandler.py
index cc06bd21a..248725ccf 100644
--- a/module/remote/ClientHandler.py
+++ b/module/remote/ClientHandler.py
@@ -20,9 +20,4 @@ class ClientHandler(RequestHandler):
def proceed(self, data):
obj = self.decrypt(data)
- self.client.data_arrived(obj)
-
- #if obj.function == "get_downloads":
- # self.client.show_links(obj.response)
-
- return self.encrypt(obj)
+ self.client.data_arrived(obj) \ No newline at end of file
diff --git a/module/remote/ClientSocket.py b/module/remote/ClientSocket.py
index 68e6ee884..4efeaf3ab 100644
--- a/module/remote/ClientSocket.py
+++ b/module/remote/ClientSocket.py
@@ -7,10 +7,9 @@ socket for connecting to the core's server
"""
import asynchat
-import socket
import asyncore
+import socket
import threading
-import time
from ClientHandler import ClientHandler
from RequestObject import RequestObject
@@ -55,9 +54,7 @@ class ClientSocket(asynchat.async_chat):
self.data += data
def found_terminator(self):
- obj = self.handler.proceed(self.data)
- #self.push(obj+"\n")
- print "data arrived"
+ self.handler.proceed(self.data)
self.data = ""
def push_obj(self, obj):
diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py
index dd4fdeb5f..f7623d27b 100644
--- a/module/remote/RequestHandler.py
+++ b/module/remote/RequestHandler.py
@@ -28,7 +28,7 @@ class RequestHandler:
if obj.command == "exec":
func = getattr(self.core, obj.function)
- obj.response = func( * obj.args)
+ obj.response = func(*obj.args)
else:
obj.response = "error happend"
diff --git a/module/remote/RequestObject.py b/module/remote/RequestObject.py
index 86e803e9c..7080a6faf 100644
--- a/module/remote/RequestObject.py
+++ b/module/remote/RequestObject.py
@@ -6,7 +6,6 @@ authored by: RaNaN
represents the object for interaction
"""
-
class RequestObject(object):
def __init__(self):
self.version = 0
diff --git a/module/remote/SocketServer.py b/module/remote/SocketServer.py
index c9979adb8..c519d8a3b 100644
--- a/module/remote/SocketServer.py
+++ b/module/remote/SocketServer.py
@@ -10,6 +10,7 @@ import asynchat
import asyncore
import socket
import threading
+
from RequestHandler import RequestHandler
diff --git a/module/thread_list.py b/module/thread_list.py
index a206c19c4..eb852a37b 100644
--- a/module/thread_list.py
+++ b/module/thread_list.py
@@ -22,7 +22,7 @@ import re
import subprocess
import time
import urllib2
-from threading import Lock
+from threading import RLock
from download_thread import Download_Thread
@@ -33,10 +33,11 @@ class Thread_List(object):
self.max_threads = 3
self.py_load_files = [] # files in queque
self.f_relation = [0, 0]
- self.lock = Lock()
+ self.lock = RLock()
self.py_downloading = [] # files downloading
self.occ_plugins = [] #occupied plugins
self.pause = False
+ self.reconnecting = False
def create_thread(self):
""" creates thread for Py_Load_File and append thread to self.threads
@@ -65,6 +66,14 @@ class Thread_List(object):
# return job if suitable, otherwise send thread idle
self.lock.acquire()
+ if not self.py_load_files:
+ return False
+
+ self.init_reconnect()
+
+ if self.reconnecting:
+ return None
+
if self.pause:
return None
@@ -91,10 +100,18 @@ class Thread_List(object):
self.occ_plugins.remove(pyfile.modul.__name__)
self.py_downloading.remove(pyfile)
- self.parent.logger.info('finished downloading ' + pyfile.url + ' @' + str(pyfile.status.get_speed()) + 'kb/s')
-
- if pyfile.plugin.props['type'] == "container":
- self.parent.extend_links(pyfile.plugin.links)
+
+ if pyfile.status.type == "finished":
+ self.parent.logger.info('finished downloading ' + pyfile.url + ' @' + str(pyfile.status.get_speed()) + 'kb/s')
+
+ #remove from txt
+
+ if pyfile.plugin.props['type'] == "container":
+ self.parent.extend_links(pyfile.plugin.links)
+
+ if pyfile.status.type == "reconnected":
+ print "put it back"
+ self.py_load_files.insert(0, pyfile)
self.lock.release()
return True
@@ -114,12 +131,48 @@ class Thread_List(object):
self.f_relation[1] += 1
self.select_thread()
+ def init_reconnect(self, pyfile=None):
+
+ self.lock.acquire()
+
+ reconnecting = filter(lambda pyfile: pyfile.status.want_reconnect is True, self.py_downloading) #returns all which want to reconenct
+
+
+ if reconnecting and reconnecting == self.py_downloading:
+ #if empty -> all want reconnect
+ self.reconnecting = True
+ self.parent.logger.info("Reconnecting")
+ self.reconnect()
+
+ self.py_downloading.remove(pyfile)
+
+ while self.py_downloading:
+ print "waiting"
+ time.sleep(1)
+
+ self.py_downloading.append(pyfile)
+
+ self.reconnecting = False
+
+ self.lock.release()
+
+ return True
+
+ else:
+ self.lock.release()
+ return False
+
+
def reconnect(self):
- self.parent.logger.debug("reconnect")
+
+ print "reconnected"
+ return True
+
reconn = subprocess.Popen(self.parent.config['reconnectMethod'])
reconn.wait()
ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1) #versuchen neue ip aus zu lesen
while ip == "": #solange versuch bis neue ip ausgelesen
ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1)
time.sleep(1)
- #print "Neue IP: " + ip
+ self.parent.logger.info("Reconnected, new IP: " + ip)
+ \ No newline at end of file