Esempio n. 1
0
async def test_rmtree(any_dir):
    assert [p async for p in bbb.listdir(any_dir)] == []

    N = 5
    await asyncio.wait([
        helpers.unsafe_create_file(any_dir / "alpha" / str(i))
        for i in range(N)
    ] + [
        helpers.unsafe_create_file(any_dir / "alpha" / "beta" / str(i))
        for i in range(N)
    ])
    with pytest.raises(NotADirectoryError):
        async with bbb.BoostExecutor(N) as e:
            await bbb.rmtree(any_dir / "alpha" / "0", e)

    async with bbb.BoostExecutor(N) as e:
        assert len([p async for p in bbb.listdir(any_dir / "alpha")]) == N + 1
        assert len([p async for p in bbb.listtree(any_dir / "alpha")]) == 2 * N
        await bbb.rmtree(any_dir / "alpha", e)

    with pytest.raises(FileNotFoundError):
        async with bbb.BoostExecutor(N) as e:
            await bbb.rmtree(any_dir / "alpha", e)

    with pytest.raises(FileNotFoundError):
        [p async for p in bbb.listdir(any_dir / "alpha")]
    assert [p async for p in bbb.listdir(any_dir)] == []
    assert [p async for p in bbb.listtree(any_dir)] == []
Esempio n. 2
0
async def lstree(path: str, long: bool = False, machine: bool = False) -> None:
    try:
        if long:
            await print_long(bbb.scantree(path), human_readable=not machine)
        else:
            async for p in bbb.listtree(path):
                print(p)
    except NotADirectoryError:
        path_obj = bbb.BasePath.from_str(path)
        if long:
            stat = await bbb.stat(path_obj)
            entry = bbb.listing.DirEntry.from_path_stat(path_obj, stat)
            print(entry.format(human_readable=not machine))
        else:
            print(path_obj)
Esempio n. 3
0
async def test_copyglob():
    with helpers.tmp_azure_dir() as dir1:
        with helpers.tmp_azure_dir() as dir2:
            await asyncio.wait([
                helpers.unsafe_create_file(dir1 / "f1"),
                helpers.unsafe_create_file(dir1 / "f2"),
                helpers.unsafe_create_file(dir1 / "g3"),
            ])

            async with bbb.BoostExecutor(100) as e:
                copied = [
                    p async for p in bbb.copying.copyglob_iterator(
                        dir1 / "f*", dir2, e)
                ]
                assert sorted([p.relative_to(dir1)
                               for p in copied]) == ["f1", "f2"]
                contents = sorted(
                    [p.relative_to(dir2) async for p in bbb.listtree(dir2)])
                assert contents == ["f1", "f2"]
Esempio n. 4
0
 async def _listtree(d, base):
     return sorted([p.relative_to(base) async for p in bbb.listtree(d)])
Esempio n. 5
0
 async def _listtree(d):
     return sorted([p.relative_to(any_dir) async for p in bbb.listtree(d)])