Package ZenRelations :: Module ExportRM
[hide private]
[frames] | no frames]

Source Code for Module ZenRelations.ExportRM

 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__="""ExportRM 
15   
16  Export RelationshipManager objects from a zope database 
17   
18  $Id: ExportRM.py,v 1.1 2003/04/23 21:25:58 edahl Exp $""" 
19   
20  __version__ = "$Revision: 1.1 $"[11:-2] 
21   
22  import sys 
23   
24  import Globals 
25   
26  from Products.ZenUtils.ZCmdBase import ZCmdBase 
27  from Products.ZenRelations.RelationshipManager import RelationshipManager 
28   
29 -class ExportRM(ZCmdBase):
30
31 - def __init__(self):
32 ZCmdBase.__init__(self) 33 if not self.options.outfile: 34 self.outfile = sys.stdout 35 else: 36 self.outfile = open(self.options.outfile, 'w')
37 38
39 - def buildOptions(self):
40 """basic options setup sub classes can add more options here""" 41 ZCmdBase.buildOptions(self) 42 self.parser.add_option('-o', '--outfile', 43 dest="outfile", 44 help="output file for export default is stdout") 45 self.parser.add_option('--ignore', action="append", 46 dest="ignorerels", default=[], 47 help="relations that should be ignored can be many")
48 49
50 - def export(self, root=None):
51 if not root: 52 root = self.dataroot 53 if hasattr(root, "exportXml"): 54 self.outfile.write("""<?xml version="1.0"?>\n""") 55 self.outfile.write("<objects>\n") 56 root.exportXml(self.outfile,self.options.ignorerels,True) 57 self.outfile.write("</objects>\n") 58 else: 59 print "ERROR: root object not a exportable (exportXml not found)"
60 61 62 63 if __name__ == '__main__': 64 ex = ExportRM() 65 ex.export() 66