diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-06-17 10:39:54 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-06-17 10:39:54 +0200 |
commit | 34a1ada97b5a7e5e353491ba0663bb6e27d3c57a (patch) | |
tree | 9d18e056fd22cbc1f3912a019dc3e20b80b398ec /module | |
parent | new file list modul (diff) | |
download | pyload-34a1ada97b5a7e5e353491ba0663bb6e27d3c57a.tar.xz |
file_list saves links, links.txt only for link dumping
Diffstat (limited to 'module')
-rw-r--r-- | module/file_list.py | 39 | ||||
-rw-r--r-- | module/thread_list.py | 15 |
2 files changed, 40 insertions, 14 deletions
diff --git a/module/file_list.py b/module/file_list.py index c9a96635f..fe4080807 100644 --- a/module/file_list.py +++ b/module/file_list.py @@ -22,31 +22,47 @@ LIST_VERSION = 1 import cPickle from Py_Load_File import PyLoadFile - + class File_List(object): def __init__(self, core): self.core = core self.files = [] self.data = {'version': LIST_VERSION} - self.id = 0 - #self.load() + self.load() def new_pyfile(self, url): url = url.replace("\n", "") pyfile = PyLoadFile(self.core, url) pyfile.download_folder = self.core.config['download_folder'] - pyfile.id = self.id - self.id += 1 + pyfile.id = self.get_id() return pyfile def append(self, url): - self.files.append(self.new_pyfile(url)) + new_file = self.new_pyfile(url) + self.files.append(new_file) + self.data[new_file.id] = Data(url) def extend(self, urls): for url in urls: self.append(url) + def remove(self, pyfile): + + if pyfile in self.files: + self.files.remove(pyfile) + + del self.data[pyfile.id] + + def get_id(self): + """return a free id""" + id = 1 + while id in self.data.keys(): + id += 1 + + return id + + def save(self): output = open('links.pkl', 'wb') cPickle.dump(self.data, output, -1) @@ -61,6 +77,13 @@ class File_List(object): if obj['version'] < LIST_VERSION: obj = {'version': LIST_VERSION} - self.data = obj + for key, value in obj.iteritems(): + if key != 'version': + self.append(value.url) - + self.core.logger.info("Links loaded: "+ str(int(len(obj) - 1))) + + +class Data(): + def __init__(self, url): + self.url = url
\ No newline at end of file diff --git a/module/thread_list.py b/module/thread_list.py index 62131b20e..54a17e318 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -17,13 +17,11 @@ # along with this program; if not, see <http://www.gnu.org/licenses/>. # ### -#python from __future__ import with_statement import re import subprocess import time import urllib2 - from threading import RLock from download_thread import Download_Thread @@ -31,11 +29,9 @@ from download_thread import Download_Thread class Thread_List(object): def __init__(self, parent): self.parent = parent - self.list = parent.file_list + self.list = parent.file_list #file list self.threads = [] self.max_threads = int(self.parent.config['max_downloads']) - # self.py_load_files = [] # files in queque - # self.f_relation = [0, 0] self.lock = RLock() self.py_downloading = [] # files downloading self.occ_plugins = [] #occupied plugins @@ -55,7 +51,7 @@ class Thread_List(object): self.threads.remove(thread) def select_thread(self): - """ select a thread + """ create all threads """ while len(self.threads) < self.max_threads: self.create_thread() @@ -89,6 +85,7 @@ class Thread_List(object): def job_finished(self, pyfile): + """manage completing download""" self.lock.acquire() if not pyfile.plugin.multi_dl: @@ -99,6 +96,8 @@ class Thread_List(object): if pyfile.status.type == "finished": self.parent.logger.info('Download finished: ' + pyfile.url + ' @' + str(pyfile.status.get_speed()) + 'kb/s') + self.list.remove(pyfile) + if pyfile.plugin.props['type'] == "container": self.list.extend(pyfile.plugin.links) @@ -112,6 +111,10 @@ class Thread_List(object): with open(self.parent.config['failed_file'], 'a') as f: f.write(pyfile.url + "\n") + self.list.remove(pyfile) + + self.list.save() + self.lock.release() return True |