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

Pavel Vinogradov blaze-guest at alioth.debian.org
Fri Jun 15 06:33:15 UTC 2007


Author: blaze-guest
Date: 2007-06-15 06:33:15 +0000 (Fri, 15 Jun 2007)
New Revision: 49

Modified:
   trunk/tools/oval/definition/generator.py
Log:
New experimental algorithm of architectures handling

Modified: trunk/tools/oval/definition/generator.py
===================================================================
--- trunk/tools/oval/definition/generator.py	2007-06-13 18:31:19 UTC (rev 48)
+++ trunk/tools/oval/definition/generator.py	2007-06-15 06:33:15 UTC (rev 49)
@@ -25,6 +25,50 @@
 	
 	return (element)
 
+eq = {}
+eq_arch = []
+di = {}	
+
+def __dictAdd (dic, pkey, key, value):
+	if dic.has_key (pkey):
+		dic[pkey][key] = value
+	else:
+		dic[pkey] = {key : value}
+		
+def __dictDiff (arch, packages):
+	
+	global eq, di, eq_arch
+		
+	if len(eq) == 0:
+		eq = packages
+		eq_arch = [arch, ]
+		return (0)
+	else:
+		p_keys = packages.keys()
+		eq_keys = eq.keys()
+		
+		for p in p_keys:
+			if p in eq_keys:
+				if packages[p] != eq[p]:
+					__dictAdd(di, arch, p, packages[p])
+					for ar in eq_arch:
+						__dictAdd (di, ar, p, eq[p])
+					del (eq[p])
+			else:
+				__dictAdd (di, arch, p, packages[p])
+		
+		for p in eq_keys:
+			if p in p_keys:
+				pass
+			else:
+				for ar in eq_arch:
+					__dictAdd (di, ar, p, eq[p])
+				del (eq[p])
+				
+		if len(eq):
+			eq_arch.append(arch)
+		return (0)
+					
 namespace = "oval:org.debian.oval"
 tests = __createXMLElement ("tests")
 objects = __createXMLElement ("objects")
@@ -155,65 +199,113 @@
 		archIndepCriteria.appendChild (packageCriteria)
 	
 		archCriteria.appendChild (archIndepCriteria)
-	 	
-	# We must check that bpackages for all supported architectures is qeuals
-	stdPkg = None
-	stdArch = ""
-	diffCount = -1
-	for (key, value) in data.iteritems():
-		if key != "all":
-			if stdPkg == None:
-				stdPkg = value
-				stdArch = key
-				diffCount = 0
-			else:
-				if stdPkg != value:
-					diffCount += 1
-					logging.log(logging.ERROR, "Bpackages differ [" + str(diffCount) + "] in " + dsa + "[" + version + "] for " + stdArch + " and " + key)
-					if diffCount == 1:
-						logging.log(logging.INFO, stdPkg)
-						logging.log(logging.INFO, value)
-	
-	# Now, since we have multiple architectures.. go into loop
-	# Notice: this code is assuming all the architectures are using the same binary package versions which migth not necessarily be true..
 
-
-	if diffCount == 0:
-		# All supported architectures have queuals bpackages
+	for i in range(2):
+		global eq, eq_arch, di
 		
-		archDependCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture depended section", "operation" : "AND"})
+		eq = {}
+		eq_arch = []
+		if i == 0:
+			dt  =data
+		else:
+			dt = di
+		di = {}	
+	
+		for (key, value) in dt.iteritems():
+			if key != "all":
+				__dictDiff (key, value)
+	
+		archDependCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture depended section", "operation" : "AND"})	
 		supportedArchCriteria = __createXMLElement ("criteria", attrs={"comment" : "Supported architectures section", "operation" : "OR"})
-		for arch in data.keys():
-			if arch != "all":
-				supportedArchCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", arch), "comment" : "%s architecture" % arch}))
-				archDependCriteria.appendChild (supportedArchCriteria)
-
+		for arch in eq_arch:
+			supportedArchCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", arch), "comment" : "%s architecture" % arch}))
+			archDependCriteria.appendChild (supportedArchCriteria)
+	
 		packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operation" : "OR"})
-	
-		for bpkg in data[stdArch].keys():
-			packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(bpkg, data[stdArch][bpkg]), "comment" : "%s DPKG is earlier than %s" % (bpkg, data[stdArch][bpkg])}))
-				
+		
+		for bpkg in eq.keys():
+			packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(bpkg, eq[bpkg]), "comment" : "%s DPKG is earlier than %s" % (bpkg, eq[bpkg])}))
+					
 		archDependCriteria.appendChild (packageCriteria)
 		archCriteria.appendChild (archDependCriteria)
