77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
import sys
|
|
import os
|
|
from progress.bar import Bar
|
|
from jinja2 import Environment, FileSystemLoader
|
|
import subprocess
|
|
import time
|
|
|
|
def argument_parsing():
|
|
if (len(sys.argv) < 2):
|
|
print("error: missing argument", file=sys.stderr)
|
|
exit(1)
|
|
return sys.argv[1]
|
|
|
|
def get_exif(folder: str, raw: str):
|
|
absolut_path = os.path.join(folder, "exif.txt")
|
|
if os.path.exists(absolut_path):
|
|
return absolut_path
|
|
if os.system(f"exiftool {raw} > {absolut_path} 2>/dev/null") == 0:
|
|
return absolut_path
|
|
os.remove(absolut_path)
|
|
return None
|
|
|
|
def get_images(files):
|
|
images_datas: list[str] = []
|
|
images: list[str] = [file for file in files if os.path.isfile(file) and file.endswith(".png")]
|
|
for image in images:
|
|
export_data_file: str = image + ".out.pp3"
|
|
if (os.path.exists(export_data_file) and os.path.isfile(export_data_file)):
|
|
images_datas.append((image, export_data_file))
|
|
images_datas.append((image,))
|
|
return images_datas
|
|
|
|
def get_updated_folders(path: str):
|
|
updated_folders: list[str] = []
|
|
for element_name in os.listdir(path):
|
|
absolut_path: str = os.path.join(path, element_name)
|
|
if not os.path.isdir(absolut_path):
|
|
continue
|
|
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(absolut_path)
|
|
folder_modified_date = time.ctime(mtime)
|
|
html_path: str = os.path.join(absolut_path, f"{element_name}.html")
|
|
if not os.path.exists(html_path):
|
|
updated_folders.append(absolut_path)
|
|
continue
|
|
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(absolut_path)
|
|
html_modified_date = time.ctime(mtime)
|
|
if (html_modified_date < folder_modified_date):
|
|
updated_folders.append(absolut_path)
|
|
continue
|
|
|
|
return updated_folders
|
|
|
|
def get_readme(folder):
|
|
absolut_path: str = os.path.join(folder, "readme.md")
|
|
if (os.path.exists(absolut_path)):
|
|
return absolut_path
|
|
return None
|
|
|
|
def gen_pages(folders: list[str]):
|
|
with Bar("generating...", max=len(folders)) as bar:
|
|
for folder in folders:
|
|
files: list[str] = [os.path.join(folder, file) for file in os.listdir(folder)]
|
|
images: list[str] = get_images(files)
|
|
raws: list[str] = [file for file in files if file.endswith(".NEF")]
|
|
raw: str = raws[0] if len(raws) > 0 else None
|
|
exif: str = get_exif(folder, raw)
|
|
readme: str = get_readme(folder)
|
|
bar.next()
|
|
|
|
def main():
|
|
site_path: str = argument_parsing()
|
|
folders = get_updated_folders(site_path)
|
|
gen_pages(folders)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |