diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-03-12 03:42:14 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-03-12 03:42:14 +0100 |
commit | af94542b8d938dd931c07d439e9eb6437aab38bf (patch) | |
tree | 678dacafce7f3ff7106ab689737659de0136c766 /src/lib/Server/Plugins/Packages | |
parent | 0a289059cab2dfd6005b4e8fe6852221b49efcbe (diff) | |
download | bcfg2-af94542b8d938dd931c07d439e9eb6437aab38bf.tar.gz bcfg2-af94542b8d938dd931c07d439e9eb6437aab38bf.tar.bz2 bcfg2-af94542b8d938dd931c07d439e9eb6437aab38bf.zip |
Plugins/Packages: backported packages_form_entry/_to_entry
1.3.0 adds an layer of abstraction to the Packages plugin, that makes it
possible to change the method how Packages gets the name of a configured
entry or how it build the Package object, send to the client. This
backports these changes.
Diffstat (limited to 'src/lib/Server/Plugins/Packages')
-rw-r--r-- | src/lib/Server/Plugins/Packages/Collection.py | 35 | ||||
-rw-r--r-- | src/lib/Server/Plugins/Packages/__init__.py | 8 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/lib/Server/Plugins/Packages/Collection.py b/src/lib/Server/Plugins/Packages/Collection.py index d2d8a015d..f5e5bbe02 100644 --- a/src/lib/Server/Plugins/Packages/Collection.py +++ b/src/lib/Server/Plugins/Packages/Collection.py @@ -1,5 +1,6 @@ import copy import logging +import lxml.etree import Bcfg2.Server.Plugin logger = logging.getLogger(__name__) @@ -156,6 +157,40 @@ class Collection(Bcfg2.Server.Plugin.Debuggable): """ do any collection-level data setup tasks """ pass + def packages_from_entry(self, entry): + """ Given a Package or BoundPackage entry, get a list of the + package(s) described by it in a format appropriate for passing + to :func:`complete`. By default, that's just the name; only + the :mod:`Bcfg2.Server.Plugins.Packages.Yum` backend supports + versions or other extended data. See :ref:`pkg-objects` for + more details. + + :param entry: The XML entry describing the package or packages. + :type entry: lxml.etree._Element + :returns: list of strings, but see :ref:`pkg-objects` + """ + return [entry.get("name")] + + def packages_to_entry(self, pkglist, entry, config): + """ Given a list of package objects as returned by + :func:`packages_from_entry` or :func:`complete`, return an XML + tree describing the BoundPackage entries that should be + included in the client configuration. See :ref:`pkg-objects` + for more details. + + :param pkglist: A list of packages as returned by + :func:`complete` + :type pkglist: list of strings, but see :ref:`pkg-objects` + :param entry: The base XML entry to add all of the Package + entries to. This should be modified in place. + :type entry: lxml.etree._Element + """ + for pkg in pkglist: + lxml.etree.SubElement(entry, 'BoundPackage', name=pkg, + version=config.get("packages", "version", + default="auto"), + type=self.ptype, origin='Packages') + def complete(self, packagelist, pinnings=None, recommended=None): '''Build the transitive closure of all package dependencies diff --git a/src/lib/Server/Plugins/Packages/__init__.py b/src/lib/Server/Plugins/Packages/__init__.py index 427393ea0..d998f1c8b 100644 --- a/src/lib/Server/Plugins/Packages/__init__.py +++ b/src/lib/Server/Plugins/Packages/__init__.py @@ -157,7 +157,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, for struct in structures: for pkg in struct.xpath('//Package | //BoundPackage'): if pkg.get("name"): - initial.add(pkg.get("name")) + initial.update(collection.packages_from_entry(pkg)) if pkg.get("recommended"): recommended[pkg.get("name")] = pkg.get("recommended") @@ -189,11 +189,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, self.debug_log("Packages: %d initial, %d complete, %d new" % (len(initial), len(packages), len(newpkgs))) newpkgs.sort() - for pkg in newpkgs: - lxml.etree.SubElement(independent, 'BoundPackage', name=pkg, - version=self.config.get("global", "version", - default="auto"), - type=collection.ptype, origin='Packages') + collection.packages_to_entry(newpkgs, independent, self.config) def Refresh(self): '''Packages.Refresh() => True|False\nReload configuration |