From 20388ece86c91c7f2db112b6da38cfb2b8853196 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 25 Dec 2014 16:07:39 -0800 Subject: Clearer code in filter_file. --- lib/spack/llnl/util/filesystem.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 6a04d98a18..24c77a80db 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -63,8 +63,11 @@ def filter_file(regex, repl, *filenames, **kwargs): # Allow strings to use \1, \2, etc. for replacement, like sed if not callable(repl): unescaped = repl.replace(r'\\', '\\') - repl = lambda m: re.sub( - r'\\([0-9])', lambda x: m.group(int(x.group(1))), unescaped) + def replace_groups_with_groupid(m): + def groupid_to_group(x): + return m.group(int(x.group(1))) + return re.sub(r'\\([1-9])', groupid_to_group, unescaped) + repl = replace_groups_with_groupid if string: regex = re.escape(regex) -- cgit v1.2.3-60-g2f50