summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugin.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-03-23 14:57:09 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-03-23 14:57:09 +0000
commitd2a7c0a153e547ff327cfac29f10788f7926a06b (patch)
tree4247e713a577fb93b3edb08b127398a1269f4c9f /src/lib/Server/Plugin.py
parentea2f00e639417d4b88c98245adc2f1c4a99bd3e1 (diff)
downloadbcfg2-d2a7c0a153e547ff327cfac29f10788f7926a06b.tar.gz
bcfg2-d2a7c0a153e547ff327cfac29f10788f7926a06b.tar.bz2
bcfg2-d2a7c0a153e547ff327cfac29f10788f7926a06b.zip
make Specificity generically useful
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4445 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugin.py')
-rw-r--r--src/lib/Server/Plugin.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 7fdf8b3fc..4b1d9d8d1 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -396,24 +396,12 @@ class SpecificityError(Exception):
class Specificity:
- def __init__(self, reg, fname):
- self.hostname = None
- self.all = False
- self.group = None
- self.prio = 0
- self.delta = False
- data = reg.match(fname)
- if not data:
- raise SpecificityError(fname)
- if data.group('hostname'):
- self.hostname = data.group('hostname')
- elif data.group('group'):
- self.group = data.group('group')
- self.prio = int(data.group('prio'))
- else:
- self.all = True
- if 'delta' in data.groupdict():
- self.delta = data.group('delta')
+ def __init__(self, all=False, group=False, hostname=False, prio=0, delta=False):
+ self.hostname = hostname
+ self.all = all
+ self.group = group
+ self.prio = prio
+ self.delta = delta
def matches(self, metadata):
return self.all or \
@@ -486,7 +474,7 @@ class EntrySet:
else:
fpath = "%s/%s" % (self.path, event.filename)
try:
- spec = Specificity(self.specific, event.filename)
+ spec = self.specificity_from_filename(event.filename)
except SpecificityError:
if not self.ignore.match(event.filename):
logger.error("Could not process filename %s; ignoring" % fpath)
@@ -496,6 +484,23 @@ class EntrySet:
spec)
self.entries[event.filename].handle_event(event)
+ def specificity_from_filename(self, fname):
+ '''construct a specificity instance from a filename and regex'''
+ data = self.specific.match(fname)
+ if not data:
+ raise SpecificityError(fname)
+ kwargs = {}
+ if data.group('hostname'):
+ kwargs['hostname'] = data.group('hostname')
+ elif data.group('group'):
+ kwargs['group'] = data.group('group')
+ kwargs['prio'] = int(data.group('prio'))
+ else:
+ kwargs['all'] = True
+ if 'delta' in data.groupdict():
+ kwargs['delta'] = data.group('delta')
+ return Specificity(**kwargs)
+
def update_metadata(self, event):
'''process info and info.xml files for the templates'''
fpath = "%s/%s" % (self.path, event.filename)