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: CheckRelations.py,v 1.2 2004/10/19 22:28:59 edahl Exp $"""
19
20 __version__ = "$Revision: 1.2 $"[11:-2]
21
22
23 import transaction
24
25 import Globals
26 from Acquisition import aq_parent
27
28 from Products.ZenUtils.Utils import getAllConfmonObjects
29
30 from ZenScriptBase import ZenScriptBase
31
33
35 repair = self.options.repair
36 ccount = 0
37 for object in getAllConfmonObjects(self.dmd):
38 ccount += 1
39 self.log.debug("checking relations on object %s"
40 % object.getPrimaryDmdId())
41 object.checkRelations(repair=repair)
42 ch = object._p_changed
43 if not ch: object._p_deactivate()
44 if ccount >= self.options.savepoint:
45 transaction.savepoint()
46 ccount = 0
47 if self.options.nocommit:
48 self.log.info("not commiting any changes")
49 else:
50 trans = transaction.get()
51 trans.note('CheckRelations cleaned relations' )
52 trans.commit()
53
54
56 ZenScriptBase.buildOptions(self)
57
58 self.parser.add_option('-r', '--repair',
59 dest='repair', action="store_true",
60 help='repair all inconsistant relations')
61
62 self.parser.add_option('-x', '--savepoint',
63 dest='savepoint', default=500, type="int",
64 help='how many lines should be loaded before savepoint')
65
66 self.parser.add_option('-n', '--nocommit',
67 dest='nocommit', action="store_true",
68 help='Do not store changes to the Dmd (for debugging)')
69
70
71 if __name__ == "__main__":
72 tmbk = CheckRelations(connect=True)
73 tmbk.rebuild()
74