Download tasks/amazon-home-services/environment/reference/clone/ahs_app/reset.py from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/amazon-home-services/environment/reference/clone/ahs_app/reset.py
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/amazon-home-services/environment/reference/clone/ahs_app/reset.py
-
curl -L -o reset.py https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/amazon-home-services/environment/reference/clone/ahs_app/reset.py
1.61 kB
| """Reset one explicitly selected Amazon Home Services test data directory.""" | |
| from __future__ import annotations | |
| import argparse | |
| from pathlib import Path | |
| DATABASE_FILENAME = "amazon-home-services.sqlite3" | |
| def reset_data_dir(data_dir: Path) -> list[Path]: | |
| """Remove only this site's SQLite files from an existing, explicit directory.""" | |
| requested = data_dir.expanduser() | |
| if not requested.is_absolute(): | |
| raise ValueError("--data-dir must be an absolute path") | |
| resolved = requested.resolve(strict=True) | |
| if not resolved.is_dir(): | |
| raise ValueError("--data-dir must name an existing directory") | |
| if resolved == Path(resolved.anchor) or resolved == Path.home().resolve(): | |
| raise ValueError("refusing a broad reset directory") | |
| removed: list[Path] = [] | |
| for suffix in ("", "-wal", "-shm"): | |
| target = resolved / f"{DATABASE_FILENAME}{suffix}" | |
| if target.is_symlink(): | |
| raise ValueError(f"refusing symlinked database artifact: {target.name}") | |
| if target.exists(): | |
| if not target.is_file(): | |
| raise ValueError(f"database artifact is not a file: {target.name}") | |
| target.unlink() | |
| removed.append(target) | |
| return removed | |
| def main() -> int: | |
| parser = argparse.ArgumentParser( | |
| description="Reset only the Amazon Home Services SQLite database in a test data directory." | |
| ) | |
| parser.add_argument("--data-dir", required=True, type=Path) | |
| args = parser.parse_args() | |
| reset_data_dir(args.data_dir) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |