magcms/prosopopoee

64 lines
2.5 KiB
Plaintext
Raw Normal View History

2015-12-03 06:09:29 +01:00
#!/usr/bin/env python
import os
2015-12-08 06:57:17 +01:00
import sys
2015-12-08 07:04:07 +01:00
import yaml
2015-12-08 07:34:55 +01:00
from dateutil.parser import parse
from jinja2 import Environment, FileSystemLoader
templates = Environment(loader=FileSystemLoader([os.path.realpath(os.path.join(os.getcwd(), "templates")), os.path.join(os.path.split(os.path.realpath(__file__))[0], "templates")]))
index_template = templates.get_template("index.html")
gallery_index_template = templates.get_template("gallery-index.html")
2015-12-08 07:04:07 +01:00
2015-12-08 07:28:57 +01:00
def error(test, error_message):
if not test:
sys.stderr.write(error_message)
sys.stderr.write("\n")
2015-12-08 08:06:47 +01:00
sys.stderr.write("Abort.\n")
2015-12-08 06:57:17 +01:00
sys.exit(1)
2015-12-08 07:28:57 +01:00
def main():
2015-12-08 08:06:47 +01:00
error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a settings.yaml in the current working directory")
2015-12-08 07:28:57 +01:00
2015-12-08 07:36:17 +01:00
settings = yaml.safe_load(open("settings.yaml", "r"))
2015-12-08 07:04:07 +01:00
2015-12-08 07:28:57 +01:00
error(isinstance(settings, dict), "Your settings.yaml should be a dict")
error(settings.get("title"), "You should specify a title in your main settings.yaml")
2015-12-08 07:26:55 +01:00
title = settings["title"]
sub_title = settings.get("sub_title", "")
2015-12-08 07:34:55 +01:00
front_page_galleries_cover = []
2015-12-08 07:11:55 +01:00
dirs = filter(lambda x: x not in (".", "..") and os.path.isdir(x) and os.path.exists(os.path.join(os.getcwd(), x, "settings.yaml")), os.listdir(os.getcwd()))
2015-12-08 08:06:47 +01:00
error(dirs, "I can't find at least one directory with a settings.yaml in the current working directory, you don't have any gallery?")
2015-12-08 07:34:55 +01:00
for gallery in dirs:
2015-12-08 08:06:47 +01:00
gallery_settings = yaml.safe_load(open(os.path.join(os.getcwd(), gallery, "settings.yaml"), "r"))
2015-12-08 07:34:55 +01:00
2015-12-08 08:06:47 +01:00
error(isinstance(gallery_settings, dict), "Your %s should be a dict" % (os.path.join(gallery, "settings.yaml")))
2015-12-08 07:34:55 +01:00
error(gallery_settings.get("title"), "You should specify a title in %s" % (os.path.join(gallery, "settings.yaml")))
error(gallery_settings.get("cover"), "You should specify a path to a cover picture in %s" % (os.path.join(gallery, "settings.yaml")))
gallery_title = gallery_settings["title"]
gallery_sub_title = gallery_settings.get("sub_title", "")
gallery_date = parse(gallery_settings["date"]) if "date" in gallery_settings else ""
2015-12-08 07:34:55 +01:00
front_page_galleries_cover.append({
"title": gallery_title,
"sub_title": gallery_sub_title,
"date": gallery_date,
})
2015-12-08 07:11:55 +01:00
2015-12-08 08:07:24 +01:00
front_page_galleries_cover = sorted(front_page_galleries_cover, key=lambda x: x["date"])
2015-12-08 06:55:01 +01:00
if not os.path.exists("build"):
os.makedirs("build")
if __name__ == '__main__':
main()