diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2015-03-12 10:32:29 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2015-03-12 10:32:29 -0700 |
commit | 560f2c299a384183d314a0c4968169a0f35cc9c1 (patch) | |
tree | 23840fafda60a4d657c1b37072df1c46f2f68a6d /lib/spack/llnl/util/link_tree.py | |
parent | 32e2f21e8dc255caa2a756fc61d5994e62d68fe2 (diff) | |
download | spack-560f2c299a384183d314a0c4968169a0f35cc9c1.tar.gz spack-560f2c299a384183d314a0c4968169a0f35cc9c1.tar.bz2 spack-560f2c299a384183d314a0c4968169a0f35cc9c1.tar.xz spack-560f2c299a384183d314a0c4968169a0f35cc9c1.zip |
Add install_tree, force_symlink helper functions.
Diffstat (limited to 'lib/spack/llnl/util/link_tree.py')
-rw-r--r-- | lib/spack/llnl/util/link_tree.py | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/lib/spack/llnl/util/link_tree.py b/lib/spack/llnl/util/link_tree.py index 4d778eca1e..583f077b79 100644 --- a/lib/spack/llnl/util/link_tree.py +++ b/lib/spack/llnl/util/link_tree.py @@ -32,88 +32,6 @@ from llnl.util.filesystem import * empty_file_name = '.spack-empty' -def traverse_tree(source_root, dest_root, rel_path='', **kwargs): - """Traverse two filesystem trees simultaneously. - - Walks the LinkTree directory in pre or post order. Yields each - file in the source directory with a matching path from the dest - directory, along with whether the file is a directory. - e.g., for this tree:: - - root/ - a/ - file1 - file2 - b/ - file3 - - When called on dest, this yields:: - - ('root', 'dest') - ('root/a', 'dest/a') - ('root/a/file1', 'dest/a/file1') - ('root/a/file2', 'dest/a/file2') - ('root/b', 'dest/b') - ('root/b/file3', 'dest/b/file3') - - Optional args: - - order=[pre|post] -- Whether to do pre- or post-order traveral. - - ignore=<predicate> -- Predicate indicating which files to ignore. - - follow_nonexisting -- Whether to descend into directories in - src that do not exit in dest. Default True. - - follow_links -- Whether to descend into symlinks in src. - - """ - follow_nonexisting = kwargs.get('follow_nonexisting', True) - follow_links = kwargs.get('follow_link', False) - - # Yield in pre or post order? - order = kwargs.get('order', 'pre') - if order not in ('pre', 'post'): - raise ValueError("Order must be 'pre' or 'post'.") - - # List of relative paths to ignore under the src root. - ignore = kwargs.get('ignore', lambda filename: False) - - # Don't descend into ignored directories - if ignore(rel_path): - return - - source_path = os.path.join(source_root, rel_path) - dest_path = os.path.join(dest_root, rel_path) - - # preorder yields directories before children - if order == 'pre': - yield (source_path, dest_path) - - for f in os.listdir(source_path): - source_child = os.path.join(source_path, f) - dest_child = os.path.join(dest_path, f) - rel_child = os.path.join(rel_path, f) - - # Treat as a directory - if os.path.isdir(source_child) and ( - follow_links or not os.path.islink(source_child)): - - # When follow_nonexisting isn't set, don't descend into dirs - # in source that do not exist in dest - if follow_nonexisting or os.path.exists(dest_child): - tuples = traverse_tree(source_root, dest_root, rel_child, **kwargs) - for t in tuples: yield t - - # Treat as a file. - elif not ignore(os.path.join(rel_path, f)): - yield (source_child, dest_child) - - if order == 'post': - yield (source_path, dest_path) - - - class LinkTree(object): """Class to create trees of symbolic links from a source directory. |