From c876d0563bb92e5ce7d037ab6a89eb0e0bd69160 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 1 Mar 2013 03:29:05 +0100 Subject: Pinning: new pluing to handle the pinnings The pinnings of packages to a specific source are now handled with a specific plugin. This has the advantage that genshi templates could be generated out of the configured pinnings. --- src/lib/Server/Plugins/Pinning.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/lib/Server/Plugins/Pinning.py (limited to 'src/lib/Server/Plugins/Pinning.py') diff --git a/src/lib/Server/Plugins/Pinning.py b/src/lib/Server/Plugins/Pinning.py new file mode 100644 index 000000000..474ece41b --- /dev/null +++ b/src/lib/Server/Plugins/Pinning.py @@ -0,0 +1,49 @@ +import os +import re +import sys +import copy +import logging +import lxml.etree +import Bcfg2.Server.Plugin + +logger = logging.getLogger('Bcfg2.Plugins.Pinnings') + +class PinningFile(Bcfg2.Server.Plugin.StructFile): + """Class for pinning files.""" + def get_additional_data(self, meta): + data = self.Match(meta) + results = {} + for d in data: + name = d.get('name', '') + src = d.get('src', '') + results[name] = src + return results + +class PinDirectoryBacked(Bcfg2.Server.Plugin.DirectoryBacked): + __child__ = PinningFile + patterns = re.compile(r'.*\.xml$') + + def get_additional_data(self, meta): + results = {} + for files in self.entries: + results.update(self.entries[files].get_additional_data(meta)) + return results + +class Pinning(Bcfg2.Server.Plugin.Plugin, + Bcfg2.Server.Plugin.Connector): + name = 'Pinning' + version = '$Revision$' + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.Connector.__init__(self) + try: + self.store = PinDirectoryBacked(self.data, core.fam) + except OSError: + e = sys.exc_info()[1] + self.logger.error("Error while creating Pinning store: %s %s" % + (e.strerror, e.filename)) + raise Bcfg2.Server.Plugin.PluginInitError + + def get_additional_data(self, meta): + return self.store.get_additional_data(meta) -- cgit v1.2.3-1-g7c22