[Oval-commits] r309 - in trunk/oval-server: . oval/dsa2oval/definition

Pavel Vinogradov blaze-guest at alioth.debian.org
Sun Nov 18 19:49:00 UTC 2007


Author: blaze-guest
Date: 2007-11-18 19:49:00 +0000 (Sun, 18 Nov 2007)
New Revision: 309

Modified:
   trunk/oval-server/dsa2oval.py
   trunk/oval-server/oval/dsa2oval/definition/generator.py
Log:
Rewrite OVAL XML generation. Reduce memory usage.

Modified: trunk/oval-server/dsa2oval.py
===================================================================
--- trunk/oval-server/dsa2oval.py	2007-11-18 19:47:46 UTC (rev 308)
+++ trunk/oval-server/dsa2oval.py	2007-11-18 19:49:00 UTC (rev 309)
@@ -15,8 +15,10 @@
 from oval.dsa2oval.definition import generator
 from oval.dsa2oval.parser import dsa
 from oval.dsa2oval.parser import wml
+#from guppy import hpy
 
 assert sys.version_info >= (2,4), 'Requires Python 2.4 or better'
+#h = hpy()
 
 class Walker:
 	
@@ -39,9 +41,14 @@
     	Use generator from dsa2oval package for convert all DSA stored in dict
     	to proper formated XML file.
     	"""
-		ovalBuilder = generator.OVALGenerator()    
-		ovalDefinitions = ovalBuilder.createOVALDefinitions (self.dsaref)
-		ovalBuilder.printOVALDefinitions (ovalDefinitions)
+		ovalBuilder = generator.OVALGenerator()
+		
+#		print "Before: ovalBuilder.printOVALDefinitions (self.dsaref)"
+#		print h.heap()    
+		ovalBuilder.printOVALDefinitions (self.dsaref)
+		
+#		print "After: ovalBuilder.printOVALDefinitions (self.dsaref)"		
+#		print h.heap()
 
 	def parseDir (self, directory, depth):
 		""" Recursive search directory for DSA files contain postfix in their names.
@@ -102,7 +109,7 @@
 
 		@type filename: C(string)
 		@param filename: path to DSA file
-		@rtype: C(string)		
+		@rtype: C(int)		
 		"""
 
 		(path, ext) = os.path.splitext(filename)

Modified: trunk/oval-server/oval/dsa2oval/definition/generator.py
===================================================================
--- trunk/oval-server/oval/dsa2oval/definition/generator.py	2007-11-18 19:47:46 UTC (rev 308)
+++ trunk/oval-server/oval/dsa2oval/definition/generator.py	2007-11-18 19:49:00 UTC (rev 309)
@@ -479,8 +479,16 @@
 			Generate namespace section and use other functions to generate definitions,
 			tests, objects and states subsections.
 			
-			return -- Generated OVAL XML definition 
+			@attention: Generated OVAL XML definitions required big amount of memory
+			@deprecated: Require big amount of memory. Use printOVALDefinitions instead
+			
+			@type dsaref: C(dict)
+			@param dsaref: Dict with DSA data 
+			
+			@return: 	Generated OVAL XML definition
+			@rtype: 	C(string) 
 		"""
+		
 		doc = xml.dom.minidom.Document ()
 	
 		root = self.__createXMLElement ("oval_definitions", 
@@ -499,23 +507,53 @@
 		root.appendChild ( self.__createGeneratorHeader () )
 		
 		definitions = doc.createElement ("definitions")
-		
+				
 		keyids = dsaref.keys()
 		keyids.sort()
 		for dsa in keyids:
-			try:
+			try:				
 				definitions.appendChild (self.createDefinition(dsa, dsaref[dsa]))
 			except DSAFormatException:
 				logging.log (logging.ERROR, "DSA %s: Bad data file. Ignore this DSA." % dsa)
-				
+		
 		root.appendChild (definitions)
 		
 		root.appendChild(self.tests)
 		root.appendChild(self.objects)
 		root.appendChild(self.states)
-	
+		
 		return doc
-	
-	def printOVALDefinitions (self, doc):
-		if doc.getElementsByTagName("definitions")[0].hasChildNodes():
-			xml.dom.ext.PrettyPrint(doc)
+
+	def printOVALDefinitions (self, dsaref):
+		""" Generate XML OVAL definition tree for range of DSA
+
+			Generate namespace section and use other functions to generate definitions,
+			tests, objects and states subsections.
+			
+			@attention: XML formatting have wrong indentation and newline
+			
+			@type dsaref: C(dict)
+			@param dsaref: Dict with DSA data 
+		"""
+		
+		print "<?xml version='1.0' encoding='UTF-8'?>"
+		print "<oval_definitions xmlns='http://oval.mitre.org/XMLSchema/oval-definitions-5' xmlns:unix-def='http://oval.mitre.org/XMLSchema/oval-definitions-5#unix' xmlns:ind-def ='http://oval.mitre.org/XMLSchema/oval-definitions-5#independent' xmlns:oval='http://oval.mitre.org/XMLSchema/oval-common-5' xmlns:oval-def='http://oval.mitre.org/XMLSchema/oval-definitions-5' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://oval.mitre.org/XMLSchema/oval-definitions-5#independent /usr/share/ovaldi/xml/independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux /usr/share/ovaldi/xml/linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix /usr/share/ovaldi/xml/unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 /usr/share/ovaldi/xml/oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 /usr/share/ovaldi/xml/oval-common-schema.xsd' xmlns:linux-def='http://oval.mitre.org/XMLSchema/oval-definitions-5#linux'>"		
+		
+		xml.dom.ext.PrettyPrint(self.__createGeneratorHeader ())		
+		print "  <definitions>"
+		
+		keyids = dsaref.keys()
+		keyids.sort()
+		for dsa in keyids:
+			try:				
+				xml.dom.ext.PrettyPrint(self.createDefinition(dsa, dsaref[dsa]))
+			except DSAFormatException:
+				logging.log (logging.ERROR, "DSA %s: Bad data file. Ignore this DSA." % dsa)
+		
+		print "  </definitions>"		
+		
+		xml.dom.ext.PrettyPrint(self.tests)		
+		xml.dom.ext.PrettyPrint(self.objects)
+		xml.dom.ext.PrettyPrint(self.states)
+		
+		print "</oval_definitions>"
\ No newline at end of file




More information about the Oval-commits mailing list