bcbd1bdb22
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
147 lines
4.5 KiB
Python
147 lines
4.5 KiB
Python
from collections.abc import Awaitable, Callable
|
|
|
|
from mirage.commands.builtin.utils.formatting import _human_size
|
|
from mirage.commands.builtin.utils.output import (format_record_text,
|
|
format_records)
|
|
from mirage.types import PathSpec
|
|
|
|
|
|
def _format_size(size: int, human: bool) -> str:
|
|
return _human_size(size) if human else str(size)
|
|
|
|
|
|
def _depth(entry_path: str, base_path: str) -> int:
|
|
base = base_path.rstrip("/")
|
|
rel = entry_path.rstrip("/")[len(base):]
|
|
if not rel:
|
|
return 0
|
|
return rel.strip("/").count("/") + 1
|
|
|
|
|
|
async def _du_one(
|
|
path: PathSpec,
|
|
compute_total: Callable[[PathSpec], Awaitable[int]],
|
|
compute_all: Callable[[PathSpec], Awaitable[tuple[list[tuple[str, int]],
|
|
int]]],
|
|
*,
|
|
s: bool,
|
|
a: bool,
|
|
h: bool,
|
|
max_depth: int | None,
|
|
) -> tuple[str, int]:
|
|
label = path.raw_path
|
|
|
|
if s:
|
|
total = await compute_total(path)
|
|
return _format_size(total, h) + "\t" + label, total
|
|
|
|
all_entries, total = await compute_all(path)
|
|
if not all_entries:
|
|
total = await compute_total(path)
|
|
return _format_size(total, h) + "\t" + label, total
|
|
|
|
if not a:
|
|
return _format_size(total, h) + "\t" + label, total
|
|
|
|
entries = all_entries
|
|
if max_depth is not None:
|
|
entries = [(p, sz) for p, sz in entries
|
|
if _depth(p, path.virtual) <= max_depth]
|
|
if not entries:
|
|
return _format_size(total, h) + "\t" + label, total
|
|
|
|
lines = [_format_size(sz, h) + "\t" + p for p, sz in entries]
|
|
display_total = sum(sz for _, sz in entries)
|
|
return "\n".join(lines), display_total
|
|
|
|
|
|
async def du(
|
|
paths: list[PathSpec],
|
|
*,
|
|
compute_total: Callable[[PathSpec], Awaitable[int]],
|
|
compute_all: Callable[[PathSpec], Awaitable[tuple[list[tuple[str, int]],
|
|
int]]],
|
|
s: bool = False,
|
|
a: bool = False,
|
|
h: bool = False,
|
|
max_depth: int | None = None,
|
|
c: bool = False,
|
|
) -> str:
|
|
sub_texts: list[str] = []
|
|
totals: list[int] = []
|
|
for p in paths:
|
|
text, total = await _du_one(
|
|
p,
|
|
compute_total,
|
|
compute_all,
|
|
s=s,
|
|
a=a,
|
|
h=h,
|
|
max_depth=max_depth,
|
|
)
|
|
sub_texts.append(text)
|
|
totals.append(total)
|
|
out = format_record_text(sub_texts)
|
|
if c:
|
|
grand = sum(totals)
|
|
out += _format_size(grand, h) + "\ttotal\n"
|
|
return out
|
|
|
|
|
|
async def _du_block(
|
|
p0: PathSpec,
|
|
compute_total: Callable[[PathSpec], Awaitable[int]],
|
|
compute_all: Callable[[PathSpec], Awaitable[list[tuple[str, int]]]] | None,
|
|
*,
|
|
s: bool,
|
|
a: bool,
|
|
h: bool,
|
|
max_depth: int | None,
|
|
) -> tuple[list[str], int]:
|
|
if s or compute_all is None:
|
|
total = await compute_total(p0)
|
|
return [_format_size(total, h) + "\t" + p0.raw_path], total
|
|
all_entries = await compute_all(p0)
|
|
if not all_entries:
|
|
total = await compute_total(p0)
|
|
return [_format_size(total, h) + "\t" + p0.raw_path], total
|
|
if not a:
|
|
all_entries = [(p, sz) for p, sz in all_entries if p == p0.virtual]
|
|
if max_depth is not None:
|
|
all_entries = [(p, sz) for p, sz in all_entries
|
|
if _depth(p, p0.virtual) <= max_depth]
|
|
if not all_entries:
|
|
total = await compute_total(p0)
|
|
return [_format_size(total, h) + "\t" + p0.raw_path], total
|
|
lines = [_format_size(sz, h) + "\t" + p for p, sz in all_entries]
|
|
return lines, sum(sz for _, sz in all_entries)
|
|
|
|
|
|
async def du_multi(
|
|
paths: list[PathSpec],
|
|
*,
|
|
compute_total: Callable[[PathSpec], Awaitable[int]],
|
|
compute_all: Callable[[PathSpec], Awaitable[list[tuple[str, int]]]]
|
|
| None = None,
|
|
h: bool = False,
|
|
s: bool = False,
|
|
a: bool = False,
|
|
max_depth: int | None = None,
|
|
c: bool = False,
|
|
) -> bytes:
|
|
lines: list[str] = []
|
|
totals: list[int] = []
|
|
for p0 in paths:
|
|
block, total = await _du_block(p0,
|
|
compute_total,
|
|
compute_all,
|
|
s=s,
|
|
a=a,
|
|
h=h,
|
|
max_depth=max_depth)
|
|
lines.extend(block)
|
|
totals.append(total)
|
|
if c:
|
|
lines.append(_format_size(sum(totals), h) + "\ttotal")
|
|
return format_records(lines)
|