summaryrefslogtreecommitdiffstats
path: root/pyload/database/File.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/database/File.py')
-rw-r--r--pyload/database/File.py127
1 files changed, 43 insertions, 84 deletions
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;")