diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Generator.py | 81 | ||||
-rw-r--r-- | src/lib/Server/Generators/account.py | 3 | ||||
-rw-r--r-- | src/lib/Server/Generators/cfg.py | 3 | ||||
-rw-r--r-- | src/lib/Server/Generators/fstab.py | 3 | ||||
-rw-r--r-- | src/lib/Server/Generators/servicemgr.py | 3 |
5 files changed, 83 insertions, 10 deletions
diff --git a/src/lib/Server/Generator.py b/src/lib/Server/Generator.py index eb66404a2..1ea602947 100644 --- a/src/lib/Server/Generator.py +++ b/src/lib/Server/Generator.py @@ -1,8 +1,7 @@ #!/usr/bin/env python # $Id$ -from Error import GeneratorError - +from elementtree.ElementTree import XML from syslog import syslog, LOG_ERR class Generator(object): @@ -58,3 +57,81 @@ class Generator(object): def AcceptProbeData(self, client, probedata): return + +class FileBacked(object): + '''This object caches file data in memory. + HandleEvent is called whenever fam registers an event. + Index can parse the data into member data as required. + This object is meant to be used as a part of DirectoryBacked.''' + + def __init__(self, name): + self.name = name + self.HandleEvent() + + def HandleEvent(self, event=None): + self.data = file(self.name).read() + self.Index() + + def Index(self): + pass + +class DirectoryBacked(object): + '''This object is a coherent cache for a filesystem hierarchy of files.''' + __child__ = FileBacked + + def __init__(self, name, fam): + self.name = name + self.fam = fam + self.entries = {} + self.inventory = False + fam.AddMonitor(name, self) + + def __getitem__(self, key): + return self.entries[key] + + def __iter__(self): + return self.entries.iteritems() + + def AddEntry(self, name): + if self.entries.has_key(name): + print "got multiple adds" + else: + self.entries[name] = self.__child__('%s/%s'%(self.name, name)) + self.entries[name].HandleEvent() + + def HandleEvent(self, event): + action = event.code2str() + if action == 'exists': + if event.filename != self.name: + self.AddEntry(event.filename) + elif action == 'created': + self.AddEntry(event.filename) + elif action == 'changed': + self.entries[event.filename].HandleEvent(event) + elif action == 'deleted': + if self.entries.has_key(event.filename): + del self.entries[event.filename] + elif action in ['endExist']: + pass + else: + print "Got unknown event %s %s %s"%(event.requestID, event.code2str(), event.filename) + +class XMLFileBacked(FileBacked): + '''This object is a coherent cache for an XML file to be used as a part of DirectoryBacked.''' + __identifier__ = 'name' + + def Index(self): + a = XML(self.data) + self.label = a.attrib[self.__identifier__] + self.entries = a.getchildren() + + def __iter__(self): + return iter(self.entries) + +class SingleXMLFileBacked(XMLFileBacked): + '''This object is a coherent cache for an independent XML File.''' + def __init__(self,filename,fam): + XMLFileBacked.__init__(self, filename) + fam.AddMonitor(filename, self) + + diff --git a/src/lib/Server/Generators/account.py b/src/lib/Server/Generators/account.py index 2405128f8..8c91676e4 100644 --- a/src/lib/Server/Generators/account.py +++ b/src/lib/Server/Generators/account.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -from Bcfg2.Server.Generator import Generator -from Bcfg2.Server.GeneratorUtils import DirectoryBacked +from Bcfg2.Server.Generator import Generator, DirectoryBacked from Bcfg2.Server.Types import ConfigFile class account(Generator): diff --git a/src/lib/Server/Generators/cfg.py b/src/lib/Server/Generators/cfg.py index e2f70b8bc..97b0775e1 100644 --- a/src/lib/Server/Generators/cfg.py +++ b/src/lib/Server/Generators/cfg.py @@ -5,8 +5,7 @@ from re import compile from stat import S_ISDIR, ST_MODE from string import join -from Bcfg2.Server.Generator import Generator -from Bcfg2.Server.GeneratorUtils import DirectoryBacked, FileBacked +from Bcfg2.Server.Generator import Generator, DirectoryBacked, FileBacked from Bcfg2.Server.Metadata import Metadata class FileEntry(FileBacked): diff --git a/src/lib/Server/Generators/fstab.py b/src/lib/Server/Generators/fstab.py index 16e3ae4bf..bb9568ce8 100644 --- a/src/lib/Server/Generators/fstab.py +++ b/src/lib/Server/Generators/fstab.py @@ -2,8 +2,7 @@ from re import compile -from Bcfg2.Server.Generator import Generator -from Bcfg2.Server.GeneratorUtils import DirectoryBacked +from Bcfg2.Server.Generator import Generator, DirectoryBacked from Bcfg2.Server.Types import ConfigFile class fstab(Generator): diff --git a/src/lib/Server/Generators/servicemgr.py b/src/lib/Server/Generators/servicemgr.py index 2e7a480ae..dfee9f224 100644 --- a/src/lib/Server/Generators/servicemgr.py +++ b/src/lib/Server/Generators/servicemgr.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -from Bcfg2.Server.Generator import Generator -from Bcfg2.Server.GeneratorUtils import SingleXMLFileBacked +from Bcfg2.Server.Generator import Generator, SingleXMLFileBacked class ServiceList(SingleXMLFileBacked): pass |