summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-12-12 17:45:40 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-12-12 17:45:40 +0100
commitddc6c0c15c132933e9676d563bad37288a3212f5 (patch)
treea5d6ecbcc4b96be9f8aead14262f3aa3ec69a5df /module
parentfixed progress when resuming (diff)
downloadpyload-ddc6c0c15c132933e9676d563bad37288a3212f5.tar.xz
universal progress (ex. unrar progress), link info now emits update event, updated .pot
Diffstat (limited to 'module')
-rw-r--r--module/FileDatabase.py276
-rw-r--r--module/gui/Collector.py5
-rw-r--r--module/gui/Queue.py16
-rw-r--r--module/network/FtpRequest.py12
-rwxr-xr-xmodule/network/Request.py8
-rw-r--r--module/network/XdccRequest.py1
-rw-r--r--module/plugins/Plugin.py3
-rw-r--r--module/plugins/hooks/UnRar.py6
8 files changed, 48 insertions, 279 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py
index 9225873fe..9e5417c75 100644
--- a/module/FileDatabase.py
+++ b/module/FileDatabase.py
@@ -16,6 +16,7 @@
@author: RaNaN
@author: mkaay
"""
+
from Queue import Queue
from os import remove
from os.path import exists
@@ -32,6 +33,9 @@ from module.PullEvents import ReloadAllEvent
from module.PullEvents import RemoveEvent
from module.PullEvents import UpdateEvent
+from module.PyPackage import PyPackage
+from module.PyFile import PyFile
+
try:
from pysqlite2 import dbapi2 as sqlite3
except:
@@ -468,7 +472,6 @@ class FileHandler:
p.order = position
self.db.commit()
-
e = ReloadAllEvent("collector" if not p.queue else "queue")
self.core.pullManager.addEvent(e)
@@ -500,15 +503,16 @@ class FileHandler:
e = ReloadAllEvent("collector" if not self.getPackage(f["package"]).queue else "queue")
-
self.core.pullManager.addEvent(e)
@change
def updateFileInfo(self, data, pid):
""" updates file info (name, size, status, url)"""
- self.db.updateLinkInfo(data)
+ ids = self.db.updateLinkInfo(data)
- #@TODO package update event
+ for fid in ids:
+ e = UpdateEvent("file", fid, "collector" if not self.getFile(fid).package().queue else "queue")
+ self.core.pullManager.addEvent(e)
def checkPackageFinished(self, pyfile):
""" checks if package is finished and calls hookmanager """
@@ -729,7 +733,8 @@ class FileDatabaseBackend(Thread):
'error': r[5],
'plugin': r[6],
'package': r[7],
- 'order': r[8]
+ 'order': r[8],
+ 'progress': 100 if r[4] in (0, 4) else 0
}
return data
@@ -785,7 +790,8 @@ class FileDatabaseBackend(Thread):
'error': r[5],
'plugin': r[6],
'package': r[7],
- 'order': r[8]
+ 'order': r[8],
+ 'progress': 100 if r[4] in (0, 4) else 0
}
return data
@@ -822,10 +828,15 @@ class FileDatabaseBackend(Thread):
def updatePackage(self, p):
self.c.execute('UPDATE packages SET name=?,folder=?,site=?,password=?,queue=?,priority=? WHERE id=?', (p.name, p.folder, p.site, p.password, p.queue, p.priority, str(p.id)))
- @async
+ @queue
def updateLinkInfo(self, data):
""" data is list of tupels (name, size, status, url) """
self.c.executemany('UPDATE links SET name=?, size=?, status=? WHERE url=? AND status NOT IN (0,8,12,13)', data)
+ ids = []
+ self.c.execute('SELECT id FROM links WHERE url IN (\'%s\')' % "','".join([x[3] for x in data]))
+ for r in self.c:
+ ids.append(int(r[0]))
+ return ids
@queue
def reorderPackage(self, p, position, noMove=False):
@@ -925,257 +936,6 @@ class FileDatabaseBackend(Thread):
self.c.execute("SELECT id FROM links WHERE package=? AND status NOT IN (0, 13) LIMIT 3", (str(pid),))
return [r[0] for r in self.c]
-
-class PyFile():
- def __init__(self, manager, id, url, name, size, status, error, pluginname, package, order):
- self.m = manager
-
- self.id = int(id)
- self.url = url
- self.name = name
- self.size = size
- self.status = status
- self.pluginname = pluginname
- self.packageid = package #should not be used, use package() instead
- self.error = error
- self.order = order
- # database information ends here
-
- self.plugin = None
-
- self.waitUntil = 0 # time() + time to wait
-
- # status attributes
- self.active = False #obsolete?
- self.abort = False
- self.reconnected = False
-
- #hook progress
- self.alternativePercent = None
-
- self.m.cache[int(id)] = self
-
-
- def __repr__(self):
- return "PyFile %s: %s@%s" % (self.id, self.name, self.pluginname)
-
- def initPlugin(self):
- """ inits plugin instance """
- if not self.plugin:
- self.pluginmodule = self.m.core.pluginManager.getPlugin(self.pluginname)
- self.pluginclass = getattr(self.pluginmodule, self.pluginname)
- self.plugin = self.pluginclass(self)
-
-
- def package(self):
- """ return package instance"""
- return self.m.getPackage(self.packageid)
-
- def setStatus(self, status):
- self.status = statusMap[status]
- self.sync() #@TODO needed aslong no better job approving exists
-
- def hasStatus(self, status):
- return statusMap[status] == self.status
-
- def sync(self):
- """sync PyFile instance with database"""
- self.m.updateLink(self)
-
- def release(self):
- """sync and remove from cache"""
- self.sync()
- if hasattr(self, "plugin"):
- del self.plugin
- self.m.releaseLink(self.id)
-
- def delete(self):
- """delete pyfile from database"""
- self.m.deleteLink(self.id)
-
- def toDict(self):
- """return dict with all information for interface"""
- return self.toDbDict()
-
- def toDbDict(self):
- """return data as dict for databse
-
- format:
-
- {
- id: {'url': url, 'name': name ... }
- }
-
- """
- return {
- self.id: {
- 'id': self.id,
- 'url': self.url,
- 'name': self.name,
- 'plugin': self.pluginname,
- 'size': self.getSize(),
- 'format_size': self.formatSize(),
- 'status': self.status,
- 'statusmsg': self.m.statusMsg[self.status],
- 'package': self.packageid,
- 'error': self.error,
- 'order': self.order
- }
- }
-
- def abortDownload(self):
- """abort pyfile if possible"""
- while self.id in self.m.core.threadManager.processingIds():
- self.abort = True
- if self.plugin and self.plugin.req: self.plugin.req.abort = True
- sleep(0.1)
-
- self.abort = False
- if hasattr(self, "plugin") and self.plugin and self.plugin.req: self.plugin.req.abort = False
- self.release()
-
- def finishIfDone(self):
- """set status to finish and release file if every thread is finished with it"""
-
- if self.id in self.m.core.threadManager.processingIds():
- return False
-
- self.setStatus("finished")
- self.release()
- return True
-
- def formatWait(self):
- """ formats and return wait time in humanreadable format """
- seconds = self.waitUntil - time()
-
- if seconds < 0: return "00:00:00"
-
- hours, seconds = divmod(seconds, 3600)
- minutes, seconds = divmod(seconds, 60)
- return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
-
- def formatSize(self):
- """ formats size to readable format """
- return formatSize(self.getSize())
-
- def formatETA(self):
- """ formats eta to readable format """
- seconds = self.getETA()
-
- if seconds < 0: return "00:00:00"
-
- hours, seconds = divmod(seconds, 3600)
- minutes, seconds = divmod(seconds, 60)
- return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
-
- def getSpeed(self):
- """ calculates speed """
- try:
- return self.plugin.req.get_speed()
- except:
- return 0
-
- def getETA(self):
- """ gets established time of arrival"""
- try:
- return self.plugin.req.get_ETA()
- except:
- return 0
-
- def getBytesLeft(self):
- """ gets bytes left """
- try:
- return self.plugin.req.bytes_left()
- except:
- return 0
-
- def getPercent(self):
- """ get % of download """
- if self.alternativePercent: return self.alternativePercent
- try:
- return int((float(self.plugin.req.dl_arrived) / self.plugin.req.dl_size) * 100)
- except:
- return 0
-
- def getSize(self):
- """ get size of download """
- if self.size: return self.size
- else:
- try:
- return self.plugin.req.dl_size
- except:
- return 0
-
- def notifyChange(self):
- e = UpdateEvent("file", self.id, "collector" if not self.package().queue else "queue")
- self.m.core.pullManager.addEvent(e)
-
-class PyPackage():
- def __init__(self, manager, id, name, folder, site, password, queue, order, priority):
- self.m = manager
- self.m.packageCache[int(id)] = self
-
- self.id = int(id)
- self.name = name
- self.folder = folder
- self.site = site
- self.password = password
- self.queue = queue
- self.order = order
- self.priority = priority
-
-
- self.setFinished = False
-
- def toDict(self):
- """return data as dict
-
- format:
-
- {
- id: {'name': name ... 'links': {} } }
- }
-
- """
- return {
- self.id: {
- 'id': self.id,
- 'name': self.name,
- 'folder': self.folder,
- 'site': self.site,
- 'password': self.password,
- 'queue': self.queue,
- 'order': self.order,
- 'priority': self.priority,
- 'links': {}
- }
- }
-
- def getChildren(self):
- """get information about contained links"""
- return self.m.getPackageData(self.id)["links"]
-
- def setPriority(self, priority):
- self.priority = priority
- self.sync()
-
- def sync(self):
- """sync with db"""
- self.m.updatePackage(self)
-
- def release(self):
- """sync and delete from cache"""
- self.sync()
- self.m.releasePackage(self.id)
-
- def delete(self):
- self.m.deletePackage(self.id)
-
- def notifyChange(self):
- e = UpdateEvent("file", self.id, "collector" if not self.queue else "queue")
- self.m.core.pullManager.addEvent(e)
-
-
if __name__ == "__main__":
pypath = "."
diff --git a/module/gui/Collector.py b/module/gui/Collector.py
index 5fc041a8e..87d433566 100644
--- a/module/gui/Collector.py
+++ b/module/gui/Collector.py
@@ -142,8 +142,9 @@ class CollectorModel(QAbstractItemModel):
if package.id == int(info["package"]):
for k, child in enumerate(package.children):
if child.id == int(event[3]):
- child.data = info
- child.data["downloading"] = None
+ child.data.update(info)
+ if not info["status"] == 12:
+ child.data["downloading"] = None
self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), self.index(k, 0, self.index(p, 0)), self.index(k, self.cols, self.index(p, self.cols)))
break
else:
diff --git a/module/gui/Queue.py b/module/gui/Queue.py
index 5489f85ce..eb13415f0 100644
--- a/module/gui/Queue.py
+++ b/module/gui/Queue.py
@@ -116,24 +116,12 @@ class QueueModel(CollectorModel):
def getProgress(self, item):
locker = QMutexLocker(self.mutex)
if isinstance(item, Link):
- if item.data["downloading"]:
- return int(item.data["downloading"]["percent"])
- if item.data["statusmsg"] == "finished" or \
- item.data["statusmsg"] == "failed" or \
- item.data["statusmsg"] == "aborted":
- return 100
+ return int(item.data["progress"])
elif isinstance(item, Package):
count = len(item.children)
perc_sum = 0
for child in item.children:
- val = 0
- if child.data["downloading"]:
- val = int(child.data["downloading"]["percent"])
- elif child.data["statusmsg"] == "finished" or \
- child.data["statusmsg"] == "failed" or \
- child.data["statusmsg"] == "aborted":
- val = 100
- perc_sum += val
+ perc_sum += int(child.data["progress"])
if count == 0:
return 0
return perc_sum/count
diff --git a/module/network/FtpRequest.py b/module/network/FtpRequest.py
index d8f556fea..a0986a9ed 100644
--- a/module/network/FtpRequest.py
+++ b/module/network/FtpRequest.py
@@ -54,6 +54,7 @@ class FtpRequest:
self.averageSpeeds = []
self.averageSpeedTime = 0.0
self.averageSpeedCount = 0.0
+ self.progressNotify = None
self.speedLimitActive = False
self.maxSpeed = 0
@@ -219,8 +220,15 @@ class FtpRequest:
def progress(self, dl_t, dl_d, up_t, up_d):
if self.abort:
return False
- self.dl_arrived = int(dl_d)
- self.dl_size = int(dl_t)
+ self.dl_arrived = int(dl_d)+self.offset
+ self.dl_size = int(dl_t)+self.offset
+
+ if self.progressNotify:
+ try:
+ progress = int(float(self.dl_arrived)/self.dl_size*100)
+ self.progressNotify(progress)
+ except:
+ pass
def get_free_name(self, file_name):
file_count = 0
diff --git a/module/network/Request.py b/module/network/Request.py
index 3a3cd0f41..5314f97ab 100755
--- a/module/network/Request.py
+++ b/module/network/Request.py
@@ -63,6 +63,7 @@ class Request:
self.isSlow = False
self.cookieJar = None
self.interface = interface
+ self.progressNotify = None
# change this for connection information
self.debug = False
@@ -379,6 +380,13 @@ class Request:
self.dl_arrived = int(dl_d)+self.offset
self.dl_size = int(dl_t)+self.offset
+ if self.progressNotify:
+ try:
+ progress = int(float(self.dl_arrived)/self.dl_size*100)
+ self.progressNotify(progress)
+ except:
+ pass
+
def get_free_name(self, folder, file_name):
file_count = 0
file_name = join(folder, file_name)
diff --git a/module/network/XdccRequest.py b/module/network/XdccRequest.py
index b65398dbc..18378cc6f 100644
--- a/module/network/XdccRequest.py
+++ b/module/network/XdccRequest.py
@@ -70,6 +70,7 @@ class XdccRequest:
self.speedLimitActive = False
self.maxSpeed = 0
self.isSlow = False
+ self.progressNotify = None
# change this for connection information
self.debug = False
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 34c06539a..f2c3b18eb 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -101,7 +101,8 @@ class Plugin(object):
#self.req.canContinue = True
else:
self.req = pyfile.m.core.requestFactory.getRequest(self.__name__)
-
+ self.req.progressNotify = pyfile.progress.setValue
+
self.log = pyfile.m.core.log
self.pyfile = pyfile
diff --git a/module/plugins/hooks/UnRar.py b/module/plugins/hooks/UnRar.py
index 46b9aac6a..fa762a832 100644
--- a/module/plugins/hooks/UnRar.py
+++ b/module/plugins/hooks/UnRar.py
@@ -119,8 +119,10 @@ class UnRar(Hook):
self.core.log.info(_("starting Unrar of %s") % fname)
pyfile = self.core.files.getFile(fid)
pyfile.setStatus("processing")
+ pyfile.progress.setRange(0, 100)
def s(p):
- pyfile.alternativePercent = p
+ pyfile.progress.setValue(p)
+
download_folder = self.core.config['general']['download_folder']
if self.core.config['general']['folder_per_package']:
@@ -165,7 +167,7 @@ class UnRar(Hook):
else:
self.core.log.info(_("Unrar of %s failed (wrong password)") % fname)
finally:
- pyfile.alternativePercent = None
+ pyfile.progress.setValue(100)
pyfile.setStatus("finished")
pyfile.release()