summaryrefslogtreecommitdiffstats
path: root/module/thread_list.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-20 13:05:21 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-20 13:05:21 +0200
commit641cd8c63f4c3a96a9acf4d46450ab975b9c66cd (patch)
treea1bf0e74c3bde51d174bc0d154d1f88359437fbc /module/thread_list.py
parentModul struktur angelegt und request klasse eingefügt (diff)
downloadpyload-641cd8c63f4c3a96a9acf4d46450ab975b9c66cd.tar.xz
Neue Request Klasse eingebunden + ein paar Status Funktionen
Diffstat (limited to 'module/thread_list.py')
-rw-r--r--module/thread_list.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/module/thread_list.py b/module/thread_list.py
new file mode 100644
index 000000000..2a5dbe6f6
--- /dev/null
+++ b/module/thread_list.py
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+#Copyright (C) 2009 sp00b, sebnapi
+#
+#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/>.
+#
+###
+#python
+from Queue import Queue
+
+#my
+from download_thread import Download_Thread
+
+class Thread_List(object):
+ def __init__(self, parent):
+ self.parent = parent
+ self.threads = []
+ self.max_threads = 3
+ self.py_load_files = []
+ self.download_queue = Queue()
+ self.status_queue = Queue()
+ self.f_relation = [0,0]
+
+ def create_thread(self):
+ """ creates thread for Py_Load_File and append thread to self.threads
+ """
+ if self.py_load_files:
+ thread = Download_Thread(self)
+ self.threads.append(thread)
+ return True
+
+ def get_loaded_urls(self):
+ loaded_urls = []
+ for file in self.py_load_files:
+ loaded_urls.append(file.url)
+ return loaded_urls
+
+ def remove_thread(self, thread):
+ self.threads.remove(thread)
+
+ def status(self):
+ if not self.status_queue.empty():
+ while not self.status_queue.empty():
+ status = self.status_queue.get()
+ self.py_load_files[status.id].status = status
+
+ def getJob(self):
+ # nur wenn auch geladen werden soll, ansonsten thread in leerlauf schicken
+ if True:
+ return self.download_queue.get()
+
+ def extend_py_load_files(self):
+ pass
+
+ def select_thread(self):
+ """ select a thread
+ """
+ if len(self.threads) < self.max_threads:
+ self.create_thread()
+
+ def append_py_load_file(self, py_load_file):
+ py_load_file.id = len(self.py_load_files)
+ self.py_load_files.append(py_load_file)
+ self.download_queue.put(py_load_file)
+ self.f_relation[1] += 1
+ self.select_thread()
+
+ def reconnect():
+ reconn = subprocess.Popen(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