Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 4430:f2f2904fe6ce
- refactor: move import_journal to hyperdb
.-- it was reimplemented in back_anydbm and rdbms_common and was
already inconsistent -- and it doen't have any backend dependencies
itself. Interestingly this now fails a test for memorydb (but
passes for anydbm: Huh?)
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Thu, 07 Oct 2010 12:22:10 +0000 |
| parents | 06af6d5bedbe |
| children | 9b619dcb030a |
comparison
equal
deleted
inserted
replaced
| 4429:d75e92fbfcca | 4430:f2f2904fe6ce |
|---|---|
| 1235 def export_propnames(self): | 1235 def export_propnames(self): |
| 1236 """List the property names for export from this Class""" | 1236 """List the property names for export from this Class""" |
| 1237 propnames = self.getprops().keys() | 1237 propnames = self.getprops().keys() |
| 1238 propnames.sort() | 1238 propnames.sort() |
| 1239 return propnames | 1239 return propnames |
| 1240 | |
| 1241 def import_journals(self, entries): | |
| 1242 """Import a class's journal. | |
| 1243 | |
| 1244 Uses setjournal() to set the journal for each item. | |
| 1245 Strategy for import: Sort first by id, then import journals for | |
| 1246 each id, this way the memory footprint is a lot smaller than the | |
| 1247 initial implementation which stored everything in a big hash by | |
| 1248 id and then proceeded to import journals for each id.""" | |
| 1249 properties = self.getprops() | |
| 1250 a = [] | |
| 1251 for l in entries: | |
| 1252 # first element in sorted list is the (numeric) id | |
| 1253 # in python2.4 and up we would use sorted with a key... | |
| 1254 a.append ((int (l [0].strip ("'")), l)) | |
| 1255 a.sort () | |
| 1256 | |
| 1257 | |
| 1258 last = 0 | |
| 1259 r = [] | |
| 1260 for n, l in a: | |
| 1261 nodeid, jdate, user, action, params = map(eval, l) | |
| 1262 assert (str(n) == nodeid) | |
| 1263 if n != last: | |
| 1264 if r: | |
| 1265 self.db.setjournal(self.classname, nodeid, r) | |
| 1266 last = n | |
| 1267 r = [] | |
| 1268 | |
| 1269 if action == 'set': | |
| 1270 for propname, value in params.iteritems(): | |
| 1271 prop = properties[propname] | |
| 1272 if value is None: | |
| 1273 pass | |
| 1274 elif isinstance(prop, Date): | |
| 1275 value = date.Date(value) | |
| 1276 elif isinstance(prop, Interval): | |
| 1277 value = date.Interval(value) | |
| 1278 elif isinstance(prop, Password): | |
| 1279 pwd = password.Password() | |
| 1280 pwd.unpack(value) | |
| 1281 value = pwd | |
| 1282 params[propname] = value | |
| 1283 elif action == 'create' and params: | |
| 1284 # old tracker with data stored in the create! | |
| 1285 params = {} | |
| 1286 r.append((nodeid, date.Date(jdate), user, action, params)) | |
| 1287 if r: | |
| 1288 self.db.setjournal(self.classname, nodeid, r) | |
| 1289 | |
| 1240 # | 1290 # |
| 1241 # convenience methods | 1291 # convenience methods |
| 1242 # | 1292 # |
| 1243 def get_roles(self, nodeid): | 1293 def get_roles(self, nodeid): |
| 1244 """Return iterator for all roles for this nodeid. | 1294 """Return iterator for all roles for this nodeid. |
