[Oval-commits] r89 - in trunk/tools/oval: definition parser
Pavel Vinogradov
blaze-guest at alioth.debian.org
Tue Jul 17 11:12:19 UTC 2007
Author: blaze-guest
Date: 2007-07-17 11:12:18 +0000 (Tue, 17 Jul 2007)
New Revision: 89
Modified:
trunk/tools/oval/definition/differ.py
trunk/tools/oval/definition/generator.py
trunk/tools/oval/parser/dsa.py
Log:
Code refactoring. Better error cheching.
Modified: trunk/tools/oval/definition/differ.py
===================================================================
--- trunk/tools/oval/definition/differ.py 2007-07-17 10:34:39 UTC (rev 88)
+++ trunk/tools/oval/definition/differ.py 2007-07-17 11:12:18 UTC (rev 89)
@@ -38,7 +38,7 @@
def compareElement (self, architecture, packages):
#We already inspected this arch
if architecture in self.__equalArch:
- logging.log(logging.WARNING, "Architecture " + architecture + "already inspected")
+ logging.log(logging.DEBUG, "Architecture " + architecture + "already inspected")
return (0)
#We don't have inspected base
@@ -72,6 +72,6 @@
self.__equal = equalC
self.__differ = differC
else:
- logging.log(logging.WARNING, "Architecture " + architecture + " too differens")
+ logging.log(logging.DEBUG, "Architecture " + architecture + " too differens")
self.__differ[architecture] = packages
return (1)
Modified: trunk/tools/oval/definition/generator.py
===================================================================
--- trunk/tools/oval/definition/generator.py 2007-07-17 10:34:39 UTC (rev 88)
+++ trunk/tools/oval/definition/generator.py 2007-07-17 11:12:18 UTC (rev 89)
@@ -12,10 +12,12 @@
import datetime
import xml.dom.ext
import xml.dom.minidom
-import sys
from oval.definition.differ import differ
-class DSAFormatException (Exception):
+class OvalGeneratorException (Exception):
+ pass
+
+class DSAFormatException (OvalGeneratorException):
code = 1
def __createXMLElement (name, descr = None, attrs = {}):
@@ -107,7 +109,7 @@
Use state hash for optimization of resulted XML
"""
-
+ #TODO: Add arch state generation
if not testsHash["dpkgSte"].has_key(operation) or not testsHash["dpkgSte"][operation].has_key(value):
stateId = __getNewId ("state")
@@ -296,8 +298,16 @@
"""
doc = xml.dom.minidom.Document ()
+ if not dsaref.has_key("release"):
+ logging.log(logging.WARNING, "DSA %s: Release definition not well formatted. Ignore this DSA." % dsa)
+ raise DSAFormatException
+
+ if not dsaref.has_key("description"):
+ logging.log(logging.WARNING, "DSA %s: Description information missed. Ignore this DSA." % dsa)
+ raise DSAFormatException
+
if not dsaref.has_key("packages"):
- logging.log(logging.WARNING, "Release definition not well formatted")
+ logging.log(logging.WARNING, "DSA %s: Package information missed. Ignore this DSA." % dsa)
raise DSAFormatException
### Definition block: Metadata, Notes, Criteria
@@ -310,13 +320,9 @@
### Definition : Metadata : Affected : platform, product ###
affected = __createXMLElement ("affected", attrs = {"family" : "unix"})
- try:
- for platform in dsaref["packages"]:
- affected.appendChild ( __createXMLElement ("platform", "Debian GNU/Linux %s" % platform))
- affected.appendChild ( __createXMLElement ("product", dsaref.get("package")))
- except:
- logging.log (logging.WARNING, "packages None in DSA " + dsa)
- raise DSAFormatException
+ for platform in dsaref["release"]:
+ affected.appendChild ( __createXMLElement ("platform", "Debian GNU/Linux %s" % platform))
+ affected.appendChild ( __createXMLElement ("product", dsaref.get("packages")))
metadata.appendChild (affected)
### Definition : Metadata : Affected : END ###
@@ -345,12 +351,9 @@
### Definition : Criteria ###
platformCriteria = __createXMLElement ("criteria", attrs = {"comment" : "Platform section", "operator" : "OR"})
- if dsaref.has_key("packages"):
- for platform in dsaref["packages"]:
- data = dsaref["packages"][platform]
- platformCriteria.appendChild (createPlatformDefinition(platform, data, dsa))
- else:
- logging.log(logging.WARNING, "packages None in DSA " + dsa)
+ for platform in dsaref["release"]:
+ data = dsaref["release"][platform]
+ platformCriteria.appendChild (createPlatformDefinition(platform, data, dsa))
definition.appendChild (platformCriteria)
### Definition : Criteria END ###
@@ -389,7 +392,7 @@
try:
definitions.appendChild (createDefinition(dsa, dsaref[dsa]))
except DSAFormatException:
- logging.log (logging.WARNING, "DSA %s format not proper parsable" % dsa)
+ logging.log (logging.WARNING, "DSA %s: Bad data file. Ignore this DSA." % dsa)
root.appendChild (definitions)
Modified: trunk/tools/oval/parser/dsa.py
===================================================================
--- trunk/tools/oval/parser/dsa.py 2007-07-17 10:34:39 UTC (rev 88)
+++ trunk/tools/oval/parser/dsa.py 2007-07-17 11:12:18 UTC (rev 89)
@@ -68,7 +68,7 @@
pakpatern = re.compile (r'packages>(.*?)</define-tag>')
result = pakpatern.search (line)
if result:
- data["package"] = result.groups()[0]
+ data["packages"] = result.groups()[0]
vulpatern = re.compile (r'isvulnerable>(.*?)</define-tag>')
result = vulpatern.search (line)
@@ -85,31 +85,26 @@
if result:
deb_ver = result.groups()[0]
- if data.has_key("packages"):
- if data["packages"].has_key(deb_ver):
+ if data.has_key("release"):
+ if data["release"].has_key(deb_ver):
logging.log(logging.WARNING, "DSA %s contain second files section for release %s" % (dsa, deb_ver))
else:
- data["packages"][deb_ver] = {}
+ data["release"][deb_ver] = {}
else:
- data["packages"] = {deb_ver: {}}
+ data["release"] = {deb_ver: {}}
# Binary packages are pushed into array
# Those are prepended by fileurls
# TODO: Packages do _NOT_ include epochs
# (that should be fixed)
- if data.has_key("package") and deb_ver:
- #urlpatern = re.compile (r'fileurl [\w:/.]+/([^/]*?)\.deb[ >]')
+ if data.has_key("release") and deb_ver:
urlpatern = re.compile (r'fileurl [\w:/.\-+]+/([\w\-.+~]+)\.deb[^i]')
result = urlpatern.search (line)
if result:
(package, version, architecture) = result.groups()[0].split("_")
- if data["packages"][deb_ver].has_key(architecture):
-# if data["packages"][deb_ver][architecture].has_key(package):
-# if not version in data["packages"][deb_ver][architecture][package]:
-# data["packages"][deb_ver][architecture][package].append(version)
-# else:
- data["packages"][deb_ver][architecture][package] = version
+ if data["release"][deb_ver].has_key(architecture):
+ data["release"][deb_ver][architecture][package] = version
else:
- data["packages"][deb_ver][architecture] = {package : version}
+ data["release"][deb_ver][architecture] = {package : version}
return (dsa, data)
More information about the Oval-commits
mailing list