diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2004-05-27 19:24:45 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2004-05-27 19:24:45 +0000 |
commit | 7958ad73a13342e6da1e1ec3c777801c6f2af787 (patch) | |
tree | 80165b89a9a073a4c22036b56339576b544f91ba /generators/cfg.py | |
parent | 79e8967ac9fb5622b9377335a14968b6707e94ba (diff) | |
download | bcfg2-7958ad73a13342e6da1e1ec3c777801c6f2af787.tar.gz bcfg2-7958ad73a13342e6da1e1ec3c777801c6f2af787.tar.bz2 bcfg2-7958ad73a13342e6da1e1ec3c777801c6f2af787.zip |
(Logical change 1.19)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@76 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'generators/cfg.py')
-rw-r--r-- | generators/cfg.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/generators/cfg.py b/generators/cfg.py index e69de29bb..2417c9202 100644 --- a/generators/cfg.py +++ b/generators/cfg.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +from os import stat, listdir +from re import compile +from stat import S_ISDIR, ST_MODE, ST_MTIME + +from Types import ConfigFile +from Generator import Generator +from GeneratorUtils import DirectoryBacked, FileBacked + +class ConfigFragment(object): + def __init__(self,filename,datafile): + self.re = compile("\S+%s(.(?P<type>[BTH])(?P<prio>\d)+_(?P<data>\S+)(.(?P<op>cat|udiff))?)?"%(filename)) + m = self.re.match(datafile) + self.type = m.group('type') + if self.type: + self.prio = m.group('prio') + self.data = m.group('data') + self.op = m.group('op') + else: + self.type='G' + self.data = file(datafile).read() + self.mtime = stat(datafile)[ST_MTIME] + +class ConfigFileRepository(DirectoryBacked): + fragment = compile("(^:info$|^(?P<filename>.*)(\.((B(?P<bprio>\d+)_(?P<bundle>\S+))|(T(?P<tprio>\d+)_(?P<tag>\S+))(I(?P<iprio>\d+)_(?P<image>\S+))|(H_(?P<hostname>\S+)))(\.(?P<op>cat|udiff))?)?$)") + + def __index__(self): + pass + +class Repository(object): + def __init__(self,path): + # we need to figure out when to rerun this code + self.path = path + dirs = [path] + self.entries = {} + # we can locate file locations by searching for :info files + while dirs: + el = listdir(dirs[0]) + for entry in el: + s = stat("%s/%s"%(dirs[0],entry)) + if S_ISDIR(s[ST_MODE]): + dirs.append("%s/%s"%(dirs[0],entry)) + if ':info' in el: + print dirs[0] + self.entries[dirs[0][len(path):]] = DirectoryBacked(dirs[0]) + dirs = dirs[1:] + +class cfg(Generator): + __name__ = 'cfg' + __version__ = '$Id$' + __author__ = 'bcfg-dev@mcs.anl.gov' + __build__ = {} + + def __setup__(self): + self.repo = Repository(self.data) + + |