From 923e48916f19bedfe5b239b1baca18dc38c39491 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 8 Jan 2013 13:16:35 -0500 Subject: replace unintuitive reduce() calls with slightly less unintuitive chain() calls --- src/lib/Bcfg2/Server/Plugins/Base.py | 12 +++++------- src/lib/Bcfg2/Server/Plugins/SSHbase.py | 15 +++++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins') 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 -- cgit v1.2.3-1-g7c22