Mercurial > libervia-backend
comparison src/tools/sqlite.py @ 413:dd4caab17008
core: - individual parameters managed through sqlite
- new asyncGetParamA method, which allow to get parameter for a not connected profile
==> individual parameters are cached in memory when the profile is connected, but must be accessed
though sqlite else, and that must be done asynchronously
primitivus:
- profile manager updated to use asyncGetParamA
/!\ still broken, need more work before being able to run again
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 01 Nov 2011 20:39:22 +0100 |
parents | 62b17854254e |
children | 32dc8b18c2ae |
comparison
equal
deleted
inserted
replaced
412:62b17854254e | 413:dd4caab17008 |
---|---|
96 def loadGenParams(self, params_gen): | 96 def loadGenParams(self, params_gen): |
97 """Load general parameters | 97 """Load general parameters |
98 @param params_gen: dictionary to fill | 98 @param params_gen: dictionary to fill |
99 @return: deferred""" | 99 @return: deferred""" |
100 def fillParams(result): | 100 def fillParams(result): |
101 params_gen[(category, name)] = value | 101 for param in result: |
102 category,name,value = param | |
103 params_gen[(category, name)] = value | |
102 debug(_("loading general parameters from database")) | 104 debug(_("loading general parameters from database")) |
103 return self.dbpool.runQuery("SELECT category,name,value FROM param_gen").addCallback(fillParams) | 105 return self.dbpool.runQuery("SELECT category,name,value FROM param_gen").addCallback(fillParams) |
104 | 106 |
105 def loadIndParams(self, params_ind, profile): | 107 def loadIndParams(self, params_ind, profile): |
106 """Load general parameters | 108 """Load general parameters |
107 @param params_ind: dictionary to fill | 109 @param params_ind: dictionary to fill |
108 @param profile: a profile which *must* exist | 110 @param profile: a profile which *must* exist |
109 @return: deferred""" | 111 @return: deferred""" |
110 def fillParams(result): | 112 def fillParams(result): |
111 params_ind[profile][(category, name)] = value | 113 for param in result: |
114 category,name,value = param | |
115 params_ind[profile][(category, name)] = value | |
112 debug(_("loading individual parameters from database")) | 116 debug(_("loading individual parameters from database")) |
113 d = self.dbpool.runQuery("SELECT category,name,value FROM param_gen WHERE profile_id=?", self.profiles[profile]) | 117 d = self.dbpool.runQuery("SELECT category,name,value FROM param_gen WHERE profile_id=?", self.profiles[profile]) |
114 d.addCallback(fillParams) | 118 d.addCallback(fillParams) |
115 return d | 119 return d |
120 | |
121 def getIndParam(self, category, name, profile): | |
122 """Ask database for the value of one specific individual parameter | |
123 @param category: category of the parameter | |
124 @param name: name of the parameter | |
125 @param profile: %(doc_profile)s | |
126 @return: deferred""" | |
127 d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", (category,name,self.profiles[profile])) | |
128 d.addCallback(self.__getFirstResult) | |
129 return d | |
130 | |
116 | 131 |
117 def setGenParam(self, category, name, value): | 132 def setGenParam(self, category, name, value): |
118 """Save the general parameters in database | 133 """Save the general parameters in database |
119 @param category: category of the parameter | 134 @param category: category of the parameter |
120 @param name: name of the parameter | 135 @param name: name of the parameter |
132 @param profile: a profile which *must* exist | 147 @param profile: a profile which *must* exist |
133 @return: deferred""" | 148 @return: deferred""" |
134 d = self.dbpool.runQuery("REPLACE INTO param_ind(category,name,profile_id,value) VALUES (?,?,?,?)", (category, name, self.profiles[profile], value)) | 149 d = self.dbpool.runQuery("REPLACE INTO param_ind(category,name,profile_id,value) VALUES (?,?,?,?)", (category, name, self.profiles[profile], value)) |
135 d.addErrback(lambda ignore: error(_("Can't set individual parameter (%(category)s/%(name)s) for [%(profile)s] in database" % {"category":category, "name":name, "profile":profile}))) | 150 d.addErrback(lambda ignore: error(_("Can't set individual parameter (%(category)s/%(name)s) for [%(profile)s] in database" % {"category":category, "name":name, "profile":profile}))) |
136 return d | 151 return d |
152 | |
153 ##Helper methods## | |
154 | |
155 def __getFirstResult(self, result): | |
156 """Return the first result of a database query | |
157 Useful when we are looking for one specific value""" | |
158 return "" if not result else result[0][0] |