Bases: ComicboxArchiveWrite
Calculate page filenames.
Source code in comicbox/box/archive/mtime.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 | class ComicboxArchiveMtime(ComicboxArchiveWrite):
"""Calculate page filenames."""
def _is_comment_json(self, archive: ArchiveType) -> bool:
# Slice, don't index: zipfile hands back a bytes comment and rarfile
# a str one, and indexing bytes yields an int (123) that matches
# neither bracket, so every CBZ comment tested as not-json.
return (
self._config.is_read_comments
and bool(comment := getattr(archive, "comment", ""))
and (comment[:1] in _BRACKETS)
)
def get_path_mtime_dttm(self) -> datetime | None:
"""Get the path mtime as datetime."""
if not self._path_mtime_dttm and self._path:
self._path_mtime_dttm: datetime | None = datetime.fromtimestamp(
self._path.stat().st_mtime, tz=UTC
)
return self._path_mtime_dttm
def get_metadata_files_mtime(self) -> datetime | None:
"""Get the latest metadata archive file mtime according to the read config."""
max_mtime: datetime | None = None
for info in self.infolist():
if ArchiveInfo.is_dir(info):
continue
# filename
filename = ArchiveInfo.filename(info)
if not filename:
continue
path = Path(filename)
if path.name.lower() not in self._config.read_metadata_lower_filenames:
continue
# mtime
mtime = ArchiveInfo.mtime(info)
if not mtime:
mtime = self.get_path_mtime_dttm()
if mtime and (max_mtime is None or (max_mtime < mtime)):
max_mtime = mtime
return max_mtime
def get_metadata_mtime(self) -> datetime | None:
"""Get the latest metadata mtime according to the read config."""
# Ensure the archive is ready.
archive = self._get_archive()
if self._archive_is_pdf or self._is_comment_json(archive):
return self.get_path_mtime_dttm()
return self.get_metadata_files_mtime()
|
Get the latest metadata archive file mtime according to the read config.
Source code in comicbox/box/archive/mtime.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 | def get_metadata_files_mtime(self) -> datetime | None:
"""Get the latest metadata archive file mtime according to the read config."""
max_mtime: datetime | None = None
for info in self.infolist():
if ArchiveInfo.is_dir(info):
continue
# filename
filename = ArchiveInfo.filename(info)
if not filename:
continue
path = Path(filename)
if path.name.lower() not in self._config.read_metadata_lower_filenames:
continue
# mtime
mtime = ArchiveInfo.mtime(info)
if not mtime:
mtime = self.get_path_mtime_dttm()
if mtime and (max_mtime is None or (max_mtime < mtime)):
max_mtime = mtime
return max_mtime
|
Get the latest metadata mtime according to the read config.
Source code in comicbox/box/archive/mtime.py
57
58
59
60
61
62
63
64
65 | def get_metadata_mtime(self) -> datetime | None:
"""Get the latest metadata mtime according to the read config."""
# Ensure the archive is ready.
archive = self._get_archive()
if self._archive_is_pdf or self._is_comment_json(archive):
return self.get_path_mtime_dttm()
return self.get_metadata_files_mtime()
|
get_path_mtime_dttm()
Get the path mtime as datetime.
Source code in comicbox/box/archive/mtime.py
| def get_path_mtime_dttm(self) -> datetime | None:
"""Get the path mtime as datetime."""
if not self._path_mtime_dttm and self._path:
self._path_mtime_dttm: datetime | None = datetime.fromtimestamp(
self._path.stat().st_mtime, tz=UTC
)
return self._path_mtime_dttm
|