diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-11-29 01:22:50 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-11-29 01:22:50 -0600 |
commit | 655e3c6fb7b13659e15b30e96b6c943d48170a71 (patch) | |
tree | 07b6718f99f95edb99a5a251678de74ffbda5174 /src/pyssg/database_entry.py | |
parent | 98bfded1b407431ad62642d7f029e4e5f3534c07 (diff) |
refactor database entries into its own class
Diffstat (limited to 'src/pyssg/database_entry.py')
-rw-r--r-- | src/pyssg/database_entry.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/pyssg/database_entry.py b/src/pyssg/database_entry.py new file mode 100644 index 0000000..3fec92a --- /dev/null +++ b/src/pyssg/database_entry.py @@ -0,0 +1,47 @@ +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 = [] + else: + self.tags = entry[4].split(',') + + log.debug('tag content: [%s]', ', '.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 + + + 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 '-'] + + + def update_tags(self, new_tags: list[str]) -> None: + self.tags = new_tags |