opti: regen only updated folder

This commit is contained in:
starnakin 2025-04-14 13:24:08 +02:00
parent 307c5c4d82
commit 97533dc6d8

View File

@ -3,6 +3,7 @@ import os
from progress.bar import Bar
from jinja2 import Environment, FileSystemLoader
import subprocess
import time
def argument_parsing():
if (len(sys.argv) < 2):
@ -33,12 +34,30 @@ def get_images(files):
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 main():
site_path: str = argument_parsing()
folders: list[str] = [os.path.join(site_path, f) for f in os.listdir(site_path)]
folders = [file for file in folders if os.path.isdir(file)]
folders = get_updated_folders(site_path)
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)]