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  from Acquisition import aq_parent 
27   
28  from Products.ZenUtils.Utils import getAllConfmonObjects 
29   
30  from ZenScriptBase import ZenScriptBase 
31   
32 -class CheckRelations(ZenScriptBase):
33
34 - def rebuild(self):
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
55 - def buildOptions(self):
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