Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r198 - branches/stateengine/src

Project highlights: Stable Version: 1.6.1, Development Version: 1.7.6

current
Discussion topic

Back to topic list

svn commit: r198 - branches/stateengine/src

Reply

Author jjneely
Full name Jack Neely
Date 2005-09-05 13:45:22 PDT
Message Author: jjneely
Date: Mon Sep 5 13:45:22 2005
New Revision: 198

Added:
   branches/stateengine​/src/config.py
Modified:
   branches/stateengine​/src/hostconfig.py
   branches/stateengine​/src/hosts.py
   branches/stateengine​/src/se.conf
Log:
This brings in some classes for managing the server and client
configration. (Where the database lives, etc.)

This also starts work on a class to manage all the hosts that we have some
state information for. (Right now they are known as 'configs'.) Its quite
slow because the the SHA1 bussiness. Need to rework.


Added: branches/stateengine​/src/config.py
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/config.​py?view=auto&rev​=198
====================​====================​====================​==================
--- (empty file)
+++ branches/stateengine​/src/config.py Mon Sep 5 13:45:22 2005
@@ -0,0 +1,27 @@
+import ConfigParser
+
+class Configuration(object):
+
+ type = ""
+
+ def __init__(self):
+ self.cfg = ConfigParser.ConfigParser()
+ files = self.cfg.read(['/etc/se.conf', 'se.conf'])
+
+ if files == None:
+ raise Exception("Configuration file not found.")
+
+ def get(self, key):
+ return self.cfg.get(self.type, key)
+
+
+class Server(Configuration):
+
+ type = "server"
+
+ def DBFile(self):
+ return self.get("db")
+
+ def ConfigDir(self):
+ return self.get("configs")
+

Modified: branches/stateengine​/src/hostconfig.py
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/hostcon​fig.py?view=diff​&rev=198&p1=bran​ches/stateengine/src​/hostconfig.py&r​1=197&p2=branche​s/stateengine/src/ho​stconfig.py&r2=1​98
====================​====================​====================​==================
--- branches/stateengine​/src/hostconfig.py (original)
+++ branches/stateengine​/src/hostconfig.py Mon Sep 5 13:45:22 2005
@@ -1,6 +1,57 @@
+import os
 import os.path
+import sha
+import config
 from pyparsing import *
 
+
+class HostDict(dict):
+
+ def __init__(self):
+ self.conf = config.Server()
+ dict.__init__(self)
+
+ def _getFilesAndDirs(self, path):
+ # Helper function for filesystem recurstion
+
+ dirs = []
+ files = []
+
+ if not os.path.isabs(path):
+ path = os.path.abspath(path)
+
+ dir = os.listdir(path)
+ for node in dir:
+ apath = os.path.join(path, node)
+ if os.path.isdir(apath):
+ dirs.append(apath)
+ elif os.path.isfile(apath):
+ files.append(apath)
+
+ return files, dirs
+
+ def load(self, dir=None):
+ if dir == None:
+ dir = self.conf.ConfigDir()
+
+ files, dirs = self._getFilesAndDirs(dir)
+
+ for file in files:
+ h = HostConfig(file)
+ fd = open(file)
+ sum = sha.new(fd.read())
+ fd.close()
+
+ key = os.path.basename(file)
+ if self.has_key(key):
+ print "Multiple Config files for %s" % key
+ else:
+ self[os.path.basename(file)] = (h, sum.hexdigest())
+
+ for dir in dirs:
+ self.load(dir)
+
+
 # Class to hold state information from host config
 class HostConfig(object):
 
@@ -18,21 +69,17 @@
     stateConfig.validate()
     stateConfig.ignore("#" + restOfLine)
 
- def __init__(self, hostname=None, basepath=None):
+ def __init__(self, path):
         # Get hostconfig for hostname
         self._stateArgs = {}
         self._stateKWs = {}
- if basepath:
- self._basepath = basepath
- else:
- self._basepath = ""
+ self._path = path
 
- if hostname:
- self.readConfig(hostname)
+ self.readConfig()
         
 
- def readConfig(self, hostname):
- fd = self._getConfigFile(hostname)
+ def readConfig(self):
+ fd = self._getConfigFile()
 
         for line in fd.readlines():
             try:
@@ -53,10 +100,10 @@
 
             self.addConfig(parse[0], args, tuples)
 
- def _getConfigFile(self, hostname):
- # return an open file of the config for hostname
+ def _getConfigFile(self):
+ # return an open file of the config
 
- fd = open(os.path.join(se​lf._basepath, hostname))
+ fd = open(self._path)
         return fd
         
     def addConfig(self, stateKey, args, kwtuples):

Modified: branches/stateengine​/src/hosts.py
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/hosts.p​y?view=diff&rev=​198&p1=branches/​stateengine/src/host​s.py&r1=197&​p2=branches/stateeng​ine/src/hosts.py​&r2=198
====================​====================​====================​==================
--- branches/stateengine​/src/hosts.py (original)
+++ branches/stateengine​/src/hosts.py Mon Sep 5 13:45:22 2005
@@ -1,21 +1,15 @@
 import pickle
-import ConfigParser
+import config
 import sqlite
 from db import DB
 
-cfg = ConfigParser.ConfigParser()
-files = cfg.read(['/etc/se.conf', 'se.conf'])
-if files == None:
- raise Exception("Configuration file not found.")
-del files
-
-db = DB(cfg.get("main", "db"))
-
+conf = config.Server()
 
 class Hosts(object):
 
     def __init__(self):
- self.c = db.getCursor()
+ self.db = DB(conf.DBFile())
+ self.c = self.db.getCursor()
         self._iter = None
         
 
@@ -54,7 +48,7 @@
     def next(self):
         q = """select hostid from hosts"""
         if not self._iter:
- self._iter = db.getCursor()
+ self._iter = self.db.getCursor()
             self._iter.execute(q)
         
         id = self._iter.fetchone()
@@ -77,7 +71,8 @@
 class ActionQueue(object):
 
     def __init__(self):
- self.c = db.getCursor()
+ self.db = DB(conf.DBFile())
+ self.c = self.db.getCursor()
 
 
     def put(self, hostid, action, args, kwargs):
@@ -97,7 +92,7 @@
 
         self.c.execute(q2, (hostid, queueOrder, action, blob))
 
- db.commit()
+ self.db.commit()
 
 
     def get(self, hostid):
@@ -124,7 +119,7 @@
     def remove(self, actionKey):
         q = """ delete from actions where actionkey=%s"""
         self.c.execute(q, (actionKey,))
- db.commit()
+ self.db.commit()
         
 
 

Modified: branches/stateengine​/src/se.conf
Url: http://current.tigri​s.org/source/browse/​current/branches/sta​teengine/src/se.conf​?view=diff&rev=1​98&p1=branches/s​tateengine/src/se.co​nf&r1=197&p2​=branches/stateengin​e/src/se.conf&r2​=198
====================​====================​====================​==================
--- branches/stateengine​/src/se.conf (original)
+++ branches/stateengine​/src/se.conf Mon Sep 5 13:45:22 2005
@@ -1,3 +1,3 @@
-[main]
+[server]
 db=se.sqlite
-
+configs=../configs

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r198 - branches/stateengine/src jjneely Jack Neely 2005-09-05 13:45:22 PDT
Messages per page: