Package Products :: Package ZenModel :: Module XmlDataLoader |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.XmlDataLoader

     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  import os
    14  import transaction
    15  import Globals
    16
    17  from Products.ZenRelations.ImportRM import ImportRM
    18
    19 -class XmlDataLoader(ImportRM):
    20
    21 -    def loadDatabase(self):
    22          datadir = os.path.join(os.path.dirname(__file__),"data")
    23          self.log.info("loading data from:%s", datadir)
    24          for path, dirname, filenames in os.walk(datadir):
    25              filenames.sort()
    26              for filename in filter(lambda f: f.endswith(".xml"), filenames):
    27                  self.options.infile = os.path.join(path,filename)
    28                  self.log.info("loading: %s", self.options.infile)
    29                  ImportRM.loadDatabase(self)
    30          # Reindex ProductKeys and EventClassKeys after XML load
    31          self.dmd.Manufacturers.reIndex()
    32          self.dmd.Events.reIndex()
    33          transaction.commit()
    34
    35
    36  if __name__ == "__main__":
    37      rl = XmlDataLoader()
    38      rl.loadDatabase()
    39