diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-08-09 21:30:58 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-08-09 21:30:58 +0200 |
commit | 087286d3fd6087fc7772ea538629f0add4eeb776 (patch) | |
tree | 6c4e8943e0b06525025519db81498fcee4e2861a | |
parent | removed gocr dependency (diff) | |
download | pyload-087286d3fd6087fc7772ea538629f0add4eeb776.tar.xz |
improvements
-rw-r--r-- | module/FileDatabase.py | 108 | ||||
-rw-r--r-- | module/PluginThread.py | 7 | ||||
-rw-r--r-- | module/ThreadManager.py | 6 |
3 files changed, 75 insertions, 46 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py index b8116d14e..fcbca1649 100644 --- a/module/FileDatabase.py +++ b/module/FileDatabase.py @@ -98,6 +98,14 @@ class FileHandler: return func(*args) return new + def lock(func): + def new(*args): + args[0].lock.acquire() + res = func(*args) + args[0].lock.release() + return res + return new + #---------------------------------------------------------------------- def save(self): """saves all data to backend""" @@ -126,22 +134,16 @@ class FileHandler: #---------------------------------------------------------------------- @change + @lock def addLinks(self, urls, package): """adds links""" - - data = [] - for x in self.core.pluginManager.parseUrls(urls): - # tuple of (url, name, plugin, package) - lastID = self.db.addLink(x[0], x[0], x[1], package) - data.append( (x[0],x[1] )) - - f = self.db.getFile(lastID) - e = InsertEvent("file", lastID, f.order, "collector" if not self.getPackage(package).queue else "queue") - self.core.pullManager.addEvent(e) - f.release() + data = self.core.pluginManager.parseUrls(urls) + + self.db.addLinks(data, package) + self.core.threadManager.createInfoThread(data, package) - self.core.threadManager.createInfoThread(data) + #@TODO package update event #---------------------------------------------------------------------- @change @@ -155,11 +157,10 @@ class FileHandler: #---------------------------------------------------------------------- @change + @lock def deletePackage(self, id): """delete package and all contained links""" - self.lock.acquire() - p = self.getPackage(id) e = RemoveEvent("pack", id, "collector" if not p.queue else "queue") @@ -175,16 +176,13 @@ class FileHandler: if self.packageCache.has_key(id): del self.packageCache[id] - - self.lock.release() #---------------------------------------------------------------------- @change + @lock def deleteLink(self, id): """deletes links""" - self.lock.acquire() - f = self.getFile(id) e = RemoveEvent("file", id, "collector" if not f.package().queue else "queue") @@ -195,8 +193,6 @@ class FileHandler: if self.cache.has_key(id): del self.cache[id] - self.lock.release() - self.db.deleteLink(f) self.core.pullManager.addEvent(e) @@ -259,9 +255,10 @@ class FileHandler: #---------------------------------------------------------------------- def getFileData(self, id): """returns dict with file information""" - pyfile = self.getFile(id) + if self.cache.has_key(id): + return self.cache[id].toDbDict() - return pyfile.toDbDict() if pyfile else {} + return self.db.getLinkData() #---------------------------------------------------------------------- def getFile(self, id): @@ -272,11 +269,10 @@ class FileHandler: return self.db.getFile(id) #---------------------------------------------------------------------- + @lock def getJob(self, occ): """get suitable job""" - self.lock.acquire() - #@TODO clean mess if self.jobCache.has_key(occ): @@ -312,7 +308,6 @@ class FileHandler: #pyfile = self.getFile(self.jobCache[occ].pop()) - self.lock.release() return pyfile #---------------------------------------------------------------------- @@ -330,6 +325,8 @@ class FileHandler: pass #---------------------------------------------------------------------- + @change + @lock def restartPackage(self, id): """restart package""" for pyfile in self.cache.itervalues(): @@ -341,6 +338,8 @@ class FileHandler: e = UpdateEvent("pack", id, "collector" if not self.getPackage(id).queue else "queue") self.core.pullManager.addEvent(e) + @change + @lock def restartFile(self, id): """ restart file""" if self.cache.has_key(id): @@ -356,6 +355,7 @@ class FileHandler: self.core.pullManager.addEvent(e) @change + @lock def setPackageLocation(self, id, queue): """push package to queue""" @@ -380,6 +380,7 @@ class FileHandler: self.core.pullManager.addEvent(e) @change + @lock def reorderPackage(self, id, position): p = self.db.getPackage(id) @@ -394,23 +395,33 @@ class FileHandler: self.core.pullManager.addEvent(e) @change + @lock def reorderFile(self, id, position): - f = self.db.getFile(id) + f = self.getFileData(id) - e = RemoveEvent("file", id, "collector" if not f.package().queue else "queue") + #@TODO test... + + e = RemoveEvent("file", id, "collector" if not self.getPackage(f[str(id)]["package"]).queue else "queue") self.core.pullManager.addEvent(e) - self.db.reorderFile(f, position) + self.db.reorderLink(f, position) + + if self.cache.has_key(id): + self.cache[id].order = position self.db.commit() - e = ReloadAllEvent("collector" if not f.package().queue else "queue") + e = ReloadAllEvent("collector" if not self.getPackage(f[str(id)]["package"]).queue else "queue") + + self.core.pullManager.addEvent(e) @change - def updateFileInfo(self, data): + def updateFileInfo(self, data, pid): """ updates file info (name, size, status, url)""" self.db.updateLinkInfo(data) + + #@TODO package update event ######################################################################### class FileDatabaseBackend(Thread): @@ -526,10 +537,10 @@ class FileDatabaseBackend(Thread): @queue def addLinks(self, links, package): - """ links is a list of tupels (url,name,plugin)""" + """ links is a list of tupels (url,plugin)""" order = self._nextFileOrder(package) orders = [order+x for x in range(len(links))] - links = [(x[0],x[1],x[2],package,o) for x, o in links, orders] + links = [(x[0],x[0],x[1],package,o) for x, o in zip(links, orders)] self.c.executemany('INSERT INTO links(url, name, plugin, package, linkorder) VALUES(?,?,?,?,?)', links) @queue @@ -617,8 +628,24 @@ class FileDatabaseBackend(Thread): def getLinkData(self, id): - """get link information""" - pass + """get link information as dict""" + self.c.execute('SELECT id,url,name,size,status,error,plugin,package,linkorder FROM links WHERE id=?', (str(id),)) + data = {} + r = self.c.fetchone() + data[str(r[0])] = { + 'url': r[1], + 'name': r[2], + 'size': r[3], + 'format_size': formatSize(r[3]), + 'status': r[4], + 'statusmsg': self.manager.statusMsg[r[4]], + 'error': r[5], + 'plugin': r[6], + 'package': r[7], + 'order': r[8] + } + + return data @queue def getPackageData(self, id): @@ -667,12 +694,13 @@ class FileDatabaseBackend(Thread): @queue def reorderLink(self, f, position): - self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder > ? AND package=?', ( f.order, str(f.packageid) ) ) - self.c.execute('UPDATE links SET linkorder=linkorder+1 WHERE linkorder >= ? AND package=?', ( position, str(f.packageid) ) ) - self.c.execute('UPDATE links SET linkorder=? WHERE id=?', ( position, str(f.id) ) ) - f.order = position - f.sync() - + """ reorder link with f as dict for pyfile """ + id = f.keys[0] + self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder > ? AND package=?', ( f[str(id)]["order"], str(f[str(id)]["package"]) ) ) + self.c.execute('UPDATE links SET linkorder=linkorder+1 WHERE linkorder >= ? AND package=?', ( position, str(f[str(id)]["package"]) ) ) + self.c.execute('UPDATE links SET linkorder=? WHERE id=?', ( position, str(id) ) ) + + @queue def clearPackageOrder(self, p): self.c.execute('UPDATE packages SET packageorder=? WHERE id=?', ( -1, str(p.id) ) ) diff --git a/module/PluginThread.py b/module/PluginThread.py index 35aee66be..d60880ef3 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -271,11 +271,12 @@ class HookThread(PluginThread): class InfoThread(PluginThread): #---------------------------------------------------------------------- - def __init__(self, manager, data): + def __init__(self, manager, data, pid): """Constructor""" PluginThread.__init__(self, manager) self.data = data + self.pid = pid # package id # [ .. (name, plugin) .. ] self.start() @@ -292,12 +293,12 @@ class InfoThread(PluginThread): plugins[plugin] = [url] for pluginname, urls in plugins.iteritems(): - plugin = self.m.core.pluginManager.getPlugin(plugin) + plugin = self.m.core.pluginManager.getPlugin(pluginname) if hasattr(plugin, "getInfo"): self.m.core.log.debug("Run Info Fetching for %s" % pluginname) for result in plugin.getInfo(urls): if not type(result) == list: result = [result] - self.m.core.files.updateFileInfo(result) + self.m.core.files.updateFileInfo(result, self.pid) self.m.core.log.debug("Finished Info Fetching for %s" % pluginname) diff --git a/module/ThreadManager.py b/module/ThreadManager.py index 9e8da1b2c..caa8524d4 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -61,13 +61,13 @@ class ThreadManager: self.threads.append(thread) #---------------------------------------------------------------------- - def createInfoThread(self, data): + def createInfoThread(self, data, pid): """ start a thread whichs fetches online status and other infos data = [ .. () .. ] """ - PluginThread.InfoThread(self, data) + PluginThread.InfoThread(self, data, pid) #---------------------------------------------------------------------- @@ -156,7 +156,7 @@ class ThreadManager: def assignJob(self): """assing a job to a thread if possible""" - if self.pause: return + if self.pause or not self.core.server_methods.is_time_download(): return free = [x for x in self.threads if not x.active] |