diff options
author | James Yang <jjyang@mcs.anl.gov> | 2008-07-28 19:51:48 +0000 |
---|---|---|
committer | James Yang <jjyang@mcs.anl.gov> | 2008-07-28 19:51:48 +0000 |
commit | cc7c9309271eeee32e294a6fb1111f76988cf95e (patch) | |
tree | 498b287376729efbe1d0c929da50f2aae78046d7 /src/lib | |
parent | 83b60a48456c8d3efe90b5593d80323e435f2426 (diff) | |
download | bcfg2-cc7c9309271eeee32e294a6fb1111f76988cf95e.tar.gz bcfg2-cc7c9309271eeee32e294a6fb1111f76988cf95e.tar.bz2 bcfg2-cc7c9309271eeee32e294a6fb1111f76988cf95e.zip |
initial implementation of the Editor plugin.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4832 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Plugins/Editor.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lib/Server/Plugins/Editor.py b/src/lib/Server/Plugins/Editor.py new file mode 100644 index 000000000..b19df2bce --- /dev/null +++ b/src/lib/Server/Plugins/Editor.py @@ -0,0 +1,64 @@ +import Bcfg2.Server.Plugin +import fileinput +import re +import lxml.etree +from getopt import getopt + +def linesub(pattern, repl, filestring): + if filestring == None: + filestring = '' + output = list() + fileread = filestring.split('\n') + for line in fileread: + output.append(re.sub(pattern, repl, filestring)) + return '\n'.join(output) + +class EditDirectives(Bcfg2.Server.Plugin.SpecificData): + def ProcessDirectives(self, input): + temp = input + for directive in self.data.split('\n'): + directive = directive.split(',') + temp = linesub(directive[0], directive[1], temp) + return temp + +class EditEntrySet(Bcfg2.Server.Plugin.EntrySet): + def __init__(self, basename, path, props, entry_type, encoding): + Bcfg2.Server.Plugin.EntrySet.__init__(self, basename, path, props, entry_type, encoding) + self.inputs = dict() + + def bind_entry(self, entry, metadata): + client = metadata.hostname + filename = entry.get('name') + permdata = {'owner':'root', 'group':'root'} + permdata['perms'] = '0644' + [entry.attrib.__setitem__(key, permdata[key]) for key in permdata] + entry.text = self.entries['edits'].ProcessDirectives(self.get_client_data(client)) + if not entry.text: + entry.set('empty', 'true') + + def get_client_data(self, client): + return self.inputs[client] + + +class Editor(Bcfg2.Server.Plugin.GroupSpool,Bcfg2.Server.Plugin.ProbingPlugin): + __name__ = 'Editor' + __version__ = '1' + __author__ = 'bcfg2-dev@mcs.anl.gov' + filename_pattern = 'edits' + es_child_cls = EditDirectives + es_cls = EditEntrySet + + def GetProbes(self, _): + probelist = list() + for name in self.entries.keys(): + probe = lxml.etree.Element('probe') + probe.set('name', name) + probe.set('source', "Editor") + probe.text = "cat %s" %name + probelist.append(probe) + return probelist + + def ReceiveData(self, client, datalist): + for data in datalist: + self.entries[data.get('name')].inputs[client.hostname] = data.text + print data, data.attrib |