[enh] simplify a lot theme handling

This commit is contained in:
Laurent Peuch 2016-02-23 05:57:46 +01:00
parent 904b1385d1
commit f8580c7900

View File

@ -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"))