From 7958ad73a13342e6da1e1ec3c777801c6f2af787 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Thu, 27 May 2004 19:24:45 +0000 Subject: (Logical change 1.19) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@76 ce84e21b-d406-0410-9b95-82705330c041 --- generators/cfg.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'generators') 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[BTH])(?P\d)+_(?P\S+)(.(?Pcat|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.*)(\.((B(?P\d+)_(?P\S+))|(T(?P\d+)_(?P\S+))(I(?P\d+)_(?P\S+))|(H_(?P\S+)))(\.(?Pcat|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) + + -- cgit v1.2.3-1-g7c22