diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2015-06-06 14:01:06 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2015-06-06 15:26:48 -0700 |
commit | 5d7a6c0c4671626fd402245fe57cec526e6365f8 (patch) | |
tree | b6da306c0079fca6b71fd81887ae27eb1bd1ecb6 | |
parent | 1f0246f970c4198e59f039590b808afd5ef98d88 (diff) | |
download | spack-5d7a6c0c4671626fd402245fe57cec526e6365f8.tar.gz spack-5d7a6c0c4671626fd402245fe57cec526e6365f8.tar.bz2 spack-5d7a6c0c4671626fd402245fe57cec526e6365f8.tar.xz spack-5d7a6c0c4671626fd402245fe57cec526e6365f8.zip |
Add FileFilter convenience class to llnl.util.filesystem.
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 8eff642938..029a7536df 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -25,7 +25,7 @@ __all__ = ['set_install_permissions', 'install', 'install_tree', 'traverse_tree', 'expand_user', 'working_dir', 'touch', 'touchp', 'mkdirp', 'force_remove', 'join_path', 'ancestor', 'can_access', 'filter_file', - 'change_sed_delimiter', 'is_exe', 'force_symlink'] + 'FileFilter', 'change_sed_delimiter', 'is_exe', 'force_symlink'] import os import sys @@ -96,6 +96,15 @@ def filter_file(regex, repl, *filenames, **kwargs): shutil.rmtree(backup, ignore_errors=True) +class FileFilter(object): + """Convenience class for calling filter_file a lot.""" + def __init__(self, *filenames): + self.filenames = filenames + + def filter(self, regex, repl, **kwargs): + return filter_file(regex, repl, *self.filenames, **kwargs) + + def change_sed_delimiter(old_delim, new_delim, *filenames): """Find all sed search/replace commands and change the delimiter. e.g., if the file contains seds that look like 's///', you can |