diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-09-10 11:49:35 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-09-10 11:49:35 +0200 |
commit | 54bc92b4c5e0b3543a313f497cbc2276403c5980 (patch) | |
tree | 60e220c41998d9a41dd9a0b94e9c6a5ee02ae86d /module/database/ConfigDatabase.py | |
parent | new config api (diff) | |
download | pyload-54bc92b4c5e0b3543a313f497cbc2276403c5980.tar.xz |
changed config + progress api
Diffstat (limited to 'module/database/ConfigDatabase.py')
-rw-r--r-- | module/database/ConfigDatabase.py | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/module/database/ConfigDatabase.py b/module/database/ConfigDatabase.py index cc24f6785..198ae0173 100644 --- a/module/database/ConfigDatabase.py +++ b/module/database/ConfigDatabase.py @@ -1,28 +1,49 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from module.database import DatabaseMethods, queue, async, inner - -# TODO +from module.database import DatabaseMethods, queue, async class ConfigMethods(DatabaseMethods): @async - def saveConfig(self, plugin, user, config): - pass + def saveConfig(self, plugin, config, user=None): + if user is None: + self.c.execute('INSERT INTO settings(plugin, config) VALUES(?,?)', (plugin, config)) + else: + self.c.execute('INSERT INTO settings(plugin, config, user) VALUES(?,?,?)', (plugin, config, user)) + @queue - def loadConfig(self, plugin, user): - pass + def loadConfig(self, plugin, user=None): + if user is None: + self.c.execute('SELECT config FROM settings WHERE plugin=?', (plugin, )) + else: + self.c.execute('SELECT config FROM settings WHERE plugin=? AND user=?', (plugin, user)) + + return self.c.fetchone()[0] @async - def deleteConfig(self, plugin, user): - pass + def deleteConfig(self, plugin, user=None): + if user is None: + self.c.execute('DELETE FROM settings WHERE plugin=?', (plugin, )) + else: + self.c.execute('DELETE FROM settings WHERE plugin=? AND user=?', (plugin, user)) @queue def loadAllConfigs(self): - pass + self.c.execute('SELECT user, plugin, config FROM settings') + configs = {} + for r in self.c: + if r[0] in configs: + configs[r[0]][r[1]] = r[2] + else: + configs[r[0]] = {r[1]: r[2]} + return configs + + @async + def clearAllConfigs(self): + self.c.execute('DELETE FROM settings') ConfigMethods.register()
\ No newline at end of file |