Coverage for seedboxsync/cli/commands/cmd_sync.py: 89%
28 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-26 17:46 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-26 17:46 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""All commands related to synchronization operations in SeedboxSync."""
9import click
10from huey.exceptions import TaskLockedException
11from seedboxsync.cli import Context, group, pass_context
12from seedboxsync.core.sync.services import (
13 BLACKHOLE_LOCK_NAME,
14 SEEDBOX_LOCK_NAME,
15 blackhole as blackhole_service,
16 seedbox as seedbox_service,
17)
20@group("sync", help="Run synchronization operations.") # type: ignore[untyped-decorator]
21def cli() -> None:
22 """Empty function for Click sub commands."""
25@cli.command("blackhole", help="Sync torrent from blackhole to seedbox.") # type: ignore[untyped-decorator]
26@click.option(
27 "--dry-run",
28 help="List only, do not upload or persist files.",
29 is_flag=True,
30 default=False,
31)
32@click.option(
33 "-p",
34 "--ping",
35 help="Ping a service (e.g., Healthchecks) during execution.",
36 is_flag=True,
37 default=False,
38)
39@pass_context
40def blackhole(ctx: Context, dry_run: bool, ping: bool) -> None:
41 """
42 Perform the blackhole synchronization.
44 Args:
45 ctx (Context): The Click context object.
46 dry_run (bool): Whether to perform a dry run.
47 ping (bool): Whether to ping a service during execution.
48 """
49 try:
50 with ctx.app.task_manager.lock_task(BLACKHOLE_LOCK_NAME):
51 blackhole_service(dry_run, ping)
52 except TaskLockedException:
53 ctx.app.logger.debug("Blackhole sync already running")
56@cli.command("seedbox", help="Sync files from seedbox.") # type: ignore[untyped-decorator]
57@click.option(
58 "--dry-run",
59 help="List only, do not upload or persist files.",
60 is_flag=True,
61 default=False,
62)
63@click.option(
64 "-p",
65 "--ping",
66 help="Ping a service (e.g., Healthchecks) during execution.",
67 is_flag=True,
68 default=False,
69)
70@click.option(
71 "-o",
72 "--only-store",
73 help="Store the file list only, no download; useful for already synced seedbox.",
74 is_flag=True,
75 default=False,
76)
77@pass_context
78def seedbox(ctx: Context, dry_run: bool, ping: bool, only_store: bool) -> None:
79 """
80 Perform synchronization from the seedbox.
82 Args:
83 ctx (Context): The Click context object.
84 dry_run (bool): Whether to list files without downloading or persisting them.
85 ping (bool): Whether to ping the configured monitoring service.
86 only_store (bool): Whether to record remote files without downloading them.
87 """
88 """
89 Perform the blackhole synchronization.
91 Args:
92 ctx (Context): The Click context object.
93 dry_run (bool): Whether to perform a dry run.
94 ping (bool): Whether to ping a service during execution.
95 """
96 try:
97 with ctx.app.task_manager.lock_task(SEEDBOX_LOCK_NAME):
98 seedbox_service(dry_run, ping, only_store)
99 except TaskLockedException:
100 ctx.app.logger.debug("Seedbox sync already running")