[Oval-commits] r38 - trunk/tools/oval/definition
Pavel Vinogradov
blaze-guest at alioth.debian.org
Sat Jun 9 16:35:44 UTC 2007
Author: blaze-guest
Date: 2007-06-09 16:35:44 +0000 (Sat, 09 Jun 2007)
New Revision: 38
Modified:
trunk/tools/oval/definition/generator.py
trunk/tools/oval/definition/generator.pyc
Log:
Use caching for DPKG tests
Modified: trunk/tools/oval/definition/generator.py
===================================================================
--- trunk/tools/oval/definition/generator.py 2007-06-09 15:51:30 UTC (rev 37)
+++ trunk/tools/oval/definition/generator.py 2007-06-09 16:35:44 UTC (rev 38)
@@ -34,8 +34,7 @@
objectsCurId = 1
statesCurId = 1
-archTests = {}
-releaseTests = {}
+testsHash = {"arch" : {}, "release": {}, "dpkgObj": {}, "dpkgSte": {}}
def __getNewId (type):
global testsCurId, objectsCurId, statesCurId
@@ -61,71 +60,48 @@
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",
+ if testsHash["dpkgObj"].has_key(name):
+ objectId = testsHash["dpkgObj"][name]
+ else:
+ objectId = __getNewId ("object");
+ object = __createXMLElement("dpkginfo_object",
+ attrs={"id":objectId, "version":"1",
"xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
- object.appendChild ( __createXMLElement ("name", name))
- objects.appendChild (object)
-
- 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"}))
- states.appendChild (state)
+ object.appendChild ( __createXMLElement ("name", name))
+ objects.appendChild (object)
- return (ref)
-
-def __createReleaseTest(version):
-
- global releaseTests
-
- if not releaseTests.has_key(version):
-
- ref = __getNewId("test")
+ testsHash["dpkgObj"][name] = objectId
- test = __createXMLElement("dpkginfo_test",
- 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}))
+ if testsHash["dpkgSte"].has_key(version):
+ stateId = testsHash["dpkgSte"][version]
+ else:
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"})
- object.appendChild ( __createXMLElement ("name", "debian_version"))
- objects.appendChild (object)
-
+
state = __createXMLElement("dpkginfo_state",
- attrs={"id":stateId, "version":"1",
- "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
+ attrs={"id":stateId, "version":"1",
+ "xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
state.appendChild ( __createXMLElement
- ("evr", version,
- {"datatype":"evr_string", "operation":"equals"}))
+ ("evr", version,
+ {"datatype":"evr_string", "operation":"less than"}))
states.appendChild (state)
+
+ testsHash["dpkgSte"][version] = stateId
- releaseTests[version] = ref
+ test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
- return (releaseTests[version])
+ test.appendChild ( __createXMLElement("state", attrs={"state_ref" : stateId}))
+ tests.appendChild(test)
-def __createArchTest(arch):
+ return (ref)
- global archTests
+def __createTest(testType, value):
- if not archTests.has_key(arch):
+ global testsHash
+
+ if not testsHash[testType].has_key(value):
- ref = __getNewId ("test")
+ ref = __getNewId("test")
+
test = __createXMLElement("dpkginfo_test",
attrs={"id":ref, "version":"1", "check":"all",
"xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
@@ -139,20 +115,23 @@
object = __createXMLElement("dpkginfo_object",
attrs={"id":objectId, "version":"1",
"xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
- object.appendChild ( __createXMLElement ("name", "architecture"))
+ if testType == "release":
+ object.appendChild ( __createXMLElement ("name", "debian_version"))
+ if testType == "arch":
+ object.appendChild ( __createXMLElement ("name", "architecture"))
objects.appendChild (object)
state = __createXMLElement("dpkginfo_state",
attrs={"id":stateId, "version":"1",
"xmlns":"http://oval.mitre.org/XMLSchema/oval-deinitions-5#linux"})
state.appendChild ( __createXMLElement
- ("evr", arch,
+ ("evr", value,
{"datatype":"evr_string", "operation":"equals"}))
states.appendChild (state)
- archTests[arch] = ref
+ testsHash[testType][value] = ref
- return (archTests[arch])
+ return (testsHash[testType][value])
def __createGeneratorHeader ():
"""
@@ -173,7 +152,7 @@
def createPlatformDefinition (version, data, dsa):
softwareCriteria = __createXMLElement ("criteria", attrs = {"comment" : "Release section", "operator" : "AND"})
- softwareCriteria.appendChild ( __createXMLElement ("criterion", attrs={"test_ref" : __createReleaseTest(version), "comment" : "Debian %s is installed" % version}))
+ softwareCriteria.appendChild ( __createXMLElement ("criterion", attrs={"test_ref" : __createTest("release", version), "comment" : "Debian %s is installed" % version}))
archCriteria = __createXMLElement ("criteria", attrs = {"comment" : "Architecture section", "operator" : "OR"})
@@ -181,7 +160,7 @@
if data.has_key ("all"):
archIndepCriteria = __createXMLElement ("criteria", attrs={"comment" : "Architecture independet section", "operation" : "AND"})
- archIndepCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createArchTest("all"), "comment" : "all architecture"}))
+ archIndepCriteria.appendChild ( __createXMLElement ("criterion", attrs = {"test_ref" : __createTest("arch", "all"), "comment" : "all architecture"}))
packageCriteria = __createXMLElement ("criteria", attrs={"comment" : "Packages section", "operation" : "OR"})
for pkg in data["all"].keys():
@@ -219,7 +198,7 @@
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" : __createArchTest(arch), "comment" : "%s architecture" % 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"})
@@ -237,7 +216,7 @@
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" : __createArchTest(key), "comment" : "%s architecture" % key}))
+ 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():
Modified: trunk/tools/oval/definition/generator.pyc
===================================================================
(Binary files differ)
More information about the Oval-commits
mailing list