Coverage for seedboxsync/core/dao/download.py: 100%
14 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"""Peewee DAO model for Download."""
9import datetime
10from peewee import AutoField, DateTimeField, IntegerField, TextField
11from seedboxsync.core.dao import SeedboxSyncModel
14class Download(SeedboxSyncModel):
15 """
16 Data Access Object (DAO) representing a file download.
18 This model stores information about a downloaded file, including its path,
19 size on the seedbox and locally, as well as timestamps indicating when
20 the download started and finished.
21 """
23 id = AutoField()
24 path = TextField()
25 seedbox_size = IntegerField()
26 local_size = IntegerField(default=0)
27 started = DateTimeField(default=datetime.datetime.now)
28 finished = DateTimeField(default=0)
30 @staticmethod
31 def is_already_download(filepath: str) -> bool:
32 """
33 Check if a file has already been downloaded.
35 Args:
36 filepath (str): Absolute or relative path to the file.
38 Returns:
39 bool: True if the file was already downloaded (i.e. has a nonzero
40 ``finished`` timestamp), otherwise False.
41 """
42 count = Download.select().where(Download.path == filepath, Download.finished > 0).count()
43 return count != 0