コード例 #1
0
ファイル: libraries.py プロジェクト: LudoBike/quodlibet
def iter_paths(root, exclude=[], skip_hidden=True):
    """yields paths contained in root (symlinks dereferenced)

    Any path starting with any of the path parts included in exclude
    are ignored (before and after dereferencing symlinks)

    Directory symlinks are not followed (except root itself)

    Args:
        root (fsnative)
        exclude (List[fsnative])
        skip_hidden (bool): Ignore files which are hidden or where any
            of the parent directories are hidden.
    Yields:
        fsnative: absolute dereferenced paths
    """

    assert isinstance(root, fsnative)
    assert all((isinstance(p, fsnative) for p in exclude))
    assert os.path.abspath(root)

    def skip(path):
        if skip_hidden and ishidden(path):
            return True
        # FIXME: normalize paths..
        return any((path.startswith(p) for p in exclude))

    if skip_hidden and ishidden(root):
        return

    for path, dnames, fnames in os.walk(root):
        if skip_hidden:
            dnames[:] = list(filter(
                lambda d: not ishidden(os.path.join(path, d)), dnames))
        for filename in fnames:
            fullfilename = os.path.join(path, filename)
            if skip(fullfilename):
                continue
            fullfilename = os.path.realpath(fullfilename)
            if skip(fullfilename):
                continue
            yield fullfilename
コード例 #2
0
ファイル: libraries.py プロジェクト: rakuna/quodlibet
def iter_paths(root, exclude=[], skip_hidden=True):
    """yields paths contained in root (symlinks dereferenced)

    Any path starting with any of the path parts included in exclude
    are ignored (before and after dereferencing symlinks)

    Directory symlinks are not followed (except root itself)

    Args:
        root (fsnative)
        exclude (List[fsnative])
        skip_hidden (bool): Ignore files which are hidden or where any
            of the parent directories are hidden.
    Yields:
        fsnative: absolute dereferenced paths
    """

    assert isinstance(root, fsnative)
    assert all((isinstance(p, fsnative) for p in exclude))
    assert os.path.abspath(root)

    def skip(path):
        if skip_hidden and ishidden(path):
            return True
        # FIXME: normalize paths..
        return any((path.startswith(p) for p in exclude))

    if skip_hidden and ishidden(root):
        return

    for path, dnames, fnames in os.walk(root):
        if skip_hidden:
            dnames[:] = list(
                filter(lambda d: not ishidden(os.path.join(path, d)), dnames))
        for filename in fnames:
            fullfilename = os.path.join(path, filename)
            if skip(fullfilename):
                continue
            fullfilename = os.path.realpath(fullfilename)
            if skip(fullfilename):
                continue
            yield fullfilename
コード例 #3
0
ファイル: test_util_path.py プロジェクト: ptitjes/quodlibet
 def test_main(self):
     assert ishidden(fsnative(u"."))
     assert ishidden(fsnative(u"foo/.bar"))
     assert not ishidden(fsnative(u".foo/bar"))
     assert not ishidden(fsnative(u"foo"))
コード例 #4
0
ファイル: libraries.py プロジェクト: LudoBike/quodlibet
 def skip(path):
     if skip_hidden and ishidden(path):
         return True
     # FIXME: normalize paths..
     return any((path.startswith(p) for p in exclude))
コード例 #5
0
ファイル: libraries.py プロジェクト: rakuna/quodlibet
 def skip(path):
     if skip_hidden and ishidden(path):
         return True
     # FIXME: normalize paths..
     return any((path.startswith(p) for p in exclude))
コード例 #6
0
 def test_main(self):
     assert ishidden(fsnative(u"."))
     assert ishidden(fsnative(u"foo/.bar"))
     assert not ishidden(fsnative(u".foo/bar"))
     assert not ishidden(fsnative(u"foo"))