rooted_paths.py 533 Bytes
Newer Older
1 2
"""Provides rooted_glob, for finding relative glob paths in another director."""

3 4 5 6 7 8 9 10 11 12
import glob2


def rooted_glob(root, glob):
    """
    Returns the results of running `glob` rooted in the directory `root`.
    All returned paths are relative to `root`.

    Uses glob2 globbing
    """
13
    return remove_root(root, sorted(glob2.glob('{root}/{glob}'.format(root=root, glob=glob))))
14 15 16 17 18 19 20


def remove_root(root, paths):
    """
    Returns `paths` made relative to `root`
    """
    return [pth.replace(root + '/', '') for pth in paths]