diff options
Diffstat (limited to 'pyload/database')
-rw-r--r-- | pyload/database/Backend.py | 36 | ||||
-rw-r--r-- | pyload/database/File.py | 127 | ||||
-rw-r--r-- | pyload/database/Storage.py | 8 | ||||
-rw-r--r-- | pyload/database/User.py | 20 |
4 files changed, 64 insertions, 127 deletions
diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py index 48c1fcb0d..116241a13 100644 --- a/pyload/database/Backend.py +++ b/pyload/database/Backend.py @@ -21,43 +21,39 @@ DB_VERSION = 4 class style(object): db = None - @classmethod - + @classmethod def setDB(cls, db): cls.db = db - @classmethod - + @classmethod def inner(cls, f): - @staticmethod + @staticmethod def x(*args, **kwargs): if cls.db: return f(cls.db, *args, **kwargs) return x - @classmethod - + @classmethod def queue(cls, f): - @staticmethod + @staticmethod def x(*args, **kwargs): if cls.db: return cls.db.queue(f, *args, **kwargs) return x - @classmethod - + @classmethod def async(cls, f): - @staticmethod + @staticmethod def x(*args, **kwargs): if cls.db: return cls.db.async(f, *args, **kwargs) @@ -158,9 +154,8 @@ class DatabaseBackend(Thread): break j.processJob() - @style.queue - + @style.queue def shutdown(self): self.conn.commit() self.jobs.put("quit") @@ -282,21 +277,18 @@ class DatabaseBackend(Thread): def createCursor(self): return self.conn.cursor() - @style.async - + @style.async def commit(self): self.conn.commit() - @style.queue - + @style.queue def syncSave(self): self.conn.commit() - @style.async - + @style.async def rollback(self): self.conn.rollback() @@ -314,15 +306,13 @@ class DatabaseBackend(Thread): job.wait() return job.result - @classmethod - + @classmethod def registerSub(cls, klass): cls.subs.append(klass) - @classmethod - + @classmethod def unregisterSub(cls, klass): cls.subs.remove(klass) diff --git a/pyload/database/File.py b/pyload/database/File.py index 0ff520623..205cbba1a 100644 --- a/pyload/database/File.py +++ b/pyload/database/File.py @@ -76,9 +76,8 @@ class FileHandler(object): self.db.syncSave() - @lock - + @lock def getCompleteData(self, queue=1): """gets a complete data representation""" @@ -97,9 +96,8 @@ class FileHandler(object): return packs - @lock - + @lock def getInfoData(self, queue=1): """gets a data representation without links""" @@ -110,10 +108,9 @@ class FileHandler(object): return packs + @lock @change - - def addLinks(self, urls, package): """adds links""" @@ -215,8 +212,8 @@ class FileHandler(object): pyfile.order -= 1 pyfile.notifyChange() - #-------------------------------------------------------------------------- + #-------------------------------------------------------------------------- def releaseLink(self, id): """removes pyfile from cache""" @@ -353,9 +350,8 @@ class FileHandler(object): #pyfile = self.getFile(self.jobCache[occ].pop()) return pyfile - @lock - + @lock def getDecryptJob(self): """return job for decrypting""" if "decrypt" in self.jobCache: @@ -417,10 +413,9 @@ class FileHandler(object): def resetCount(self): self.queuecount = -1 + @lock @change - - def restartPackage(self, id): """restart package""" pyfiles = self.cache.values() @@ -436,10 +431,9 @@ class FileHandler(object): e = UpdateEvent("pack", id, "collector" if not self.getPackage(id).queue else "queue") self.core.pullManager.addEvent(e) + @lock @change - - def restartFile(self, id): """ restart file""" if id in self.cache: @@ -453,10 +447,9 @@ class FileHandler(object): e = UpdateEvent("file", id, "collector" if not self.getFile(id).package().queue else "queue") self.core.pullManager.addEvent(e) + @lock @change - - def setPackageLocation(self, id, queue): """push package to queue""" @@ -488,10 +481,9 @@ class FileHandler(object): e = InsertEvent("pack", id, p.order, "collector" if not p.queue else "queue") self.core.pullManager.addEvent(e) + @lock @change - - def reorderPackage(self, id, position): p = self.getPackage(id) @@ -517,10 +509,9 @@ class FileHandler(object): e = InsertEvent("pack", id, position, "collector" if not p.queue else "queue") self.core.pullManager.addEvent(e) + @lock @change - - def reorderFile(self, id, position): f = self.getFileData(id) f = f[id] @@ -550,9 +541,8 @@ class FileHandler(object): e = InsertEvent("file", id, position, "collector" if not self.getPackage(f["package"]).queue else "queue") self.core.pullManager.addEvent(e) - @change - + @change def updateFileInfo(self, data, pid): """ updates file info (name, size, status, url)""" ids = self.db.updateLinkInfo(data) @@ -583,10 +573,9 @@ class FileHandler(object): self.core.threadManager.createInfoThread(urls, pid) + @lock @change - - def deleteFinishedLinks(self): """ deletes finished links and packages, return deleted packages """ @@ -607,43 +596,39 @@ class FileHandler(object): return deleted + @lock @change - - def restartFailed(self): """ restart all failed links """ self.db.restartFailed() class FileMethods(object): - @style.queue + @style.queue def filecount(self, queue): """returns number of files in queue""" self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=?", (queue,)) return self.c.fetchone()[0] - @style.queue - + @style.queue def queuecount(self, queue): """ number of files in queue not finished yet""" self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status NOT IN (0, 4)", (queue,)) return self.c.fetchone()[0] - @style.queue - + @style.queue def processcount(self, queue, fid): """ number of files which have to be proccessed """ self.c.execute("SELECT COUNT(*) FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE p.queue=? AND l.status IN (2, 3, 5, 7, 12) AND l.id != ?", (queue, str(fid))) return self.c.fetchone()[0] - @style.inner - + @style.inner def _nextPackageOrder(self, queue=0): self.c.execute('SELECT MAX(packageorder) FROM packages WHERE queue=?', (queue,)) max = self.c.fetchone()[0] @@ -652,9 +637,8 @@ class FileMethods(object): else: return 0 - @style.inner - + @style.inner def _nextFileOrder(self, package): self.c.execute('SELECT MAX(linkorder) FROM links WHERE package=?', (package,)) max = self.c.fetchone()[0] @@ -663,17 +647,15 @@ class FileMethods(object): else: return 0 - @style.queue - + @style.queue def addLink(self, url, name, plugin, package): order = self._nextFileOrder(package) self.c.execute('INSERT INTO links(url, name, plugin, package, linkorder) VALUES(?,?,?,?,?)', (url, name, ".".join(plugintype, pluginname), package, order)) return self.c.lastrowid - @style.queue - + @style.queue def addLinks(self, links, package): """ links is a list of tupels (url, plugin)""" order = self._nextFileOrder(package) @@ -681,32 +663,28 @@ class FileMethods(object): links = [(x[0], x[0], ".".join((x[1], x[2])), package, o) for x, o in zip(links, orders)] self.c.executemany('INSERT INTO links(url, name, plugin, package, linkorder) VALUES(?,?,?,?,?)', links) - @style.queue - + @style.queue def addPackage(self, name, folder, queue): order = self._nextPackageOrder(queue) self.c.execute('INSERT INTO packages(name, folder, queue, packageorder) VALUES(?,?,?,?)', (name, folder, queue, order)) return self.c.lastrowid - @style.queue - + @style.queue def deletePackage(self, p): self.c.execute('DELETE FROM links WHERE package=?', (str(p.id),)) self.c.execute('DELETE FROM packages WHERE id=?', (str(p.id),)) self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=?', (p.order, p.queue)) - @style.queue - + @style.queue def deleteLink(self, f): self.c.execute('DELETE FROM links WHERE id=?', (str(f.id),)) self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder > ? AND package=?', (f.order, str(f.packageid))) - @style.queue - + @style.queue def getAllLinks(self, q): """return information about all links in queue q @@ -739,9 +717,8 @@ class FileMethods(object): return data - @style.queue - + @style.queue def getAllPackages(self, q): """return information about packages in queue q (only useful in get all data) @@ -778,9 +755,8 @@ class FileMethods(object): return data - @style.queue - + @style.queue def getLinkData(self, id): """get link information as dict""" self.c.execute('SELECT id, url, name, size, status, error, plugin, package, linkorder FROM links WHERE id=?', (str(id),)) @@ -804,9 +780,8 @@ class FileMethods(object): return data - @style.queue - + @style.queue def getPackageData(self, id): """get data about links for a package""" self.c.execute('SELECT id, url, name, size, status, error, plugin, package, linkorder FROM links WHERE package=? ORDER BY linkorder', (str(id),)) @@ -829,21 +804,18 @@ class FileMethods(object): return data - @style.async - + @style.async def updateLink(self, f): self.c.execute('UPDATE links SET url=?, name=?, size=?, status=?, error=?, package=? WHERE id=?', (f.url, f.name, f.size, f.status, str(f.error), str(f.packageid), str(f.id))) - @style.queue - + @style.queue def updatePackage(self, p): self.c.execute('UPDATE packages SET name=?, folder=?, site=?, password=?, queue=? WHERE id=?', (p.name, p.folder, p.site, p.password, p.queue, str(p.id))) - @style.queue - + @style.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 IN (1, 2, 3, 14)', data) @@ -853,9 +825,8 @@ class FileMethods(object): ids.append(int(r[0])) return ids - @style.queue - + @style.queue def reorderPackage(self, p, position, noMove=False): if position == -1: position = self._nextPackageOrder(p.queue) @@ -867,9 +838,8 @@ class FileMethods(object): self.c.execute('UPDATE packages SET packageorder=? WHERE id=?', (position, str(p.id))) - @style.queue - + @style.queue def reorderLink(self, f, position): """ reorder link with f as dict for pyfile """ if f["order"] > position: @@ -879,28 +849,24 @@ class FileMethods(object): self.c.execute('UPDATE links SET linkorder=? WHERE id=?', (position, f["id"])) - @style.queue - + @style.queue def clearPackageOrder(self, p): self.c.execute('UPDATE packages SET packageorder=? WHERE id=?', (-1, str(p.id))) self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=? AND id != ?', (p.order, p.queue, str(p.id))) - @style.async - + @style.async def restartFile(self, id): self.c.execute('UPDATE links SET status=3, error="" WHERE id=?', (str(id),)) - @style.async - + @style.async def restartPackage(self, id): self.c.execute('UPDATE links SET status=3 WHERE package=?', (str(id),)) - @style.queue - + @style.queue def getPackage(self, id): """return package instance from id""" self.c.execute("SELECT name, folder, site, password, queue, packageorder FROM packages WHERE id=?", (str(id),)) @@ -921,9 +887,8 @@ class FileMethods(object): r[5] = tuple(r[5].split('.')) return PyFile(self.manager, id, * r) - @style.queue - + @style.queue def getJob(self, occ): """return pyfile ids, which are suitable for download and dont use a occupied plugin""" @@ -943,9 +908,8 @@ class FileMethods(object): return [x[0] for x in self.c] - @style.queue - + @style.queue def getPluginJob(self, plugins): """returns pyfile ids with suited plugins""" cmd = "SELECT l.id FROM links as l INNER JOIN packages as p ON l.package=p.id WHERE l.plugin IN %s AND l.status IN (2, 3, 14) ORDER BY p.packageorder ASC, l.linkorder ASC LIMIT 5" % plugins @@ -954,39 +918,34 @@ class FileMethods(object): return [x[0] for x in self.c] - @style.queue - + @style.queue def getUnfinished(self, pid): """return list of max length 3 ids with pyfiles in package not finished or processed""" self.c.execute("SELECT id FROM links WHERE package=? AND status NOT IN (0, 4, 13) LIMIT 3", (str(pid),)) return [r[0] for r in self.c] - @style.queue - + @style.queue def deleteFinished(self): self.c.execute("DELETE FROM links WHERE status IN (0, 4)") self.c.execute("DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE packages.id=links.package)") - @style.queue - + @style.queue def restartFailed(self): self.c.execute("UPDATE links SET status=3, error='' WHERE status IN (6, 8, 9)") - @style.queue - + @style.queue def findDuplicates(self, id, folder, filename): """ checks if filename exists with different id and same package """ self.c.execute("SELECT l.plugin FROM links as l INNER JOIN packages as p ON l.package=p.id AND p.folder=? WHERE l.id!=? AND l.status=0 AND l.name=?", (folder, id, filename)) return self.c.fetchone() - @style.queue - + @style.queue def purgeLinks(self): self.c.execute("DELETE FROM links;") self.c.execute("DELETE FROM packages;") diff --git a/pyload/database/Storage.py b/pyload/database/Storage.py index bd7844d8d..a1dfb7e9f 100644 --- a/pyload/database/Storage.py +++ b/pyload/database/Storage.py @@ -5,9 +5,9 @@ from pyload.database import style from pyload.database import DatabaseBackend class StorageMethods(object): - @style.queue + @style.queue def setStorage(db, identifier, key, value): db.c.execute("SELECT id FROM storage WHERE identifier=? AND key=?", (identifier, key)) if db.c.fetchone() is not None: @@ -15,9 +15,8 @@ class StorageMethods(object): else: db.c.execute("INSERT INTO storage (identifier, key, value) VALUES (?, ?, ?)", (identifier, key, value)) - @style.queue - + @style.queue def getStorage(db, identifier, key=None): if key is not None: db.c.execute("SELECT value FROM storage WHERE identifier=? AND key=?", (identifier, key)) @@ -31,9 +30,8 @@ class StorageMethods(object): d[row[0]] = row[1] return d - @style.queue - + @style.queue def delStorage(db, identifier, key): db.c.execute("DELETE FROM storage WHERE identifier=? AND key=?", (identifier, key)) diff --git a/pyload/database/User.py b/pyload/database/User.py index 52b05749f..94f70d499 100644 --- a/pyload/database/User.py +++ b/pyload/database/User.py @@ -7,9 +7,9 @@ import random from pyload.database import DatabaseBackend, style class UserMethods(object): - @style.queue + @style.queue def checkAuth(db, user, password): c = db.c c.execute('SELECT id, name, password, role, permission, template, email FROM "users" WHERE name=?', (user,)) @@ -26,9 +26,8 @@ class UserMethods(object): else: return {} - @style.queue - + @style.queue def addUser(db, user, password): salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for i in range(0, 5)]) h = sha1(salt + password) @@ -43,8 +42,6 @@ class UserMethods(object): @style.queue - - def changePassword(db, user, oldpw, newpw): db.c.execute('SELECT id, name, password FROM users WHERE name=?', (user,)) r = db.c.fetchone() @@ -66,21 +63,16 @@ class UserMethods(object): @style.async - - def setPermission(db, user, perms): db.c.execute("UPDATE users SET permission=? WHERE name=?", (perms, user)) - @style.async - + @style.async def setRole(db, user, role): db.c.execute("UPDATE users SET role=? WHERE name=?", (role, user)) @style.queue - - def listUsers(db): db.c.execute('SELECT name FROM users') users = [] @@ -88,9 +80,8 @@ class UserMethods(object): users.append(row[0]) return users - @style.queue - + @style.queue def getAllUserData(db): db.c.execute("SELECT name, permission, role, template, email FROM users") user = {} @@ -99,9 +90,8 @@ class UserMethods(object): return user - @style.queue - + @style.queue def removeUser(db, user): db.c.execute('DELETE FROM users WHERE name=?', (user,)) |