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

# Source Code for Module Products.ZenUtils.CheckRelations

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  __doc__="""CmdBase
    12
    13  Add data base access functions for command line programs
    14
    15  $Id: CheckRelations.py,v 1.2 2004/10/19 22:28:59 edahl Exp $"""
    16
    17  __version__ = "$Revision: 1.2 $"[11:-2]
    18
    19
    20  import transaction
    21
    22  import Globals
    23
    24  from Products.ZenUtils.Utils import getAllConfmonObjects
    25
    26  from ZenScriptBase import ZenScriptBase
    27
    28 -class CheckRelations(ZenScriptBase):
    29
    30 -    def rebuild(self):
    31          repair = self.options.repair
    32          ccount = 0
    33          self.log.info("Checking relations...")
    34          for object in getAllConfmonObjects(self.dmd):
    35              ccount += 1
    36              self.log.debug("checking relations on object %s"
    37                                  % object.getPrimaryDmdId())
    38              object.checkRelations(repair=repair)
    39              ch = object._p_changed
    40              if not ch: object._p_deactivate()
    41              if ccount >= self.options.savepoint:
    42                  transaction.savepoint()
    43                  ccount = 0
    44          if self.options.nocommit:
    45              self.log.info("not commiting any changes")
    46          else:
    47              trans = transaction.get()
    48              trans.note('CheckRelations cleaned relations' )
    49              trans.commit()
    50
    51
    52 -    def buildOptions(self):
    53          ZenScriptBase.buildOptions(self)
    54
    55          self.parser.add_option('-r', '--repair',
    56                      dest='repair', action="store_true",
    57                      help='repair all inconsistant relations')
    58
    59          self.parser.add_option('-x', '--savepoint',
    60                      dest='savepoint', default=500, type="int",
    61                      help='how many lines should be loaded before savepoint')
    62
    63          self.parser.add_option('-n', '--nocommit',
    64                      dest='nocommit', action="store_true",
    65                      help='Do not store changes to the Dmd (for debugging)')
    66
    67
    68  if __name__ == "__main__":
    69      tmbk = CheckRelations(connect=True)
    70      tmbk.rebuild()
    71