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 or (at your
     8  # option) any later version as published by 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
    23          # This is an initial load, so we can forgo incremental commits
    24          self.options.chunk_size = 0
    25
    26          datadir = os.path.join(os.path.dirname(__file__),"data")
    27          self.log.info("loading data from:%s", datadir)
    28          for path, dirname, filenames in os.walk(datadir):
    29              filenames.sort()
    30              for filename in filter(lambda f: f.endswith(".xml"), filenames):
    31                  self.options.infile = os.path.join(path,filename)
    32                  self.log.info("loading: %s", self.options.infile)
    33                  ImportRM.loadDatabase(self)
    34          # Reindex ProductKeys and EventClassKeys after XML load
    35          self.dmd.Manufacturers.reIndex()
    36          self.dmd.Events.reIndex()
    37          transaction.commit()
    38
    39
    40  if __name__ == "__main__":
    41      rl = XmlDataLoader()
    42      rl.loadDatabase()
    43