From 5a355d83a0a3c3e693787e8627a041850f006950 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Fri, 21 Mar 2008 19:54:01 +0000 Subject: plugin infrastructure improvements git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4432 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Plugin.py | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index b7109732f..0166abaa8 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -8,11 +8,12 @@ from lxml.etree import XML, XMLSyntaxError logger = logging.getLogger('Bcfg2.Plugin') default_file_metadata = {'owner': 'root', 'group': 'root', 'perms': '644', - 'encoding': 'ascii'} + 'encoding': 'ascii', 'paranoid':"false"} info_regex = re.compile( \ - '^owner:(\s)*(?P\w+)$|group:(\s)*(?P\w+)$|' + - 'perms:(\s)*(?P\w+)$') + '^owner:(\s)*(?P\S+)|group:(\s)*(?P\S+)|' + + 'perms:(\s)*(?P\w+)|encoding:(\s)*(?P\w+)|' + + '(?Pparanoid(\s)*)|mtime:(\s)*(?P\w+)$' ) class PluginInitError(Exception): '''Error raised in cases of Plugin initialization errors''' @@ -419,6 +420,30 @@ class Specificity: self.hostname == metadata.hostname or \ self.group in metadata.group + def __cmp__(self, other): + '''sort most to least specific''' + if self.all: + return 1 + if self.group: + if other.hostname: + return 1 + if other.group and other.prio > self.prio: + return 1 + if other.group and other.prio == self.prio: + return 0 + return -1 + + def more_specific(self, other): + '''test if self is more specific than other''' + if self.all: + True + elif self.group: + if other.hostname: + return True + elif other.group and other.prio > self.prio: + return True + return False + class EntrySet: '''Entry sets deal with the host- and group-specific entries''' def __init__(self, basename, path, props, entry_type): @@ -484,14 +509,12 @@ class EntrySet: 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']) + for key, value in mgd.iteritems(): + if value: + self.metadata[key] = value + if len(self.metadata['perms']) == 3: + self.metadata['perms'] = "0%s" % \ + (self.metadata['perms']) def reset_metadata(self, event): '''reset metadata to defaults if info or info.xml removed''' -- cgit v1.2.3-1-g7c22