|
|
@@ -0,0 +1,48 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
|
import os |
|
|
|
|
|
|
|
from jinja2 import Environment, PackageLoader, select_autoescape |
|
|
|
|
|
|
|
from configuration import THEME |
|
|
|
|
|
|
|
|
|
|
|
PICTURES_DIR_NAME = "photos" |
|
|
|
OUTPUT_DIR_NAME = "output" |
|
|
|
|
|
|
|
|
|
|
|
def list_galleries_in(path): |
|
|
|
return [f for f in os.scandir(path) if f.is_dir()] |
|
|
|
|
|
|
|
|
|
|
|
def generate_output_dir(): |
|
|
|
output_path = os.path.join(os.curdir, OUTPUT_DIR_NAME) |
|
|
|
if not os.path.isdir(output_path): |
|
|
|
os.mkdir(output_path) |
|
|
|
return output_path |
|
|
|
|
|
|
|
|
|
|
|
def generate_index(galleries, output_path): |
|
|
|
index_path = os.path.join(output_path, "index.html") |
|
|
|
|
|
|
|
theme_path = os.path.join(os.curdir, THEME) |
|
|
|
jinja_env = Environment( |
|
|
|
loader=PackageLoader("boop", theme_path), autoescape=select_autoescape(["html"]) |
|
|
|
) |
|
|
|
index_template = jinja_env.get_template("index.html.j2") |
|
|
|
|
|
|
|
with open(index_path, "w") as index_file: |
|
|
|
index_file.write(index_template.render(galleries=galleries)) |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
pictures_folder = os.path.join(os.curdir, PICTURES_DIR_NAME) |
|
|
|
galleries = list_galleries_in(pictures_folder) |
|
|
|
|
|
|
|
if len(galleries) > 0: |
|
|
|
output_path = generate_output_dir() |
|
|
|
generate_index(galleries, output_path) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
main() |