mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 19:50:57 +05:00
Renames (no functional change, just consistency with the rest of the codebase): - cli/cli_utils.py → cli/cli_util.py - core/host_utils.py → core/host_util.py - core/tag_utils.py → core/tag_util.py - crawls/schedule_utils.py → crawls/schedule_util.py - machine/env_utils.py → machine/env_util.py Functional fixes: - archivebox add --index-only now materializes Snapshot rows synchronously via crawl.create_snapshots_from_urls() instead of just queueing the Crawl and leaving the index empty. The previous behavior broke every test that expected --index-only to populate the index, since the runner is never started in index-only mode. - config/collection.py: add _coerce_from_str_dict as the inverse of _coerce_to_str_dict so JSON-encoded INI values are decoded back to native dict/list types when mirrored into Machine.config (a JSONField). Without this, downstream consumers like MachineEvent / abx-dl get raw JSON strings where they expect dicts. Plus matching admin / middleware / model touch-ups, the registration password_change_form template, and assorted small cleanups the user worked through while validating the deploy path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
103 lines
2.6 KiB
Python
103 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
archivebox machine <action> [--filters]
|
|
|
|
Manage Machine records (system-managed, mostly read-only).
|
|
|
|
Machine records track the host machines where ArchiveBox runs.
|
|
They are created automatically by the system and are primarily for debugging.
|
|
|
|
Actions:
|
|
list - List Machines as JSONL (with optional filters)
|
|
|
|
Examples:
|
|
# List all machines
|
|
archivebox machine list
|
|
|
|
# List machines by hostname
|
|
archivebox machine list --hostname__icontains=myserver
|
|
"""
|
|
|
|
__package__ = "archivebox.cli"
|
|
__command__ = "archivebox machine"
|
|
|
|
import sys
|
|
|
|
import rich_click as click
|
|
from rich import print as rprint
|
|
|
|
from archivebox.cli.cli_util import apply_filters
|
|
|
|
|
|
# =============================================================================
|
|
# LIST
|
|
# =============================================================================
|
|
|
|
|
|
def list_machines(
|
|
hostname__icontains: str | None = None,
|
|
os_platform: str | None = None,
|
|
limit: int | None = None,
|
|
) -> int:
|
|
"""
|
|
List Machines as JSONL with optional filters.
|
|
|
|
Exit codes:
|
|
0: Success (even if no results)
|
|
"""
|
|
from archivebox.misc.jsonl import write_record
|
|
from archivebox.machine.models import Machine
|
|
|
|
is_tty = sys.stdout.isatty()
|
|
|
|
queryset = Machine.objects.all().order_by("-created_at")
|
|
|
|
# Apply filters
|
|
filter_kwargs = {
|
|
"hostname__icontains": hostname__icontains,
|
|
"os_platform": os_platform,
|
|
}
|
|
queryset = apply_filters(queryset, filter_kwargs, limit=limit)
|
|
|
|
count = 0
|
|
for machine in queryset:
|
|
if is_tty:
|
|
rprint(f"[cyan]{machine.hostname:30}[/cyan] [dim]{machine.os_platform:10}[/dim] {machine.id}")
|
|
else:
|
|
write_record(machine.to_json())
|
|
count += 1
|
|
|
|
rprint(f"[dim]Listed {count} machines[/dim]", file=sys.stderr)
|
|
return 0
|
|
|
|
|
|
# =============================================================================
|
|
# CLI Commands
|
|
# =============================================================================
|
|
|
|
|
|
@click.group()
|
|
def main():
|
|
"""Manage Machine records (read-only, system-managed)."""
|
|
pass
|
|
|
|
|
|
@main.command("list")
|
|
@click.option("--hostname__icontains", help="Filter by hostname contains")
|
|
@click.option("--os-platform", help="Filter by OS platform")
|
|
@click.option("--limit", "-n", type=int, help="Limit number of results")
|
|
def list_cmd(hostname__icontains: str | None, os_platform: str | None, limit: int | None):
|
|
"""List Machines as JSONL."""
|
|
sys.exit(
|
|
list_machines(
|
|
hostname__icontains=hostname__icontains,
|
|
os_platform=os_platform,
|
|
limit=limit,
|
|
),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|