diff options
Diffstat (limited to 'pyload/database')
-rw-r--r-- | pyload/database/AccountDatabase.py | 22 | ||||
-rw-r--r-- | pyload/database/DatabaseBackend.py | 17 | ||||
-rw-r--r-- | pyload/database/FileDatabase.py | 30 | ||||
-rw-r--r-- | pyload/database/StatisticDatabase.py | 5 | ||||
-rw-r--r-- | pyload/database/UserDatabase.py | 8 |
5 files changed, 56 insertions, 26 deletions
diff --git a/pyload/database/AccountDatabase.py b/pyload/database/AccountDatabase.py index 3ca841fbc..e432af192 100644 --- a/pyload/database/AccountDatabase.py +++ b/pyload/database/AccountDatabase.py @@ -7,23 +7,33 @@ from pyload.database import DatabaseMethods, queue, async class AccountMethods(DatabaseMethods): @queue def loadAccounts(self): - self.c.execute('SELECT plugin, loginname, owner, activated, shared, password, options FROM accounts') + self.c.execute('SELECT aid, plugin, loginname, owner, activated, shared, password, options FROM accounts') - return [(AccountInfo(r[0], r[1], r[2], activated=r[3] is 1, shared=r[4] is 1), r[5], r[6]) for r in self.c] + return [(AccountInfo(r[0], r[1], r[2], r[3], activated=r[4] is 1, shared=r[5] is 1), r[6], r[7]) for r in + self.c] + + @queue + def createAccount(self, plugin, loginname, password, owner): + self.c.execute('INSERT INTO accounts(plugin, loginname, password, owner) VALUES(?,?,?,?)', + (plugin, loginname, password, owner)) + + return self.c.lastrowid @async def saveAccounts(self, data): - self.c.executemany( - 'INSERT INTO accounts(plugin, loginname, owner, activated, shared, password, options) VALUES(?,?,?,?,?,?,?)', + 'UPDATE accounts SET ' + 'loginname=?, activated=?, shared=?, password=?, options=? ' + 'WHERE aid=?', data) @async - def removeAccount(self, plugin, loginname): - self.c.execute('DELETE FROM accounts WHERE plugin=? AND loginname=?', (plugin, loginname)) + def removeAccount(self, aid): + self.c.execute('DELETE FROM accounts WHERE aid=?', (aid,)) @queue def purgeAccounts(self): self.c.execute('DELETE FROM accounts') + AccountMethods.register()
\ No newline at end of file diff --git a/pyload/database/DatabaseBackend.py b/pyload/database/DatabaseBackend.py index df8c6e704..1bdcdc582 100644 --- a/pyload/database/DatabaseBackend.py +++ b/pyload/database/DatabaseBackend.py @@ -30,7 +30,7 @@ except: import sqlite3 DB = None -DB_VERSION = 6 +DB_VERSION = 7 def set_DB(db): @@ -298,6 +298,7 @@ class DatabaseBackend(Thread): ) self.c.execute('CREATE INDEX IF NOT EXISTS "file_index" ON files(package, owner)') self.c.execute('CREATE INDEX IF NOT EXISTS "file_owner" ON files(owner)') + self.c.execute('CREATE INDEX IF NOT EXISTS "file_plugin" ON files(plugin)') self.c.execute( 'CREATE TRIGGER IF NOT EXISTS "insert_file" AFTER INSERT ON "files"' @@ -366,30 +367,32 @@ class DatabaseBackend(Thread): self.c.execute( 'CREATE TABLE IF NOT EXISTS "accounts" (' + '"aid" INTEGER PRIMARY KEY AUTOINCREMENT, ' '"plugin" TEXT NOT NULL, ' '"loginname" TEXT NOT NULL, ' - '"owner" INTEGER NOT NULL DEFAULT -1, ' + '"owner" INTEGER NOT NULL, ' '"activated" INTEGER NOT NULL DEFAULT 1, ' '"password" TEXT DEFAULT "", ' '"shared" INTEGER NOT NULL DEFAULT 0, ' '"options" TEXT DEFAULT "", ' - 'FOREIGN KEY(owner) REFERENCES users(uid), ' - 'PRIMARY KEY (plugin, loginname, owner) ON CONFLICT REPLACE' + 'FOREIGN KEY(owner) REFERENCES users(uid)' ')' ) + self.c.execute('CREATE INDEX IF NOT EXISTS "accounts_login" ON accounts(plugin, loginname)') + self.c.execute( 'CREATE TABLE IF NOT EXISTS "stats" (' + '"id" INTEGER PRIMARY KEY AUTOINCREMENT, ' '"user" INTEGER NOT NULL, ' '"plugin" TEXT NOT NULL, ' '"time" INTEGER NOT NULL, ' '"premium" INTEGER DEFAULT 0 NOT NULL, ' '"amount" INTEGER DEFAULT 0 NOT NULL, ' - 'FOREIGN KEY(user) REFERENCES users(uid), ' - 'PRIMARY KEY(user, plugin, time)' + 'FOREIGN KEY(user) REFERENCES users(uid)' ')' ) - self.c.execute('CREATE INDEX IF NOT EXISTS "stats_time" ON stats(time)') + self.c.execute('CREATE INDEX IF NOT EXISTS "stats_time" ON stats(user, time)') #try to lower ids self.c.execute('SELECT max(fid) FROM files') diff --git a/pyload/database/FileDatabase.py b/pyload/database/FileDatabase.py index 219b16663..e6e051a92 100644 --- a/pyload/database/FileDatabase.py +++ b/pyload/database/FileDatabase.py @@ -314,6 +314,10 @@ class FileMethods(DatabaseMethods): f.hash, f.status, f.error, f.fid)) @async + def setDownloadStatus(self, fid, status): + self.c.execute('UPDATE files SET dlstatus=? WHERE fid=?', (status, fid)) + + @async def updatePackage(self, p): self.c.execute( 'UPDATE packages SET name=?, folder=?, site=?, comment=?, password=?, tags=?, status=?, shared=? WHERE pid=?', @@ -383,22 +387,28 @@ class FileMethods(DatabaseMethods): # status -> queued self.c.execute('UPDATE files SET status=3 WHERE package=?', (pid,)) - - # TODO: multi user approach @queue - def getJob(self, occ): + def getJobs(self, occ): """return pyfile ids, which are suitable for download and don't use a occupied plugin""" cmd = "(%s)" % ", ".join(["'%s'" % x for x in occ]) - #TODO - # dlstatus in online, queued | package status = ok - cmd = ("SELECT f.fid FROM files as f INNER JOIN packages as p ON f.package=p.pid " - "WHERE f.plugin NOT IN %s AND f.dlstatus IN (2,3) AND p.status=0 " - "ORDER BY p.packageorder ASC, f.fileorder ASC LIMIT 5") % cmd + # dlstatus in online, queued, occupied | package status = ok + cmd = ("SELECT f.owner, f.fid FROM files as f INNER JOIN packages as p ON f.package=p.pid " + "WHERE f.owner=? AND f.plugin NOT IN %s AND f.dlstatus IN (2,3,16) AND p.status=0 " + "ORDER BY p.packageorder ASC, f.fileorder ASC LIMIT 1") % cmd + - self.c.execute(cmd) + self.c.execute("SELECT uid FROM users") + uids = self.c.fetchall() + jobs = {} + # get jobs for all uids + for uid in uids: + self.c.execute(cmd, uid) + r = self.c.fetchone() + if r: + jobs[r[0]] = r[1] - return [x[0] for x in self.c] + return jobs @queue def getUnfinished(self, pid): diff --git a/pyload/database/StatisticDatabase.py b/pyload/database/StatisticDatabase.py index d5f9658f2..5dd5ec7ed 100644 --- a/pyload/database/StatisticDatabase.py +++ b/pyload/database/StatisticDatabase.py @@ -3,11 +3,10 @@ from pyload.database import DatabaseMethods, queue, async, inner -# TODO class StatisticMethods(DatabaseMethods): - pass - + def addEntry(self, user, plugin, premium, amount): + pass StatisticMethods.register()
\ No newline at end of file diff --git a/pyload/database/UserDatabase.py b/pyload/database/UserDatabase.py index 8d8381a40..14b4ae40c 100644 --- a/pyload/database/UserDatabase.py +++ b/pyload/database/UserDatabase.py @@ -44,6 +44,14 @@ class UserMethods(DatabaseMethods): self.c.execute('INSERT INTO users (name, password) VALUES (?, ?)', (user, password)) @queue + def addDebugUser(self, uid): + # just add a user with uid to db + try: + self.c.execute('INSERT INTO users (uid, name, password) VALUES (?, ?, ?)', (uid, "debugUser", random_salt())) + except: + pass + + @queue def getUserData(self, name=None, uid=None): qry = ('SELECT uid, name, email, role, permission, folder, traffic, dllimit, dlquota, ' 'hddquota, user, template FROM "users" WHERE ') |