Mercurial > p > roundup > code
comparison roundup/backends/rdbms_common.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 | d75e92fbfcca |
| children | 2784c239e6c8 |
comparison
equal
deleted
inserted
replaced
| 4429:d75e92fbfcca | 4430:f2f2904fe6ce |
|---|---|
| 2639 params = {} | 2639 params = {} |
| 2640 l = [nodeid, date, user, action, params] | 2640 l = [nodeid, date, user, action, params] |
| 2641 r.append(list(map(repr, l))) | 2641 r.append(list(map(repr, l))) |
| 2642 return r | 2642 return r |
| 2643 | 2643 |
| 2644 def import_journals(self, entries): | |
| 2645 """Import a class's journal. | |
| 2646 | |
| 2647 Uses setjournal() to set the journal for each item. | |
| 2648 Strategy for import: Sort first by id, then import journals for | |
| 2649 each id, this way the memory footprint is a lot smaller than the | |
| 2650 initial implementation which stored everything in a big hash by | |
| 2651 id and then proceeded to import journals for each id.""" | |
| 2652 properties = self.getprops() | |
| 2653 a = [] | |
| 2654 for l in entries: | |
| 2655 # first element in sorted list is the (numeric) id | |
| 2656 # in python2.4 and up we would use sorted with a key... | |
| 2657 a.append ((int (l [0].strip ("'")), l)) | |
| 2658 a.sort () | |
| 2659 | |
| 2660 | |
| 2661 last = 0 | |
| 2662 r = [] | |
| 2663 for n, l in a: | |
| 2664 nodeid, jdate, user, action, params = map(eval, l) | |
| 2665 assert (str(n) == nodeid) | |
| 2666 if n != last: | |
| 2667 if r: | |
| 2668 self.db.setjournal(self.classname, nodeid, r) | |
| 2669 last = n | |
| 2670 r = [] | |
| 2671 | |
| 2672 if action == 'set': | |
| 2673 for propname, value in params.iteritems(): | |
| 2674 prop = properties[propname] | |
| 2675 if value is None: | |
| 2676 pass | |
| 2677 elif isinstance(prop, Date): | |
| 2678 value = date.Date(value) | |
| 2679 elif isinstance(prop, Interval): | |
| 2680 value = date.Interval(value) | |
| 2681 elif isinstance(prop, Password): | |
| 2682 pwd = password.Password() | |
| 2683 pwd.unpack(value) | |
| 2684 value = pwd | |
| 2685 params[propname] = value | |
| 2686 elif action == 'create' and params: | |
| 2687 # old tracker with data stored in the create! | |
| 2688 params = {} | |
| 2689 r.append((nodeid, date.Date(jdate), user, action, params)) | |
| 2690 if r: | |
| 2691 self.db.setjournal(self.classname, nodeid, r) | |
| 2692 | |
| 2693 class FileClass(hyperdb.FileClass, Class): | 2644 class FileClass(hyperdb.FileClass, Class): |
| 2694 """This class defines a large chunk of data. To support this, it has a | 2645 """This class defines a large chunk of data. To support this, it has a |
| 2695 mandatory String property "content" which is typically saved off | 2646 mandatory String property "content" which is typically saved off |
| 2696 externally to the hyperdb. | 2647 externally to the hyperdb. |
| 2697 | 2648 |
