[Oval-commits] r106 - trunk/tools/oval/definition

Pavel Vinogradov blaze-guest at alioth.debian.org
Tue Aug 7 05:51:58 UTC 2007


Author: blaze-guest
Date: 2007-08-07 05:51:58 +0000 (Tue, 07 Aug 2007)
New Revision: 106

Modified:
   trunk/tools/oval/definition/generator.py
Log:
Code optimization. Add information about uname architectures

Modified: trunk/tools/oval/definition/generator.py
===================================================================
--- trunk/tools/oval/definition/generator.py	2007-08-06 19:25:58 UTC (rev 105)
+++ trunk/tools/oval/definition/generator.py	2007-08-07 05:51:58 UTC (rev 106)
@@ -13,7 +13,7 @@
 import xml.dom.ext
 import xml.dom.minidom
 from oval.definition.differ import differ
-
+					
 class OvalGeneratorException (Exception):
     pass
 
@@ -45,7 +45,7 @@
 		element.appendChild (description)
 	
 	return (element)
-					
+
 namespace = "oval:org.debian.oval"
 tests = __createXMLElement ("tests")
 objects = __createXMLElement ("objects")
@@ -57,6 +57,8 @@
 
 releaseArchHash = {"2.0" : 2, "2.1" : 4, "2.2":  6, "3.0" : 11, "3.1" : 12, "4.0" : 11}
 testsHash = {"arch" : {}, "release": {}, "obj": {}, "fileSte": {}, "unameSte" : {}, "dpkgSte": {}} 
+#We need more info about alpha, arm, hppa, bmips, lmips
+unameArchTable = {'i386' : 'i686', 'amd64' : 'x86-64', 'ia64' : 'ia64', 'powerpc' : 'ppc', 's390' : 's390x', 'm86k' : 'm86k'} 
 
 def __trimzero (val):
 	value = val[:]
@@ -162,14 +164,16 @@
 	return (testsHash["dpkgSte"][operation][value])
 
 def __createOVALUnameState (field, value, operation = "equals"):
-	""" Generate OVAL state definition 
+	""" Generate OVAL uname state definition 
 	
-		Use state hash for optimization of resulted XML
+		Use unameArchTable to convert dsa arch to uname arch value
 	"""
 	
-	if value == "i386":
-		value = "i686"
-	
+	try:
+		value = unameArchTable[value]
+	except KeyError:
+		pass
+
 	#TODO: Add arch state generation
 	if not testsHash["unameSte"].has_key(operation) or not testsHash["unameSte"][operation].has_key(value):
 		stateId = __getNewId ("state")
@@ -261,7 +265,8 @@
 					"xmlns":"http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"
 			})
 			test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
-			test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALUnameState ("processor_type", value, "equals")}))
+			if value != "all":
+				test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALUnameState ("processor_type", value, "equals")}))
 		
 		tests.appendChild(test)
 				
@@ -313,11 +318,15 @@
 		archIndepCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture independet section", "operator" : "AND"})
 		
 		archIndepCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", "all"), "comment" : "all architecture"}))
-		packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operator" : "OR"})
-		
+		#Build packages section only if we have more then one package
+		if len (data["all"]) > 1:
+			packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operator" : "OR"})
+			archIndepCriteria.appendChild (packageCriteria)
+		else:
+			packageCriteria = archIndepCriteria
+			
 		for pkg in data["all"].keys():
 			packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(pkg, data["all"][pkg]), "comment" : "%s DPKG is earlier than %s" % (pkg, data["all"][pkg])}))
-		archIndepCriteria.appendChild (packageCriteria)
 	
 		archCriteria.appendChild (archIndepCriteria)
 




More information about the Oval-commits mailing list