summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-26 11:37:44 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-26 11:37:44 +0200
commite260b201f94a2a1e470b85a6499ea70e20a11277 (patch)
tree356dc9f5a7d8ef14cf6befb8cfa324b991571a0c /module
parentfixed occasionally appearing cli bug, catpcha method for sharebiz @ ~60% (diff)
downloadpyload-e260b201f94a2a1e470b85a6499ea70e20a11277.tar.xz
Cli stable, able to abort downloads, pause/kill server
Diffstat (limited to 'module')
-rw-r--r--module/download_thread.py5
-rw-r--r--module/file_list.py14
-rwxr-xr-xmodule/network/Request.py6
-rw-r--r--module/thread_list.py9
4 files changed, 28 insertions, 6 deletions
diff --git a/module/download_thread.py b/module/download_thread.py
index 202ebcafb..2c9cc8791 100644
--- a/module/download_thread.py
+++ b/module/download_thread.py
@@ -22,6 +22,7 @@ import traceback
from time import sleep
from time import time
+from module.network.Request import AbortDownload
class Status(object):
""" Saves all status information
@@ -53,7 +54,6 @@ class Status(object):
class Reconnect(Exception):
pass
-
class Download_Thread(threading.Thread):
def __init__(self, parent):
threading.Thread.__init__(self)
@@ -70,6 +70,9 @@ class Download_Thread(threading.Thread):
if self.loadedPyFile:
try:
self.download(self.loadedPyFile)
+ except AbortDownload:
+ self.loadedPyFile.plugin.req.abort = False
+ self.loadedPyFile.status.type = "aborted"
except Reconnect:
pass
except Exception, e:
diff --git a/module/file_list.py b/module/file_list.py
index 8f32ef474..feb7613bd 100644
--- a/module/file_list.py
+++ b/module/file_list.py
@@ -20,6 +20,8 @@
LIST_VERSION = 2
+from threading import RLock
+
import cPickle
from Py_Load_File import PyLoadFile
from module.remote.RequestObject import RequestObject
@@ -29,6 +31,7 @@ class File_List(object):
self.core = core
self.files = []
self.data = {'version': LIST_VERSION, 'order': []}
+ self.lock = RLock()
self.load()
def new_pyfile(self, url):
@@ -61,6 +64,7 @@ class File_List(object):
del self.data[pyfile.id]
def remove_id(self, pyid):
+ #also abort download
pyid = int(pyid)
found = False
for pyfile in self.files:
@@ -70,6 +74,10 @@ class File_List(object):
break
if not found:
+ for pyfile in self.core.thread_list.py_downloading:
+ if pyfile.id == pyid:
+ pyfile.plugin.req.abort = True
+ break
return False
self.data['order'].remove(pyid)
@@ -84,10 +92,14 @@ class File_List(object):
return id
def save(self):
+ self.lock.acquire()
+
output = open('links.pkl', 'wb')
cPickle.dump(self.data, output, -1)
self.inform_client()
+
+ self.lock.release()
def load(self):
try:
@@ -102,7 +114,7 @@ class File_List(object):
for i in obj['order']:
self.append(obj[i].url)
- self.core.logger.info("Links loaded: "+ str(int(len(obj) - 1)))
+ self.core.logger.info("Links loaded: " + str(int(len(obj) - 1)))
def inform_client(self):
obj = RequestObject()
diff --git a/module/network/Request.py b/module/network/Request.py
index 0b518cf66..346412446 100755
--- a/module/network/Request.py
+++ b/module/network/Request.py
@@ -24,6 +24,9 @@ from cStringIO import StringIO
retrieveUrl returns response as string
"""
+class AbortDownload(Exception):
+ pass
+
class Request:
def __init__(self):
@@ -33,6 +36,8 @@ class Request:
self.dl_arrived = 0
self.dl = False
+ self.abort = False
+
self.cookies = []
self.lastURL = None
self.cj = cookielib.CookieJar()
@@ -146,6 +151,7 @@ class Request:
self.dl_arrived = 0
self.dl_time = time.time()
for chunk in conn:
+ if self.abort: raise AbortDownload
self.dl_arrived += len(chunk)
file.write(chunk)
file.close()
diff --git a/module/thread_list.py b/module/thread_list.py
index 1dadb91d3..52b264648 100644
--- a/module/thread_list.py
+++ b/module/thread_list.py
@@ -99,18 +99,19 @@ class Thread_List(object):
self.list.remove(pyfile)
if pyfile.plugin.props['type'] == "container":
-
self.list.extend(pyfile.plugin.links)
-
- if pyfile.status.type == "reconnected":#put it back in queque
+ elif pyfile.status.type == "reconnected":#put it back in queque
self.list.files.insert(0, pyfile)
- if pyfile.status.type == "failed":
+ elif pyfile.status.type == "failed":
self.parent.logger.warning("Download failed: " + pyfile.url+" | "+ pyfile.status.error)
with open(self.parent.config['failed_file'], 'a') as f:
f.write(pyfile.url + "\n")
+ self.list.remove(pyfile)
+ elif pyfile.status.type == "aborted":
+ self.parent.logger.info("Download aborted: " + pyfile.url)
self.list.remove(pyfile)
self.list.save()