1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""CmdBase
15
16 Add data base access functions for command line programs
17
18 $Id: ToManyRebuildKeys.py,v 1.2 2004/10/19 22:28:59 edahl Exp $"""
19
20 __version__ = "$Revision: 1.2 $"[11:-2]
21
22 import gc
23
24 from Acquisition import aq_parent
25
26 from Products.ZenUtils.Utils import getSubObjectsMemo
27
28 from ZCmdBase import ZCmdBase
29
30 from transaction import get_transaction
31
33
35 ccount = 0
36 for tomany in getSubObjectsMemo(self.dmd, self.filter, self.decend):
37 self.log.debug("rebuilding keys for relation %s on object %s" %
38 (tomany.getId(), aq_parent(tomany).getId()))
39 ccount += tomany.rebuildKeys(self.log)
40 if ccount >= self.options.commitCount and not self.options.noCommit:
41 trans = get_transaction()
42 trans.note('ToManyRebuildKeys rebuilt keys')
43 trans.commit()
44 ccount = 0
45 self.dmd._p_jar.sync()
46 gc.collect()
47 if self.options.noCommit:
48 self.log.info("not commiting any changes")
49 else:
50 trans = get_transaction()
51 trans.note('ToManyRebuildKeys rebuilt keys')
52 trans.commit()
53
54
56 return obj.meta_type == "To Many Relationship"
57
58
68
69
70
72 ZCmdBase.buildOptions(self)
73 self.parser.add_option('-x', '--commitCount',
74 dest='commitCount',
75 default=1000,
76 type="int",
77 help='how many lines should be loaded before commit')
78
79 self.parser.add_option('-n', '--noCommit',
80 dest='noCommit',
81 action="store_true",
82 default=0,
83 help='Do not store changes to the Dmd (for debugging)')
84
85
86 if __name__ == "__main__":
87 tmbk = ToManyRebuildKeys()
88 tmbk.rebuild()
89