-
Notifications
You must be signed in to change notification settings - Fork 13
/
recreate_v4_files_listing.py
executable file
·60 lines (47 loc) · 1.57 KB
/
recreate_v4_files_listing.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""Regenerate v4_files_listing.txt ."""
from __future__ import annotations
from pathlib import Path
REPO_MAIN_DIRPATH = Path(__file__).resolve().parent
V4_DIR = REPO_MAIN_DIRPATH / "images" / "v4"
V4_LISTFILE_NAME = "v4_files_listing.txt"
V4_LISTFILE_PATH = REPO_MAIN_DIRPATH / V4_LISTFILE_NAME
def get_v4_imagefile_names(
search_dirpath: Path = V4_DIR,
filespec: str = "*.png",
) -> list[str]:
"""Return a list of the current image files in the v4 subdirectory.
Parameters
----------
search_dirpath : Path
The directory to search for files.
filespec : str
The glob string to search for.
Returns
-------
list[str]
The names of the files found in the search directory.
"""
file_paths = search_dirpath.glob(filespec)
return [file_path.name for file_path in file_paths]
def create_v4_images_listfile(
search_dirpath: Path = V4_DIR,
filespec: str = "*.png",
output_filepath: Path = V4_LISTFILE_PATH,
) -> None:
"""Create a listfile of the current image files in the v4 subdirectory.
Parameters
----------
search_dirpath : Path
The directory to search for files.
filespec : str
The glob string to search for.
output_filepath : Path
The file to write the list of file names to.
"""
file_names = get_v4_imagefile_names(search_dirpath, filespec)
with output_filepath.open("w") as f_out:
for file_name in sorted(file_names):
f_out.write(f"{file_name}\n")
if __name__ == "__main__":
create_v4_images_listfile()