[Oval-commits] r191 - trunk/oval-server
Pavel Vinogradov
blaze-guest at alioth.debian.org
Thu Aug 23 09:45:18 UTC 2007
Author: blaze-guest
Date: 2007-08-23 09:45:18 +0000 (Thu, 23 Aug 2007)
New Revision: 191
Modified:
trunk/oval-server/oval-server.py
Log:
Implement command line parse
Modified: trunk/oval-server/oval-server.py
===================================================================
--- trunk/oval-server/oval-server.py 2007-08-23 02:25:51 UTC (rev 190)
+++ trunk/oval-server/oval-server.py 2007-08-23 09:45:18 UTC (rev 191)
@@ -2,12 +2,24 @@
from threading import Thread
from dsa2oval import convertor
from dba.dba import dba
-import os, logging
-import time
+import os, logging, sys, time, getopt
class OvalServerNotSupported(Exception):
pass
+class configNotFoundError (Exception):
+ pass
+
+logLevels = {'CRITICAL' : 50, 'ERROR' : 40, 'WARNING' : 30, 'INFO' : 20, 'DEBUG' : 10, 'NOTSET' : 0}
+
+def usage (prog = 'oval-server.py'):
+ """Print information about script flags and options"""
+
+ print """usage: python %s [-h] [-c <config>]
+\t-h\tthis help
+\t-c\tpath to config file (by default oval-server.cfg""" % prog
+
+
class httpThread(Thread):
__status = None
@@ -160,5 +172,31 @@
logging.shutdown()
if __name__ == "__main__":
- main = mainThread("oval-server.cfg")
- main.run()
\ No newline at end of file
+ #Parse command line options.
+ #By default we search for config file in current directory
+ opts = {'-c' : 'oval-server.cfg'}
+
+ try:
+ opt, args = getopt.getopt (sys.argv[1:], 'hc:')
+ except getopt.GetoptError:
+ usage (sys.argv[0])
+ sys.exit(1)
+
+ for key, value in opt:
+ opts[key] = value
+
+ if opts.has_key ('-h'):
+ usage(sys.argv[0])
+ sys.exit(0)
+
+ #Crate agent instance and run it
+ try:
+ main = mainThread(opts['-c'])
+ main.run ()
+ except configNotFoundError, e:
+ sys.stderr.write (str(e))
+ except KeyboardInterrupt, e:
+ sys.stderr.write ('Execution interrupted by keyboard.')
+ except Exception, e:
+ sys.stderr.write('Unhandled error during execution: %s : %s.' % (e.__class__, str(e)))
+ traceback.print_exc()
\ No newline at end of file
More information about the Oval-commits
mailing list