summaryrefslogtreecommitdiff
path: root/src/pyssg/database_entry.py
blob: 90c3f5f6d2469cee0c169afc59d1256e4feb0c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from typing import Union
from logging import Logger, getLogger

log: Logger = getLogger(__name__)


class DatabaseEntry:
    # not specifying the type of "list" as it could be only str
    #   or the actual values
    def __init__(self, entry: list) -> None:
        self.fname: str = entry[0]
        self.ctimestamp: float = float(entry[1])
        self.mtimestamp: float = float(entry[2])
        self.checksum: str = entry[3]
        self.tags: list[str] = []

        if isinstance(entry[4], list):
            self.tags = entry[4]
        else:
            if entry[4] != '-':
                self.tags = entry[4].split(',')

        log.debug('"%s" tag: [%s]', self.fname, ', '.join(self.tags))

    def __str__(self) -> str:
        _return_str: str = '[{}, {}, {}, {}, [{}]]'\
            .format(self.fname,
                    self.ctimestamp,
                    self.mtimestamp,
                    self.checksum,
                    ', '.join(self.tags))
        return _return_str

    # used for csv writing
    def get_raw_entry(self) -> list[str]:
        return [self.fname,
                str(self.ctimestamp),
                str(self.mtimestamp),
                self.checksum,
                ','.join(self.tags) if self.tags else '-']

    # TODO: make the function return true/false if updated
    def update_tags(self, new_tags: list[str]) -> None:
        self.tags = new_tags