Login | Register
My pages Projects Community openCollabNet

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

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

current
Discussion topic

Back to topic list

svn commit: r199 - branches/stateengine/src

Reply

Author jjneely
Full name Jack Neely
Date 2005-09-19 08:08:31 PDT
Message Author: jjneely
Date: Mon Sep 19 08:08:30 2005
New Revision: 199

Modified:
   branches/stateengine​/src/hostconfig.py
Log:
Changes for hostconfig.py to allow it to use the DB and work toward
loading/parsing/summing files on demand rather than all at once. (Which is
quite slow.)


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=199&p1=bran​ches/stateengine/src​/hostconfig.py&r​1=198&p2=branche​s/stateengine/src/ho​stconfig.py&r2=1​99
====================​====================​====================​==================
--- branches/stateengine​/src/hostconfig.py (original)
+++ branches/stateengine​/src/hostconfig.py Mon Sep 19 08:08:30 2005
@@ -3,12 +3,15 @@
 import sha
 import config
 from pyparsing import *
-
+from db import DB
 
 class HostDict(dict):
 
     def __init__(self):
         self.conf = config.Server()
+ self.db = DB(self.conf.DBFile())
+ self.cursor = self.db.getCursor()
+
         dict.__init__(self)
 
     def _getFilesAndDirs(self, path):
@@ -30,27 +33,44 @@
 
         return files, dirs
 
- def load(self, dir=None):
+ def refresh(self):
+ self.load(ignoreDups=False)
+
+ def load(self, dir=None, ignoreDups=True):
         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
+ if not ingoreDups:
+ print "Multiple Config files for %s" % file
+ # Leave existing value in place
             else:
- self[os.path.basename(file)] = (h, sum.hexdigest())
+ dict.__setitem__(self, key, file)
 
         for dir in dirs:
             self.load(dir)
-
+
+ def __getitem__(self, key):
+ value = dict.__getitem__(self, key)
+
+ if type(value) == type(""):
+ # load file on demand
+ h = HostConfig(value)
+ dict.__setitem__(self, key, h)
+ return h
+ else:
+ return value
+
+ def __setitem__(self, key, value):
+ pass
+
+ def __delitem__(self, key):
+ pass
+
 
 # Class to hold state information from host config
 class HostConfig(object):
@@ -73,9 +93,13 @@
         # Get hostconfig for hostname
         self._stateArgs = {}
         self._stateKWs = {}
- self._path = path
+ self.path = path
 
         self.readConfig()
+
+ # We need to hash the file to detect changes
+ # We need to be able to note file changes and use them instantly
+ # maybe check date and if different compare hashes?
         
 
     def readConfig(self):
@@ -103,7 +127,7 @@
     def _getConfigFile(self):
         # return an open file of the config
 
- fd = open(self._path)
+ fd = open(self.path)
         return fd
         
     def addConfig(self, stateKey, args, kwtuples):

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

Messages

Show all messages in topic

svn commit: r199 - branches/stateengine/src jjneely Jack Neely 2005-09-19 08:08:31 PDT
Messages per page: