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