[Oval-commits] r207 - trunk/oval-server
Pavel Vinogradov
blaze-guest at alioth.debian.org
Thu Aug 23 16:30:45 UTC 2007
Author: blaze-guest
Date: 2007-08-23 16:30:45 +0000 (Thu, 23 Aug 2007)
New Revision: 207
Added:
trunk/oval-server/dsa2oval.py
Removed:
trunk/oval-server/Dsa2Oval.py
Log:
Rename dsa2oval.py
Deleted: trunk/oval-server/Dsa2Oval.py
===================================================================
--- trunk/oval-server/Dsa2Oval.py 2007-08-23 16:28:40 UTC (rev 206)
+++ trunk/oval-server/Dsa2Oval.py 2007-08-23 16:30:45 UTC (rev 207)
@@ -1,136 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-# Extracts the data DSA files and creates OVAL queries to
-# be used with the OVAL query interpreter (see http://oval.mitre.org)
-#
-# (c) 2007 Pavel Vinogradov
-# (c) 2004 Javier Fernandez-Sanguino
-# Licensed under the GNU General Public License version 2.
-
-import os
-import sys
-import getopt
-import logging
-
-from dsa2oval.definition import generator
-from dsa2oval.parser import dsa
-from dsa2oval.parser import wml
-
-dsaref = {}
-
-def usage (prog = "parse-wml-oval.py"):
- """Print information about script flags and options"""
-
- print """
-usage: %s [vh] [-d <directory> | -f <path to file>]
-\t-d\twhich directory use for dsa definition search
-\t-f\twhich file use for dsa definition generation
-\t-v\tverbose mode
-\t-h\tthis help
- """ % prog
-
-def printdsas (dsaref):
- """ Generate and print OVAL Definitions for collected DSA information """
-
- ovalDefinitions = generator.createOVALDefinitions (dsaref)
- generator.printOVALDefinitions (ovalDefinitions)
-
-def parsedirs (directory, postfix, depth):
- """ Recursive search directory for DSA files contain postfix in their names.
-
- For this files called oval.parser.dsa.parseFile() for extracting DSA information.
- """
-
- if depth == 0:
- logging.log(logging.DEBUG, "Maximum depth reached at directory " + directory)
- return (0)
-
- for file in os.listdir (directory):
-
- path = "%s/%s" % (directory, file)
-
- logging.log (logging.DEBUG, "Checking %s (for %s at %s)" % (file, postfix, depth))
-
- if os.access(path, os.R_OK) and os.path.isdir (path) and not os.path.islink (path) and file[0] != '.':
- logging.log(logging.DEBUG, "Entering directory " + path)
- parsedirs (path, postfix, depth-1)
-
- #Parse DSA data files
- if os.access(path, os.R_OK) and file.endswith(postfix) and file[0] != '.' and file[0] != '#':
- result = dsa.parseFile (path)
- if result:
- if dsaref.has_key (result[0]):
- for (k, v) in result[1].iteritems():
- dsaref[result[0]][k] = v
- else:
- dsaref[result[0]] = result[1]
-
- #Parse DSA wml descriptions
- if os.access(path, os.R_OK) and file.endswith(".wml") and file[0] != '.' and file[0] != '#':
- result = wml.parseFile(path)
- if result:
- if dsaref.has_key (result[0]):
- for (k, v) in result[1].iteritems():
- dsaref[result[0]][k] = v
- else:
- dsaref[result[0]] = result[1]
-
- return 0
-
-def parsefile (filename):
-
- datafile = filename
- (path, ext) = os.path.splitext(datafile)
- wmlfile = '.'.join((path, 'wml'))
-
- #Parse data file
- result = dsa.parseFile (datafile)
- if result:
- if dsaref.has_key (result[0]):
- for (k, v) in result[1].iteritems():
- dsaref[result[0]][k] = v
- else:
- dsaref[result[0]] = result[1]
-
- #Parse wml file
- result = wml.parseFile(wmlfile)
- if result:
- if dsaref.has_key (result[0]):
- for (k, v) in result[1].iteritems():
- dsaref[result[0]][k] = v
- else:
- dsaref[result[0]] = result[1]
-
- return generator.createOVALDefinitions(dsaref)
-
-if __name__ == "__main__":
-
- # Parse cmd options with getopt
- opts = {}
-
- #By default we search dsa definitions from current directory, but -d option override this
- opts['-d'] = "./"
-
- try:
- opt, args = getopt.getopt (sys.argv[1:], 'vhd:f:')
- except getopt.GetoptError:
- usage ()
- sys.exit(1)
-
- for key, value in opt:
- opts[key] = value
-
- if opts.has_key ('-h'):
- usage()
- sys.exit(0)
-
- if opts.has_key('-v'):
- logging.basicConfig(level=logging.WARNING)
- else:
- logging.basicConfig(level=logging.ERROR)
-
- if opts.has_key('-d'):
- parsedirs (opts['-d'], '.data', 2)
- if opts.has_key('-f'):
- parsefile (opts['-f'])
- printdsas(dsaref)
\ No newline at end of file
Copied: trunk/oval-server/dsa2oval.py (from rev 202, trunk/oval-server/Dsa2Oval.py)
===================================================================
--- trunk/oval-server/dsa2oval.py (rev 0)
+++ trunk/oval-server/dsa2oval.py 2007-08-23 16:30:45 UTC (rev 207)
@@ -0,0 +1,136 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Extracts the data DSA files and creates OVAL queries to
+# be used with the OVAL query interpreter (see http://oval.mitre.org)
+#
+# (c) 2007 Pavel Vinogradov
+# (c) 2004 Javier Fernandez-Sanguino
+# Licensed under the GNU General Public License version 2.
+
+import os
+import sys
+import getopt
+import logging
+
+from dsa2oval.definition import generator
+from dsa2oval.parser import dsa
+from dsa2oval.parser import wml
+
+dsaref = {}
+
+def usage (prog = "parse-wml-oval.py"):
+ """Print information about script flags and options"""
+
+ print """
+usage: %s [vh] [-d <directory> | -f <path to file>]
+\t-d\twhich directory use for dsa definition search
+\t-f\twhich file use for dsa definition generation
+\t-v\tverbose mode
+\t-h\tthis help
+ """ % prog
+
+def printdsas (dsaref):
+ """ Generate and print OVAL Definitions for collected DSA information """
+
+ ovalDefinitions = generator.createOVALDefinitions (dsaref)
+ generator.printOVALDefinitions (ovalDefinitions)
+
+def parsedirs (directory, postfix, depth):
+ """ Recursive search directory for DSA files contain postfix in their names.
+
+ For this files called oval.parser.dsa.parseFile() for extracting DSA information.
+ """
+
+ if depth == 0:
+ logging.log(logging.DEBUG, "Maximum depth reached at directory " + directory)
+ return (0)
+
+ for file in os.listdir (directory):
+
+ path = "%s/%s" % (directory, file)
+
+ logging.log (logging.DEBUG, "Checking %s (for %s at %s)" % (file, postfix, depth))
+
+ if os.access(path, os.R_OK) and os.path.isdir (path) and not os.path.islink (path) and file[0] != '.':
+ logging.log(logging.DEBUG, "Entering directory " + path)
+ parsedirs (path, postfix, depth-1)
+
+ #Parse DSA data files
+ if os.access(path, os.R_OK) and file.endswith(postfix) and file[0] != '.' and file[0] != '#':
+ result = dsa.parseFile (path)
+ if result:
+ if dsaref.has_key (result[0]):
+ for (k, v) in result[1].iteritems():
+ dsaref[result[0]][k] = v
+ else:
+ dsaref[result[0]] = result[1]
+
+ #Parse DSA wml descriptions
+ if os.access(path, os.R_OK) and file.endswith(".wml") and file[0] != '.' and file[0] != '#':
+ result = wml.parseFile(path)
+ if result:
+ if dsaref.has_key (result[0]):
+ for (k, v) in result[1].iteritems():
+ dsaref[result[0]][k] = v
+ else:
+ dsaref[result[0]] = result[1]
+
+ return 0
+
+def parsefile (filename):
+
+ datafile = filename
+ (path, ext) = os.path.splitext(datafile)
+ wmlfile = '.'.join((path, 'wml'))
+
+ #Parse data file
+ result = dsa.parseFile (datafile)
+ if result:
+ if dsaref.has_key (result[0]):
+ for (k, v) in result[1].iteritems():
+ dsaref[result[0]][k] = v
+ else:
+ dsaref[result[0]] = result[1]
+
+ #Parse wml file
+ result = wml.parseFile(wmlfile)
+ if result:
+ if dsaref.has_key (result[0]):
+ for (k, v) in result[1].iteritems():
+ dsaref[result[0]][k] = v
+ else:
+ dsaref[result[0]] = result[1]
+
+ return generator.createOVALDefinitions(dsaref)
+
+if __name__ == "__main__":
+
+ # Parse cmd options with getopt
+ opts = {}
+
+ #By default we search dsa definitions from current directory, but -d option override this
+ opts['-d'] = "./"
+
+ try:
+ opt, args = getopt.getopt (sys.argv[1:], 'vhd:f:')
+ except getopt.GetoptError:
+ usage ()
+ sys.exit(1)
+
+ for key, value in opt:
+ opts[key] = value
+
+ if opts.has_key ('-h'):
+ usage()
+ sys.exit(0)
+
+ if opts.has_key('-v'):
+ logging.basicConfig(level=logging.WARNING)
+ else:
+ logging.basicConfig(level=logging.ERROR)
+
+ if opts.has_key('-d'):
+ parsedirs (opts['-d'], '.data', 2)
+ if opts.has_key('-f'):
+ parsefile (opts['-f'])
+ printdsas(dsaref)
\ No newline at end of file
More information about the Oval-commits
mailing list