-		
-	if diffCount > 0:
-		# Supported architectures have different bpackages. On this stage we generate package list for each architecture
+	
+	#Supported architectures have different bpackages. On this stage we generate package list for each architecture
+	if len(di):
 		archDependCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture depended section", "operation" : "OR"})
+			
+		for (key, value) in di.iteritems():
+			supportedPlatformCriteria = __createXMLElement ("criteria", attrs={"comment" : "Supported platform section", "operation" : "AND"})
+			supportedPlatformCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", key), "comment" : "%s architecture" % key}))
+			packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operation" : "OR"})
+					
+			for bpkg in di[key].keys():
+				packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(bpkg, di[key][bpkg]), "comment" : "%s DPKG is earlier than %s" % (bpkg, di[key][bpkg])}))
+			supportedPlatformCriteria.appendChild (packageCriteria)
+			archDependCriteria.appendChild (supportedPlatformCriteria)
+					
+		archCriteria.appendChild (archDependCriteria)
 		
-		for (key, value) in data.iteritems():
-			if key != "all":
-				supportedPlatformCriteria = __createXMLElement ("criteria", attrs={"comment" : "Supported platform section", "operation" : "AND"})
-				supportedPlatformCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", key), "comment" : "%s architecture" % key}))
-				packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operation" : "OR"})
-				
-				for bpkg in data[key].keys():
-					packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(bpkg, data[key][bpkg]), "comment" : "%s DPKG is earlier than %s" % (bpkg, data[key][bpkg])}))
-				supportedPlatformCriteria.appendChild (packageCriteria)
-				archDependCriteria.appendChild (supportedPlatformCriteria)
-				
-		archCriteria.appendChild (archDependCriteria)
+		 
+#	# We must check that bpackages for all supported architectures is qeuals
+#	stdPkg = None
+#	stdArch = ""
+#	diffCount = -1
+#	for (key, value) in data.iteritems():
+#		if key != "all":
+#			if stdPkg == None:
+#				stdPkg = value
+#				stdArch = key
+#				diffCount = 0
+#			else:
+#				if stdPkg != value:
+#					diffCount += 1
+#					logging.log(logging.ERROR, "Bpackages differ [" + str(diffCount) + "] in " + dsa + "[" + version + "] for " + stdArch + " and " + key + "\n\n")
+#					logging.log(logging.ERROR, stdPkg)
+#					logging.log(logging.ERROR, value)
+#					if diffCount == 1:
+#						logging.log(logging.INFO, stdPkg)
+#						logging.log(logging.INFO, value)
+#	
+#	# Now, since we have multiple architectures.. go into loop
+#	# Notice: this code is assuming all the architectures are using the same binary package versions which migth not necessarily be true..
+#
+#
+#	if diffCount == 0:
+#		# All supported architectures have queuals bpackages
+#		
+#		archDependCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture depended section", "operation" : "AND"})
+#		supportedArchCriteria = __createXMLElement ("criteria", attrs={"comment" : "Supported architectures section", "operation" : "OR"})
+#		for arch in data.keys():
+#			if arch != "all":
+#				supportedArchCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", arch), "comment" : "%s architecture" % arch}))
+#				archDependCriteria.appendChild (supportedArchCriteria)
+#
+#		packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operation" : "OR"})
+#	
+#		for bpkg in data[stdArch].keys():
+#			packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(bpkg, data[stdArch][bpkg]), "comment" : "%s DPKG is earlier than %s" % (bpkg, data[stdArch][bpkg])}))
+#				
+#		archDependCriteria.appendChild (packageCriteria)
+#		archCriteria.appendChild (archDependCriteria)
+#		
+#	if diffCount > 0:
+#		# Supported architectures have different bpackages. On this stage we generate package list for each architecture
+#		archDependCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture depended section", "operation" : "OR"})
+#		
+#		for (key, value) in data.iteritems():
+#			if key != "all":
+#				supportedPlatformCriteria = __createXMLElement ("criteria", attrs={"comment" : "Supported platform section", "operation" : "AND"})
+#				supportedPlatformCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", key), "comment" : "%s architecture" % key}))
+#				packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operation" : "OR"})
+#				
+#				for bpkg in data[key].keys():
+#					packageCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createDPKGTest(bpkg, data[key][bpkg]), "comment" : "%s DPKG is earlier than %s" % (bpkg, data[key][bpkg])}))
+#				supportedPlatformCriteria.appendChild (packageCriteria)
+#				archDependCriteria.appendChild (supportedPlatformCriteria)
+#				
+#		archCriteria.appendChild (archDependCriteria)
 	
-	softwareCriteria.appendChild (archCriteria)
+	softwareCriteria.appendChild (archCriteria)	
 	
 	return (softwareCriteria)
 




More information about the Oval-commits mailing list