From 1a6160ebeecffc57b5066ebf343188edf6a63eaa Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 12 Oct 2012 11:37:14 -0400 Subject: wrote sphinx docs for base server Core --- src/lib/Bcfg2/Server/Plugins/Decisions.py | 88 +++++++++++++++---------------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Decisions.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Decisions.py b/src/lib/Bcfg2/Server/Plugins/Decisions.py index 90d9ecbe3..5521ea045 100644 --- a/src/lib/Bcfg2/Server/Plugins/Decisions.py +++ b/src/lib/Bcfg2/Server/Plugins/Decisions.py @@ -1,67 +1,67 @@ -import logging -import lxml.etree -import sys +""" The Decisions plugin provides a flexible method to whitelist or +blacklist certain entries. """ +import os +import sys +import lxml.etree import Bcfg2.Server.Plugin -logger = logging.getLogger('Bcfg2.Plugins.Decisions') + class DecisionFile(Bcfg2.Server.Plugin.SpecificData): + """ Representation of a Decisions XML file """ + + def __init__(self, name, specific, encoding): + Bcfg2.Server.Plugin.SpecificData.__init__(self, name, specific, + encoding) + self.contents = None + def handle_event(self, event): Bcfg2.Server.Plugin.SpecificData.handle_event(self, event) self.contents = lxml.etree.XML(self.data) def get_decisions(self): - return [(x.get('type'), x.get('name')) for x in self.contents.xpath('.//Decision')] + """ Get a list of whitelist or blacklist tuples """ + return [(x.get('type'), x.get('name')) + for x in self.contents.xpath('.//Decision')] -class DecisionSet(Bcfg2.Server.Plugin.EntrySet): - basename_is_regex = True - def __init__(self, path, fam, encoding): - """Container for decision specification files. +class Decisions(Bcfg2.Server.Plugin.EntrySet, + Bcfg2.Server.Plugin.Plugin, + Bcfg2.Server.Plugin.Decision): + """ Decisions plugin - Arguments: - - `path`: repository path - - `fam`: reference to the file monitor - - `encoding`: XML character encoding + Arguments: + - `core`: Bcfg2.Core instance + - `datastore`: File repository location + """ + basename_is_regex = True + __author__ = 'bcfg-dev@mcs.anl.gov' - """ - Bcfg2.Server.Plugin.EntrySet.__init__(self, '(white|black)list', path, - DecisionFile, encoding) + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.Decision.__init__(self) + + Bcfg2.Server.Plugin.EntrySet.__init__(self, '(white|black)list', + self.data, + DecisionFile, + core.setup['encoding']) try: - fam.AddMonitor(path, self) + core.fam.AddMonitor(self.data, self) except OSError: - e = sys.exc_info()[1] - logger.error('Adding filemonitor for %s failed. ' - 'Make sure directory exists' % path) - raise Bcfg2.Server.Plugin.PluginInitError(e) + err = sys.exc_info()[1] + msg = 'Adding filemonitor for %s failed: %s' % (self.data, err) + self.logger.error(msg) + raise Bcfg2.Server.Plugin.PluginInitError(msg) def HandleEvent(self, event): + """ Handle events on Decision files by passing them off to + EntrySet.handle_event """ if event.filename != self.path: return self.handle_event(event) def GetDecisions(self, metadata, mode): ret = [] - candidates = [c for c in self.get_matching(metadata) - if c.name.split('/')[-1].startswith(mode)] - for c in candidates: - ret += c.get_decisions() + for cdt in self.get_matching(metadata): + if os.path.basename(cdt).startswith(mode): + ret.extend(cdt.get_decisions()) return ret - -class Decisions(DecisionSet, - Bcfg2.Server.Plugin.Plugin, - Bcfg2.Server.Plugin.Decision): - name = 'Decisions' - __author__ = 'bcfg-dev@mcs.anl.gov' - - def __init__(self, core, datastore): - """Decisions plugins - - Arguments: - - `core`: Bcfg2.Core instance - - `datastore`: File repository location - - """ - Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) - Bcfg2.Server.Plugin.Decision.__init__(self) - DecisionSet.__init__(self, self.data, core.fam, core.encoding) - -- cgit v1.2.3-1-g7c22