diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-01-08 13:16:35 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-01-08 13:16:35 -0500 |
commit | 923e48916f19bedfe5b239b1baca18dc38c39491 (patch) | |
tree | 2d1db7141c14925e59262aae5f38eca3ddef9a2b | |
parent | 40bfc1dc57dd6a05a01f72d6332af7d586a15768 (diff) | |
download | bcfg2-923e48916f19bedfe5b239b1baca18dc38c39491.tar.gz bcfg2-923e48916f19bedfe5b239b1baca18dc38c39491.tar.bz2 bcfg2-923e48916f19bedfe5b239b1baca18dc38c39491.zip |
replace unintuitive reduce() calls with slightly less unintuitive chain() calls
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 8 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Base.py | 12 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/SSHbase.py | 15 |
3 files changed, 16 insertions, 19 deletions
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 040036fb2..37da4a4b6 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -16,7 +16,8 @@ import Bcfg2.Logger import Bcfg2.Server.FileMonitor from Bcfg2.Cache import Cache import Bcfg2.Statistics -from Bcfg2.Compat import xmlrpclib, reduce # pylint: disable=W0622 +from itertools import chain +from Bcfg2.Compat import xmlrpclib # pylint: disable=W0622 from Bcfg2.Server.Plugin import PluginInitError, PluginExecutionError, \ track_statistics @@ -493,9 +494,8 @@ class BaseCore(object): :type metadata: Bcfg2.Server.Plugins.Metadata.ClientMetadata :returns: list of :class:`lxml.etree._Element` objects """ - structures = reduce(lambda x, y: x + y, - [struct.BuildStructures(metadata) - for struct in self.structures], []) + structures = list(chain(*[struct.BuildStructures(metadata) + for struct in self.structures])) sbundles = [b.get('name') for b in structures if b.tag == 'Bundle'] missing = [b for b in metadata.bundles if b not in sbundles] if missing: diff --git a/src/lib/Bcfg2/Server/Plugins/Base.py b/src/lib/Bcfg2/Server/Plugins/Base.py index 66515ede2..d662da60a 100644 --- a/src/lib/Bcfg2/Server/Plugins/Base.py +++ b/src/lib/Bcfg2/Server/Plugins/Base.py @@ -2,9 +2,8 @@ import copy import lxml.etree -import sys -from Bcfg2.Compat import reduce import Bcfg2.Server.Plugin +from itertools import chain class Base(Bcfg2.Server.Plugin.Plugin, @@ -18,7 +17,6 @@ class Base(Bcfg2.Server.Plugin.Plugin, __child__ = Bcfg2.Server.Plugin.StructFile deprecated = True - """Base creates independent clauses based on client metadata.""" def __init__(self, core, datastore): Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) Bcfg2.Server.Plugin.Structure.__init__(self) @@ -33,8 +31,8 @@ class Base(Bcfg2.Server.Plugin.Plugin, def BuildStructures(self, metadata): """Build structures for client described by metadata.""" ret = lxml.etree.Element("Independent", version='2.0') - fragments = reduce(lambda x, y: x + y, - [base.Match(metadata) for base - in list(self.entries.values())], []) - [ret.append(copy.copy(frag)) for frag in fragments] + fragments = list(chain(*[base.Match(metadata) + for base in list(self.entries.values())])) + for frag in fragments: + ret.append(copy.copy(frag)) return [ret] diff --git a/src/lib/Bcfg2/Server/Plugins/SSHbase.py b/src/lib/Bcfg2/Server/Plugins/SSHbase.py index feb76aa57..c7db67301 100644 --- a/src/lib/Bcfg2/Server/Plugins/SSHbase.py +++ b/src/lib/Bcfg2/Server/Plugins/SSHbase.py @@ -7,10 +7,11 @@ import socket import shutil import logging import tempfile +from itertools import chain from subprocess import Popen, PIPE import Bcfg2.Server.Plugin from Bcfg2.Server.Plugin import PluginExecutionError -from Bcfg2.Compat import any, u_str, reduce, b64encode # pylint: disable=W0622 +from Bcfg2.Compat import any, u_str, b64encode # pylint: disable=W0622 LOGGER = logging.getLogger(__name__) @@ -200,15 +201,13 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin, if specific.hostname and specific.hostname in names: hostnames = names[specific.hostname] elif specific.group: - hostnames = \ - reduce(lambda x, y: x + y, - [names[cmeta.hostname] - for cmeta in \ - mquery.by_groups([specific.group])], []) + hostnames = list(chain( + *[names[cmeta.hostname] + for cmeta in \ + mquery.by_groups([specific.group])])) elif specific.all: # a generic key for all hosts? really? - hostnames = reduce(lambda x, y: x + y, - list(names.values()), []) + hostnames = list(chain(*list(names.values()))) if not hostnames: if specific.hostname: key = specific.hostname |