feat: add archive client foundation
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Archive client command-line entry point."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
|
||||
from archive_clients.config import ClientConfig
|
||||
from archive_clients.daemon import ArchiveClientDaemon
|
||||
from archive_clients.probes import probe_root
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(prog="archive-client")
|
||||
parser.add_argument("--config", type=Path, required=True)
|
||||
parser.add_argument("--mode", choices=("archive", "cache"))
|
||||
parser.add_argument("--check-config", action="store_true")
|
||||
arguments = parser.parse_args(argv)
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
||||
config = ClientConfig.load(arguments.config, arguments.mode)
|
||||
probes = [
|
||||
probe_root(config.qbittorrent.local_root),
|
||||
probe_root(config.syncthing.local_root),
|
||||
]
|
||||
config.read_shared_token()
|
||||
config.qbittorrent.read_password()
|
||||
config.syncthing.read_api_key()
|
||||
if arguments.check_config:
|
||||
print(json.dumps({
|
||||
"client_id": config.client_id,
|
||||
"role": config.role,
|
||||
"filesystems": [probe.__dict__ | {"root": str(probe.root)} for probe in probes],
|
||||
}, sort_keys=True))
|
||||
return 0
|
||||
asyncio.run(ArchiveClientDaemon(config, probes).run())
|
||||
return 0
|
||||
Reference in New Issue
Block a user