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

Pavel Vinogradov blaze-guest at alioth.debian.org
Sat Jun 9 17:20:45 UTC 2007


Author: blaze-guest
Date: 2007-06-09 17:20:45 +0000 (Sat, 09 Jun 2007)
New Revision: 39

Modified:
   trunk/tools/oval/definition/generator.py
   trunk/tools/oval/definition/generator.pyc
Log:
Start refactoring of OVAL test generation

Modified: trunk/tools/oval/definition/generator.py
===================================================================
--- trunk/tools/oval/definition/generator.py	2007-06-09 16:35:44 UTC (rev 38)
+++ trunk/tools/oval/definition/generator.py	2007-06-09 17:20:45 UTC (rev 39)
@@ -52,17 +52,10 @@
 		statesCurId += 1
 	
 	return (result)
+
+def __createOVALObject (name):
 	
-def __createDPKGTest(name, version):
-	
-	ref = __getNewId ("test")
-	test = __createXMLElement("dpkginfo_test", 
-							  attrs={"id":ref, "version":"1", "check":"all",
-									 "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
-	
-	if testsHash["dpkgObj"].has_key(name):
-		objectId = testsHash["dpkgObj"][name]
-	else:
+	if not testsHash["dpkgObj"].has_key(name):
 		objectId = __getNewId ("object");
 		object = __createXMLElement("dpkginfo_object",
 								    attrs={"id":objectId, "version":"1",
@@ -71,33 +64,41 @@
 		objects.appendChild (object)
 
 		testsHash["dpkgObj"][name] = objectId
-		
-	if testsHash["dpkgSte"].has_key(version):
-		stateId = testsHash["dpkgSte"][version]
-	else:
+	
+	return (testsHash["dpkgObj"][name])
+
+def __createOVALState (value, operation = "less than"):
+
+	if not testsHash["dpkgSte"].has_key(operation) or not testsHash["dpkgSte"][operation].has_key(value):
 		stateId = __getNewId ("state")
 
 		state = __createXMLElement("dpkginfo_state", 
 								attrs={"id":stateId, "version":"1",
 									 "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
 		state.appendChild ( __createXMLElement 
-						 			("evr", version, 
-						  			{"datatype":"evr_string", "operation":"less than"}))
+						 			("evr", value, 
+						  			{"datatype":"evr_string", "operation":operation}))
 		states.appendChild (state)
 	
-		testsHash["dpkgSte"][version] = stateId
+		testsHash["dpkgSte"][operation] = {value : stateId}
 		
-	test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
+	return (testsHash["dpkgSte"][operation][value])
+
+def __createDPKGTest(name, version):
 	
-	test.appendChild ( __createXMLElement("state", attrs={"state_ref" : stateId}))
+	ref = __getNewId ("test")
+	test = __createXMLElement("dpkginfo_test", 
+							  attrs={"id":ref, "version":"1", "check":"all",
+									 "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
+				
+	test.appendChild ( __createXMLElement("object", attrs={"object_ref" : __createOVALObject (name)}))
+	test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALState (version)}))
 	tests.appendChild(test)
 
 	return (ref)
 
 def __createTest(testType, value):
 	
-	global testsHash
-	
 	if not testsHash[testType].has_key(value):
 
 		ref = __getNewId("test")
@@ -106,29 +107,15 @@
 								  attrs={"id":ref, "version":"1", "check":"all",
 										 "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
 		
-		objectId = __getNewId ("object");
-		test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
-		stateId = __getNewId ("state")
-		test.appendChild ( __createXMLElement("state", attrs={"state_ref" : stateId}))
-		tests.appendChild(test)
-		
-		object = __createXMLElement("dpkginfo_object", 
-								  attrs={"id":objectId, "version":"1",
-										 "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
 		if testType == "release":
-			object.appendChild ( __createXMLElement ("name", "debian_version"))
-		if testType == "arch":
-			object.appendChild ( __createXMLElement ("name", "architecture"))
-		objects.appendChild (object)
+			objectId = __createOVALObject ("debian_version")
+		else:
+			objectId = __createOVALObject ("architecture")
 		
-		state = __createXMLElement("dpkginfo_state", 
-								  attrs={"id":stateId, "version":"1",
-										 "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
-		state.appendChild ( __createXMLElement 
-							 ("evr", value, 
-							  {"datatype":"evr_string", "operation":"equals"}))
-		states.appendChild (state)
-		
+		test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
+		test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALState (value, "equals")}))
+		tests.appendChild(test)
+				
 		testsHash[testType][value] = ref
 	
 	return (testsHash[testType][value])
@@ -313,9 +300,7 @@
 	root.appendChild(tests)
 	root.appendChild(objects)
 	root.appendChild(states)
-	
-	
-	
+
 	return doc
 
 def printOVALDefinitions (doc):

Modified: trunk/tools/oval/definition/generator.pyc
===================================================================
(Binary files differ)




More information about the Oval-commits mailing list