[Oval-commits] r148 - trunk/oval-server
Pavel Vinogradov
blaze-guest at alioth.debian.org
Sun Aug 19 11:20:13 UTC 2007
Author: blaze-guest
Date: 2007-08-19 11:20:12 +0000 (Sun, 19 Aug 2007)
New Revision: 148
Modified:
trunk/oval-server/oval-server.cfg
trunk/oval-server/oval-server.py
Log:
Implement syncThread in oval-server
Modified: trunk/oval-server/oval-server.cfg
===================================================================
--- trunk/oval-server/oval-server.cfg 2007-08-18 19:44:09 UTC (rev 147)
+++ trunk/oval-server/oval-server.cfg 2007-08-19 11:20:12 UTC (rev 148)
@@ -1,6 +1,8 @@
[server]
-update_interval = 10
-lgo_file = "/tmp/oval.log"
+log_dir = /tmp
+log_file = oval-server.log
+log_level = INFO
+dsa_storage = /tmp/dsa
[agents]
agent_active = server, laptop
@@ -10,8 +12,9 @@
descr_laptop = laptop.home.nixdev.net
[source]
+type = local
name = "Local OVAL definitions source"
-prot = http
-addr = 192.168.17.1
+source = /home/blaze/opt/webwml/english/security
+update_interval = 10m
Modified: trunk/oval-server/oval-server.py
===================================================================
--- trunk/oval-server/oval-server.py 2007-08-18 19:44:09 UTC (rev 147)
+++ trunk/oval-server/oval-server.py 2007-08-19 11:20:12 UTC (rev 148)
@@ -1,38 +1,97 @@
from ConfigParser import SafeConfigParser
import os, logging
+import time
-#config - Global config object
-config = SafeConfigParser()
-logger = logging.getLogger()
+class syncThread:
+
+ __status = None
+
+ def __init__(self, config, logger):
+ self.type = config['type']
+ self.source = config['source']
+ self.storage = config['dsa_storage']
+ self.name = config['name']
+ self.update_interval = config['update_interval']
+ self.logger = logger
-def run(params):
- try:
- # Read global server config
- config.read("oval-server.cfg")
+ if self.type == 'local':
+ from dsaSync.directory import dirSync
+ self.syncer = dirSync(self.source, self.storage)
+ self.logger.info('Run local updater %s with: %s, %s' % (self.name, self.source, self.update_interval))
+
+ def startThread (self):
+ self.__status = 1
+ self.run ()
- try:
- logdirname = config.get('general', 'log_dir')
- logfilename = config.get('general', 'log_file')
- outfilename = os.path.join(logdirname, logfilename)
- except:
- outfilename = os.path.join ('/var/log', 'oval-server.log')
+ def stopThread (self):
+ self.__status = None
+
+ def run (self):
+ while 1:
+ self.logger.debug('Run local sync')
+ self.syncer.sync()
+ time.sleep(60*1)
- # Create the root handler (removing any others)
- hdlr = logging.FileHandler(outfilename, 'a')
- hdlr.setFormatter(logging.Formatter('%(asctime)s %(threadName)s %(name)s %(levelname)s %(message)s'))
- for h in logging.root.handlers:
- logging.root.removeHandler(h)
- logging.root.addHandler(hdlr)
- logging.root.setLevel(config['log_level'])
- logger.info('Logging begins')
+class mainThread:
- except IOError, e:
- logger.exception('error: %s', str(e))
+ config = SafeConfigParser()
+ logger = logging.getLogger()
+
+ def __init__(self, cfgfile):
+ try:
+ # Read global server config
+ self.config.read(cfgfile)
+ self.dsa_storage = self.config.get('server', 'dsa_storage')
+
+ try:
+ logdirname = self.config.get('server', 'log_dir')
+ logfilename = self.config.get('server', 'log_file')
+ self.outfilename = os.path.join(logdirname, logfilename)
+ except:
+ self.outfilename = os.path.join ('/tmp', 'oval-server.log')
+
+ # Create the root handler (removing any others)
+ hdlr = logging.FileHandler(self.outfilename, 'a')
+ hdlr.setFormatter(logging.Formatter('%(asctime)s %(threadName)s %(name)s %(levelname)s %(message)s'))
+ for h in logging.root.handlers:
+ logging.root.removeHandler(h)
+ logging.root.addHandler(hdlr)
+ logging.root.setLevel(logging.INFO) # config.get('server', 'log_level'))
+ self.logger.info('Logging begins')
+
+ except IOError, e:
+ self.logger.exception('error: %s', str(e))
+ logging.shutdown()
+ exit()
+
+ def __del__(self):
+ pass
+
+ def readConfigSection (self, section):
+ conf = {}
+
+ if self.config.has_section(section):
+ data = self.config.items(section)
+ for opts in data:
+ conf[opts[0]] = opts[1]
+
+ return conf
+
+ def run(self):
+ self.logger.info('mainThread.RUN')
+
+ #Create sync thread
+ conf = self.readConfigSection('source')
+ conf['dsa_storage'] = self.dsa_storage
+ syncer = syncThread(conf, self.logger)
+ syncer.startThread()
+
+ self.logger.info('Shutting down')
logging.shutdown()
- exit(2)
- logger.info('Shutting down')
- logging.shutdown()
+if __name__ == "__main__":
+ main = mainThread("oval-server.cfg")
+ main.run()
#
#if __name__ == "__main__":
# from dba import dba
More information about the Oval-commits
mailing list