From f8580c790029459a56c7694e61f43bc5a8a5b3e9 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 23 Feb 2016 05:57:46 +0100 Subject: [PATCH] [enh] simplify a lot theme handling --- prosopopee/prosopopee.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 4021661..5bb31f6 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -10,11 +10,6 @@ from jinja2 import Environment, FileSystemLoader from .cache import CACHE from .utils import error -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") -page_template = templates.get_template("page.html") - SETTINGS = { "show_date": True, "gm": { @@ -115,22 +110,22 @@ def main(): if not os.path.exists("build"): os.makedirs("build") + theme = settings.get("settings", {}).get("theme", "exposure") + + templates = Environment(loader=FileSystemLoader([os.path.realpath(os.path.join(os.getcwd(), "templates")), os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")])) + index_template = templates.get_template("index.html") + gallery_index_template = templates.get_template("gallery-index.html") + page_template = templates.get_template("page.html") + # XXX recursively merge directories if os.path.exists(os.path.join(os.getcwd(), "build", "static")): shutil.rmtree(os.path.join(os.getcwd(), "build", "static")) - if settings.get("theme"): - if os.path.exists(os.path.join(os.getcwd(), "templates")): - shutil.rmtree(os.path.join(os.getcwd(), "templates")) - shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", settings.get("theme"), "static"), os.path.join(os.getcwd(), "build", "static")) - shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", settings.get("theme"), "templates"), os.path.join(os.getcwd(), "templates")) - 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") - page_template = templates.get_template("page.html") - elif os.path.exists(os.path.join(os.getcwd(), "static")): + + if os.path.exists(os.path.join(os.getcwd(), "static")): shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", "static")) else: - shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "static"), os.path.join(os.getcwd(), "build", "static")) + print (os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static") + shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static"), os.path.join(os.getcwd(), "build", "static")) for gallery in dirs: gallery_settings = yaml.safe_load(open(os.path.join(os.getcwd(), gallery, "settings.yaml"), "r"))