add: regen parameter

This commit is contained in:
Starnakin 2025-05-06 19:30:42 +02:00
parent b9f7090e96
commit b434d0837a

View File

@ -7,13 +7,15 @@ from path import Path
from picture import Picture
from page import Page
from album import Album
import argparse
import config
def argument_parsing():
if (len(sys.argv) < 2):
print("error: missing argument", file=sys.stderr)
exit(1)
return sys.argv[1]
parser = argparse.ArgumentParser()
parser.add_argument("site_path", help="the folder of your site MUST BE ALWAYS BEFORT PARAMETERS", type=str)
parser.add_argument("-r", '--regen', help="Regenerate (t)thumb (s)small", type=str)
args = parser.parse_args()
return args
def scan_pages(folders: list[Path]) -> list[Page]:
pages: list[Page] = []
@ -82,11 +84,22 @@ def gen_bulk(bulk_path: Path):
shutil.move(os.path.join(album_path.get_absolute_path(), "general.html"), os.path.join(bulk_path.get_absolute_path(), "index.html"))
shutil.copy2("./src/templates/album.css", bulk_path.get_absolute_path())
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):
for page in scan_pages(bulk_path.get_dirs()):
for picture in page.get_pictures():
if is_thumb:
picture.gen_thumb()
if is_small:
picture.gen_small()
def main():
site_path = Path(argument_parsing())
gen_bulk(Path(site_path, "bulk"))
args = argument_parsing()
bulk_path: Path = Path(args.site_path, "bulk")
if args.regen is not None:
regen(bulk_path, 't' in args.regen, 's' in args.regen)
gen_bulk(bulk_path)
if __name__ == "__main__":