Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/test_awc_opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@ def test_recursive_cli_preserves_bank_paths(self):
self.assertEqual(read_wav(out / stem / "00000001.wav")["pcm"], struct.pack("<h", sample))
self.assertEqual(previous.read_bytes(), b"previous export")

def test_cli_bank_limits(self):
src = Path(self.tmp.name) / "banks"
src.mkdir()
fmt = format_block(1, 48000, 0, 1)
for stem in ("second", "first"):
(src / (stem + ".awc")).write_bytes(build_bank([(1, fmt, struct.pack("<h", 42))]))

for limit, expected in ((0, []), (1, ["first"]), (9, ["first", "second"])):
with self.subTest(limit=limit):
out = Path(self.out) / str(limit)
result = subprocess.run([sys.executable, "-I", awc.__file__, src, out, "--limit", str(limit),
"--jobs", "1"], check=True, capture_output=True, text=True)
self.assertIn(f"{len(expected)} banks:", result.stdout)
self.assertEqual(sorted(wav.parent.name for wav in out.glob("*/00000001.wav")), expected)

result = subprocess.run([sys.executable, "-I", awc.__file__, src, self.out, "--limit", "-1"],
capture_output=True, text=True)
self.assertEqual(result.returncode, 2)
self.assertIn("--limit must be non-negative", result.stderr)
self.assertFalse((Path(self.out) / "first").exists())

def test_single_bank_cli_keeps_flat_output(self):
bank, pcm, _ = self.make_bank()
subprocess.run([sys.executable, "-I", awc.__file__, bank, self.out, "--jobs", "1"],
Expand Down
7 changes: 5 additions & 2 deletions tools/awc_opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,12 @@ def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("src")
ap.add_argument("out")
ap.add_argument("--limit", type=int)
ap.add_argument("--limit", type=int, help="maximum number of banks to export (default: all)")
ap.add_argument("--jobs", type=int, default=max(1, (os.cpu_count() or 2) // 2),
help="banks to export at once (default: half the CPU count)")
a = ap.parse_args()
if a.limit is not None and a.limit < 0:
ap.error("--limit must be non-negative")
if os.path.isdir(a.src):
banks = []
for root, _, files in os.walk(a.src):
Expand All @@ -273,7 +275,8 @@ def main() -> int:
banks.sort()
else:
banks = [(a.src, a.out)]
banks = banks[: a.limit] if a.limit else banks
if a.limit is not None:
banks = banks[:a.limit]
tot = {"opus": 0, "pcm": 0, "other": 0, "music": 0}
jobs = max(1, a.jobs)

Expand Down
Loading