summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-09-14 15:51:13 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-09-14 15:51:13 +0000
commit1f16988e1d43bb9a994cf374569f6c7640f16837 (patch)
treedeef4343c984b3d6fef74b9bc248153e2c235b8d
parent1748afee014eaba4d88dff3b63baa9f7581db965 (diff)
downloadbcfg2-1f16988e1d43bb9a994cf374569f6c7640f16837.tar.gz
bcfg2-1f16988e1d43bb9a994cf374569f6c7640f16837.tar.bz2
bcfg2-1f16988e1d43bb9a994cf374569f6c7640f16837.zip
Implement template target ownership and permissions control
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2251 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Server/Plugins/TCheetah.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/lib/Server/Plugins/TCheetah.py b/src/lib/Server/Plugins/TCheetah.py
index 51161e8ec..7032e09fa 100644
--- a/src/lib/Server/Plugins/TCheetah.py
+++ b/src/lib/Server/Plugins/TCheetah.py
@@ -1,12 +1,12 @@
'''This module implements a templating generator based on Cheetah'''
__revision__ = '$Revision$'
-#from Bcfg2.Server.Plugin import Plugin, PluginExecutionError, FileBacked, SingleXMLFileBacked
-
-import logging, lxml.etree, posixpath, Cheetah.Template
+import logging, lxml.etree, posixpath, re, Cheetah.Template
import Bcfg2.Server.Plugin
logger = logging.getLogger('Bcfg2.Plugins.TCheetah')
+info = re.compile('^owner:(\s)*(?P<owner>\w+)$|group:(\s)*(?P<group>\w+)$|' +
+ 'perms:(\s)*(?P<perms>\w+)$')
class TemplateFile:
'''Template file creates Cheetah template structures for the loaded file'''
@@ -22,8 +22,21 @@ class TemplateFile:
self.template = Cheetah.Template.Template(open(self.name).read())
self.template.properties = self.properties.properties
elif event.filename == 'info':
- # read the metadata
- pass
+ for line in open(self.name[:-8] + '/info').readlines():
+ match = info.match(line)
+ if not match:
+ logger.warning("Failed to match line: %s"%line)
+ continue
+ else:
+ mgd = match.groupdict()
+ if mgd['owner']:
+ self.metadata['owner'] = mgd['owner']
+ elif mgd['group']:
+ self.metadata['group'] = mgd['group']
+ elif mgd['perms']:
+ self.metadata['perms'] = mgd['perms']
+ if len(self.metadata['perms']) == 3:
+ self.metadata['perms'] = "0%s" % (self.metadata['perms'])
def BuildFile(self, entry, metadata):
'''Build literal file information'''
@@ -81,12 +94,10 @@ class TCheetah(Bcfg2.Server.Plugin.Plugin):
if posixpath.isdir(epath):
self.AddDirectoryMonitor(epath[len(self.data):])
else:
- if self.entries.has_key(identifier):
- pass
- else:
+ if not self.entries.has_key(identifier):
self.entries[identifier] = TemplateFile(epath, self.properties)
- self.entries[identifier].HandleEvent(event)
self.Entries['ConfigFile'][identifier] = self.BuildEntry
+ self.entries[identifier].HandleEvent(event)
elif action == 'changed':
if self.entries.has_key(identifier):
self.entries[identifier].HandleEvent(event)