Package ZenUtils :: Module CheckRelations
[hide private]
[frames] | no frames]

Source Code for Module ZenUtils.CheckRelations

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
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   
31 -class CheckRelations(ZenScriptBase):
32
33 - def rebuild(self):
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
54 - def buildOptions(self):
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