From 6012386e61cedda17d982e2ac9f7ae494671a57c Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Wed, 31 Aug 2005 21:37:18 +0000 Subject: working, verified delta support 2005/08/30 16:04:05-05:00 anl.gov!desai fix tb from Cory (Logical change 1.291) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1159 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Generators/Cfg.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Generators/Cfg.py b/src/lib/Server/Generators/Cfg.py index 5f4d0fc39..659ad714f 100644 --- a/src/lib/Server/Generators/Cfg.py +++ b/src/lib/Server/Generators/Cfg.py @@ -56,8 +56,7 @@ class ConfigFileEntry(object): all data for all clients.''' specific = regcompile('(.*/)(?P[\S\-.]+)\.((H_(?P\S+))|' + '(B(?P\d+)_(?P\S+))|(A(?P\d+)_(?P\S+))|' + - '(I_(?P\S+))|(C(?P\d+)_(?P\S+)))' + - '(\.(?Pcat|udiff))?$') + '(I_(?P\S+))|(C(?P\d+)_(?P\S+)))$') info = regcompile('^owner:(\s)*(?P\w+)|group:(\s)*(?P\w+)|' + 'perms:(\s)*(?P\w+)|encoding:(\s)*(?P\w+)|' + '(?Pparanoid(\s)*)$') @@ -95,6 +94,8 @@ class ConfigFileEntry(object): def AddEntry(self, name): '''add new file additions for a single cf file''' + delta = False + oldname = name if name[-5:] == ':info': return self.read_info() @@ -103,6 +104,11 @@ class ConfigFileEntry(object): self.basefiles.sort() return + if name.split('/')[-1].split('.')[-1] in ['cat']: + delta = True + oldname = name + name = name[:-4] + specmatch = self.specific.match(name) if specmatch == None: syslog(LOG_ERR, "Cfg: Failed to match file %s" % (name)) @@ -113,10 +119,10 @@ class ConfigFileEntry(object): if value != None: data[item] = value - cfile = FileEntry(name, False, data.get('image', None), data.get('class', []), + cfile = FileEntry(oldname, False, data.get('image', None), data.get('class', []), data.get('bundle', []), data.get('attr', []), data.get('hostname', None)) - if specmatch.group("op") != None: + if delta: self.deltas.append(cfile) self.deltas.sort() else: @@ -170,12 +176,20 @@ class ConfigFileEntry(object): raise GeneratorError, ('basefile', name) filedata += basefile.data - # find applicable deltas - #deltas = [x for x in self.deltas if x.Applies(metadata)] - # filter for more specific - #for delta in deltas: - # pass - # apply diffs, etc + for delta in [x for x in self.deltas if metadata.Applies(x)]: + # find applicable deltas + lines = filedata.split('\n') + if not lines[-1]: + lines = lines[:-1] + dlines = [dline for dline in delta.data.split('\n') if dline] + for line in dlines: + if line[0] == '-': + if line[1:] in lines: + lines.remove(line[1:]) + else: + lines.append(line[1:]) + filedata = "\n".join(lines) + "\n" + entry.attrib.update(self.metadata) if self.paranoid: entry.attrib['paranoid'] = 'true' @@ -256,7 +270,8 @@ class Cfg(Generator): else: self.LogError("Ignoring event for %s"%(configfile)) elif action == 'deleted': - self.entries[configfile].HandleEvent(event) + if self.entries.has_key(configfile): + self.entries[configfile].HandleEvent(event) elif action in ['exists', 'endExist']: pass else: -- cgit v1.2.3-1-g7c22