Coverage for seedboxsync/cli/commands/cmd_clean.py: 100%

15 statements  

« 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 cleaning operations in SeedboxSync.""" 

8 

9import click 

10from seedboxsync.core.dao import Download 

11 

12 

13@click.group("clean", help="Cleaning operations.") 

14def cli() -> None: 

15 """Empty function for Click sub commands.""" 

16 

17 

18@cli.command("progress", help="Clean the list of files currently in download from seedbox.") 

19def progress() -> None: 

20 """ 

21 Remove all entries of files currently in download. 

22 

23 This command deletes all records from the `Download` table where 

24 the download is not yet finished (`finished == 0`). 

25 

26 Prints the number of deleted entries. 

27 """ 

28 count = Download.delete().where(Download.finished == 0).execute() 

29 click.echo(f"In progress list cleaned. {count} line(s) deleted") 

30 

31 

32@cli.command("downloaded", help="Remove a downloaded file by ID to enable re-download.") 

33@click.argument("id", required=True, type=int) 

34def downloaded(id: int) -> None: # noqa: A002 

35 """ 

36 Remove a downloaded files by its ID. 

37 

38 Allows the user to delete a specific downloaded torrent from 

39 the database, enabling it to be re-downloaded. 

40 

41 Prints a message indicating whether the torrent was removed 

42 or if no matching ID was found. 

43 

44 Args: 

45 id (int): The ID of the downloaded torrent to remove. 

46 """ 

47 count = Download.delete().where(Download.id == id).execute() 

48 if count == 0: 

49 click.echo(f"No downloaded file with id {id}") 

50 else: 

51 click.echo(f"Torrent with id {id} was removed")