2015-12-03 06:09:29 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
2015-12-08 07:04:07 +01:00
|
|
|
import yaml
|
2015-12-08 09:28:54 +01:00
|
|
|
import shutil
|
2015-12-08 07:04:07 +01:00
|
|
|
|
2015-12-08 08:06:39 +01:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
2016-02-18 06:43:28 +01:00
|
|
|
from .cache import CACHE
|
2016-04-18 14:27:28 +02:00
|
|
|
from .utils import error, warning, okgreen
|
2016-02-18 06:43:28 +01:00
|
|
|
|
2016-05-12 02:24:26 +02:00
|
|
|
|
2016-04-18 19:58:43 +02:00
|
|
|
DEFAULTS = {
|
|
|
|
"rss": True,
|
|
|
|
"share": False,
|
|
|
|
"settings": {},
|
2016-02-18 17:00:17 +01:00
|
|
|
"show_date": True,
|
2016-04-18 19:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SETTINGS = {
|
2016-02-18 06:48:05 +01:00
|
|
|
"gm": {
|
|
|
|
"quality": 75,
|
2016-02-18 14:27:13 +01:00
|
|
|
"auto-orient": True,
|
|
|
|
"strip": True,
|
|
|
|
"resize": None
|
2016-04-29 12:40:34 +02:00
|
|
|
},
|
|
|
|
"ffmpeg": {
|
2016-05-03 09:41:08 +02:00
|
|
|
"binary": "ffmpeg",
|
2016-05-12 12:04:48 +02:00
|
|
|
"loglevel": "error",
|
2016-04-29 12:40:34 +02:00
|
|
|
"format": "webm",
|
|
|
|
"resolution": "1280x720",
|
|
|
|
"bitrate": "3900k",
|
|
|
|
"preselect": "libvpx-720p"
|
2016-02-18 06:48:05 +01:00
|
|
|
}
|
2016-02-17 17:53:30 +01:00
|
|
|
}
|
|
|
|
|
2016-04-29 15:55:14 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
class Video(object):
|
|
|
|
base_dir = ""
|
|
|
|
target_dir = ""
|
|
|
|
|
|
|
|
def __init__(self, options):
|
2016-05-12 02:30:49 +02:00
|
|
|
error(SETTINGS["ffmpeg"] is not False, "I couldn't find a binary to convert video and I ask to do so, abort")
|
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
# assuming string
|
|
|
|
if not isinstance(options, dict):
|
2016-05-06 09:37:24 +02:00
|
|
|
options = {"name": options}
|
2016-04-29 15:55:14 +02:00
|
|
|
# used for caching, if it's modified -> regenerate
|
|
|
|
self.options = SETTINGS["ffmpeg"].copy()
|
2016-04-29 12:40:34 +02:00
|
|
|
self.options.update(options)
|
2016-04-29 15:55:14 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return self.options["name"]
|
|
|
|
|
|
|
|
def ffmpeg(self, source, target, options):
|
2016-05-04 09:39:35 +02:00
|
|
|
if not CACHE.needs_to_be_generated(source, target, options):
|
2016-04-29 12:40:34 +02:00
|
|
|
okgreen("Skipped", source + " is already generated")
|
2016-05-04 09:39:35 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
ffmpeg_switches = {
|
2016-05-04 09:40:12 +02:00
|
|
|
"source": source,
|
|
|
|
"target": target,
|
|
|
|
"loglevel": "-loglevel %s" % options["loglevel"],
|
|
|
|
"resolution": "-s %s" % options["resolution"],
|
2016-05-12 12:04:35 +02:00
|
|
|
"preselect": "-pre %s" % options["preselect"],
|
2016-05-04 09:40:12 +02:00
|
|
|
"resize": "-vf scale=-1:%s" % options.get("resize"),
|
|
|
|
"bitrate": "-b %s" % options["bitrate"],
|
|
|
|
"format": "-f %s" % options["format"],
|
|
|
|
"binary": "%s" % options["binary"]
|
|
|
|
}
|
2016-05-04 09:39:50 +02:00
|
|
|
|
2016-05-04 09:39:35 +02:00
|
|
|
warning("Generation", source)
|
2016-05-04 09:39:50 +02:00
|
|
|
|
2016-05-04 09:39:35 +02:00
|
|
|
if options.get("resize"):
|
|
|
|
command = "{binary} {loglevel} -i {source} {resize} -vframes 1 -y {target}".format(**ffmpeg_switches)
|
2016-05-12 03:11:38 +02:00
|
|
|
error(os.system(command) == 0, "%s command failed" % ffmpeg_switches["binary"])
|
2016-05-04 09:39:35 +02:00
|
|
|
else:
|
|
|
|
command = "{binary} {loglevel} -i {source} {resolution} {preselect} {bitrate} -pass 1 -an {format} -y {target}".format(**ffmpeg_switches)
|
|
|
|
command2 = "{binary} {loglevel} -i {source} {resolution} {preselect} {bitrate} -pass 2 -acodec libvorbis -ab 100k {format} -y {target}".format(**ffmpeg_switches)
|
2016-05-04 09:41:22 +02:00
|
|
|
print(command)
|
2016-05-12 03:11:38 +02:00
|
|
|
error(os.system(command) == 0, "%s command failed" % ffmpeg_switches["binary"])
|
2016-05-04 09:41:22 +02:00
|
|
|
print(command2)
|
2016-05-12 03:11:38 +02:00
|
|
|
error(os.system(command2) == 0, "%s command failed" % ffmpeg_switches["binary"])
|
2016-05-04 09:39:50 +02:00
|
|
|
|
2016-05-04 09:39:35 +02:00
|
|
|
CACHE.cache_picture(source, target, options)
|
2016-04-29 15:55:14 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
def copy(self):
|
|
|
|
source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, self.name)
|
|
|
|
options = self.options.copy()
|
|
|
|
self.ffmpeg(source, target, options)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def generate_thumbnail(self, gm_geometry):
|
2016-05-04 14:16:15 +02:00
|
|
|
thumbnail_name = ".".join(self.name.split(".")[:-1]) + "-%s.png" % gm_geometry
|
2016-05-04 09:42:42 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, thumbnail_name)
|
2016-05-04 09:42:42 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
options = self.options.copy()
|
|
|
|
options.update({"resize": gm_geometry})
|
2016-05-04 09:42:42 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
self.ffmpeg(source, target, options)
|
2016-05-04 09:42:42 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
return thumbnail_name
|
2016-04-29 15:55:14 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
class Image(object):
|
|
|
|
base_dir = ""
|
|
|
|
target_dir = ""
|
2015-12-11 09:22:36 +01:00
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
def __init__(self, options):
|
|
|
|
# assuming string
|
|
|
|
if not isinstance(options, dict):
|
|
|
|
options = {"name": options}
|
2016-05-04 11:01:02 +02:00
|
|
|
|
2016-02-18 09:05:17 +01:00
|
|
|
self.options = SETTINGS["gm"].copy() # used for caching, if it's modified -> regenerate
|
|
|
|
self.options.update(options)
|
2016-02-15 18:06:00 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-02-18 06:40:56 +01:00
|
|
|
return self.options["name"]
|
2016-02-15 18:06:00 +01:00
|
|
|
|
2016-02-18 14:27:13 +01:00
|
|
|
def gm(self, source, target, options):
|
2016-05-04 09:56:22 +02:00
|
|
|
if not CACHE.needs_to_be_generated(source, target, options):
|
2016-04-18 19:53:58 +02:00
|
|
|
okgreen("Skipped", source + " is already generated")
|
2016-05-04 10:12:18 +02:00
|
|
|
return
|
2016-02-18 14:27:13 +01:00
|
|
|
|
2016-05-04 09:56:22 +02:00
|
|
|
gm_switches = {
|
2016-05-04 09:56:38 +02:00
|
|
|
"source": source,
|
|
|
|
"target": target,
|
|
|
|
"auto-orient": "-auto-orient" if options["auto-orient"] else "",
|
|
|
|
"strip": "-strip" if options["strip"] else "",
|
|
|
|
"quality": "-quality %s" % options["quality"] if "quality" in options else "-define jpeg:preserve-settings",
|
|
|
|
"resize": "-resize %s" % options["resize"] if options.get("resize", None) is not None else ""
|
|
|
|
}
|
2016-05-04 09:56:49 +02:00
|
|
|
|
2016-05-04 09:56:22 +02:00
|
|
|
command = "gm convert {source} {auto-orient} {strip} {quality} {resize} {target}".format(**gm_switches)
|
|
|
|
warning("Generation", source)
|
2016-05-04 09:56:49 +02:00
|
|
|
|
2016-05-04 09:56:22 +02:00
|
|
|
print(command)
|
2016-05-12 02:35:43 +02:00
|
|
|
error(os.system(command) == 0, "gm command failed")
|
2016-05-04 09:56:49 +02:00
|
|
|
|
2016-05-04 09:56:22 +02:00
|
|
|
CACHE.cache_picture(source, target, options)
|
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
def copy(self):
|
|
|
|
source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, self.name)
|
2015-12-11 09:13:52 +01:00
|
|
|
|
|
|
|
# XXX doing this DOESN'T improve perf at all (or something like 0.1%)
|
|
|
|
# if os.path.exists(target) and os.path.getsize(source) == os.path.getsize(target):
|
2016-04-29 15:55:14 +02:00
|
|
|
# print "Skipped %s since the file hasn't been modified based on file size" % source
|
|
|
|
# return ""
|
2016-02-18 14:27:13 +01:00
|
|
|
|
|
|
|
options = self.options.copy()
|
2016-05-04 09:56:49 +02:00
|
|
|
|
2016-02-18 14:27:13 +01:00
|
|
|
if not options["auto-orient"] and not options["strip"]:
|
2016-02-15 16:51:32 +01:00
|
|
|
shutil.copyfile(source, target)
|
2016-05-04 09:57:35 +02:00
|
|
|
print("%s%s%s" % (source, "->", target))
|
2016-02-18 08:29:08 +01:00
|
|
|
else:
|
2016-04-29 12:40:34 +02:00
|
|
|
# Do not consider quality settings here, since we aim to copy the input image
|
2016-04-29 15:55:14 +02:00
|
|
|
# better to preserve input encoding setting
|
|
|
|
del options["quality"]
|
|
|
|
self.gm(source, target, options)
|
2016-05-04 09:55:19 +02:00
|
|
|
|
2015-12-08 09:29:38 +01:00
|
|
|
return ""
|
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
def generate_thumbnail(self, gm_geometry):
|
2016-05-11 18:02:18 +02:00
|
|
|
thumbnail_name = ".".join(self.name.split(".")[:-1]) + "-" + gm_geometry + "." + self.name.split(".")[-1]
|
2016-05-04 09:57:56 +02:00
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, thumbnail_name)
|
2016-05-04 09:57:56 +02:00
|
|
|
|
2016-02-18 14:27:13 +01:00
|
|
|
options = self.options.copy()
|
|
|
|
options.update({"resize": gm_geometry})
|
2016-05-04 09:57:56 +02:00
|
|
|
|
2016-02-18 14:27:13 +01:00
|
|
|
self.gm(source, target, options)
|
2016-05-04 09:57:56 +02:00
|
|
|
|
2015-12-09 07:05:48 +01:00
|
|
|
return thumbnail_name
|
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return self.name
|
|
|
|
|
2015-12-08 09:29:38 +01:00
|
|
|
|
2015-12-08 07:28:57 +01:00
|
|
|
def main():
|
2016-05-03 10:05:49 +02:00
|
|
|
settings = yaml.safe_load(open("settings.yaml", "r"))
|
2016-05-04 09:59:05 +02:00
|
|
|
|
2016-05-03 10:05:49 +02:00
|
|
|
if settings["settings"].get("ffmpeg"):
|
|
|
|
SETTINGS["ffmpeg"].update(settings["settings"]["ffmpeg"])
|
2016-05-04 09:59:05 +02:00
|
|
|
|
2016-05-03 10:05:49 +02:00
|
|
|
conv_video = settings["settings"]["ffmpeg"]["binary"]
|
|
|
|
else:
|
|
|
|
conv_video = "ffmpeg"
|
|
|
|
|
2016-05-04 10:43:22 +02:00
|
|
|
error(os.system("which gm > /dev/null") == 0, "I can't locate the gm binary, "
|
|
|
|
"please install the 'graphicsmagick' package.\n")
|
|
|
|
|
|
|
|
if os.system("which " + conv_video +" > /dev/null") != 0:
|
2016-05-04 10:45:26 +02:00
|
|
|
if conv_video == "ffmpeg" and os.system("which avconv > /dev/null") == 0:
|
|
|
|
SETTINGS["ffmpeg"]["binary"] = "avconv"
|
2016-05-11 13:31:42 +02:00
|
|
|
warning("Video", "I couldn't locate ffmpeg but I could find avconv, switching to avconv for video conversion")
|
2016-05-04 10:45:26 +02:00
|
|
|
else:
|
2016-05-11 13:31:42 +02:00
|
|
|
warning("Video", "I can't locate the "+ conv_video +" binary, "
|
2016-05-04 10:45:26 +02:00
|
|
|
"please install the '" + conv_video + "' package.\n")
|
2016-05-11 13:31:42 +02:00
|
|
|
warning("Video", "I won't be able to encode video and I will stop if I encounter a video to convert")
|
2016-05-04 10:45:26 +02:00
|
|
|
SETTINGS["ffmpeg"] = False
|
2015-12-09 06:57:53 +01:00
|
|
|
|
2016-04-18 19:54:18 +02:00
|
|
|
error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a "
|
2016-04-29 15:55:14 +02:00
|
|
|
"settings.yaml in the current working directory")
|
2015-12-08 07:28:57 +01:00
|
|
|
|
2016-05-04 10:02:22 +02:00
|
|
|
error(isinstance(settings, dict), "Your settings.yaml should be a dict")
|
2015-12-08 07:04:07 +01:00
|
|
|
|
2016-04-18 19:58:43 +02:00
|
|
|
for key, value in DEFAULTS.items():
|
|
|
|
if key not in settings:
|
|
|
|
settings[key] = value
|
|
|
|
|
|
|
|
error(settings.get("title"), "You need to specify a title in your main settings.yaml")
|
2016-04-18 19:45:10 +02:00
|
|
|
|
2016-04-18 20:00:32 +02:00
|
|
|
if (settings["rss"] or settings["share"]) and not settings.get("url"):
|
|
|
|
warning("warning", "If you want the rss and/or the social network share to work, "
|
2016-04-29 12:40:34 +02:00
|
|
|
"you need to specify the website url in root settings")
|
2016-04-18 20:00:32 +02:00
|
|
|
settings["rss"] = False
|
|
|
|
settings["share"] = False
|
2016-02-18 06:39:49 +01:00
|
|
|
|
2016-04-18 19:58:43 +02:00
|
|
|
if settings["settings"].get("gm"):
|
2016-02-18 06:48:05 +01:00
|
|
|
SETTINGS["gm"].update(settings["settings"]["gm"])
|
2016-02-18 06:39:49 +01:00
|
|
|
|
2015-12-08 07:34:55 +01:00
|
|
|
front_page_galleries_cover = []
|
2015-12-08 07:18:41 +01:00
|
|
|
|
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()))
|
|
|
|
|
2016-04-18 21:07:12 +02:00
|
|
|
error(dirs, "I can't find at least one directory with a settings.yaml in the current working "
|
2016-04-29 15:55:14 +02:00
|
|
|
"directory (NOT the settings.yaml in your current directory, but one INSIDE A "
|
|
|
|
"DIRECTORY in your current working directory), you don't have any gallery?")
|
2015-12-08 07:34:55 +01:00
|
|
|
|
2015-12-08 09:28:54 +01:00
|
|
|
if not os.path.exists("build"):
|
|
|
|
os.makedirs("build")
|
|
|
|
|
2016-04-18 19:58:43 +02:00
|
|
|
theme = settings["settings"].get("theme", "exposure")
|
2016-04-18 19:40:48 +02:00
|
|
|
|
2016-04-18 19:54:18 +02:00
|
|
|
theme_path = os.path.exists(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme))
|
|
|
|
available_themes = theme, "', '".join(os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes")))
|
|
|
|
|
|
|
|
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % (available_themes))
|
|
|
|
|
2016-05-01 16:23:23 +02:00
|
|
|
templates_dir = [
|
|
|
|
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
|
|
|
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
|
|
|
]
|
2016-04-18 19:54:18 +02:00
|
|
|
|
2016-05-01 16:23:23 +02:00
|
|
|
if theme != "exposure":
|
|
|
|
templates_dir.append(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", "exposure", "templates"))
|
|
|
|
|
|
|
|
templates = Environment(loader=FileSystemLoader(templates_dir))
|
2016-02-23 06:00:57 +01:00
|
|
|
|
2016-02-23 05:57:46 +01:00
|
|
|
index_template = templates.get_template("index.html")
|
|
|
|
gallery_index_template = templates.get_template("gallery-index.html")
|
|
|
|
page_template = templates.get_template("page.html")
|
2016-04-18 14:27:28 +02:00
|
|
|
feed_template = templates.get_template("feed.xml")
|
2016-02-23 05:57:46 +01:00
|
|
|
|
2015-12-08 09:28:54 +01:00
|
|
|
# XXX recursively merge directories
|
2015-12-09 09:03:18 +01:00
|
|
|
if os.path.exists(os.path.join(os.getcwd(), "build", "static")):
|
|
|
|
shutil.rmtree(os.path.join(os.getcwd(), "build", "static"))
|
2016-02-23 05:57:46 +01:00
|
|
|
|
|
|
|
if os.path.exists(os.path.join(os.getcwd(), "static")):
|
2016-02-19 17:39:17 +01:00
|
|
|
shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", "static"))
|
|
|
|
else:
|
2016-02-23 05:57:46 +01:00
|
|
|
shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static"), os.path.join(os.getcwd(), "build", "static"))
|
2015-12-08 09:28:54 +01:00
|
|
|
|
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")))
|
2016-02-16 08:41:53 +01:00
|
|
|
|
2016-02-13 11:21:51 +01:00
|
|
|
if gallery_settings.get("public", True):
|
2016-04-18 19:54:18 +02:00
|
|
|
error(gallery_settings.get("title"), "Your gallery describe in %s need to have a "
|
2016-04-29 15:55:14 +02:00
|
|
|
"title" % (os.path.join(gallery, "settings.yaml")))
|
2016-04-18 19:54:18 +02:00
|
|
|
error(gallery_settings.get("cover"), "You should specify a path to a cover picture "
|
2016-04-29 15:55:14 +02:00
|
|
|
"in %s" % (os.path.join(gallery, "settings.yaml")))
|
2016-05-04 10:04:50 +02:00
|
|
|
|
2016-05-12 02:16:06 +02:00
|
|
|
if isinstance(gallery_settings["cover"], dict):
|
|
|
|
cover_image_path = os.path.join(gallery, gallery_settings["cover"]["name"])
|
|
|
|
cover_image_type = gallery_settings["cover"]["type"]
|
|
|
|
else:
|
|
|
|
cover_image_path = os.path.join(gallery, gallery_settings["cover"])
|
|
|
|
cover_image_type = "image"
|
2016-05-04 10:04:50 +02:00
|
|
|
|
2016-04-18 19:54:18 +02:00
|
|
|
error(os.path.exists(cover_image_path), "File for %s cover image doesn't exist at "
|
2016-04-29 15:55:14 +02:00
|
|
|
"%s" % (gallery, cover_image_path))
|
2015-12-08 08:22:08 +01:00
|
|
|
|
2015-12-10 01:45:42 +01:00
|
|
|
front_page_galleries_cover.append({
|
2016-02-16 08:43:46 +01:00
|
|
|
"title": gallery_settings["title"],
|
2015-12-10 01:45:42 +01:00
|
|
|
"link": gallery,
|
2016-02-16 08:43:46 +01:00
|
|
|
"sub_title": gallery_settings.get("sub_title", ""),
|
|
|
|
"date": gallery_settings.get("date", ""),
|
|
|
|
"tags": gallery_settings.get("tags", ""),
|
2016-05-12 02:16:06 +02:00
|
|
|
"cover_type": cover_image_type,
|
2015-12-10 01:45:42 +01:00
|
|
|
"cover": cover_image_path,
|
2016-05-04 10:03:18 +02:00
|
|
|
})
|
2015-12-08 07:11:55 +01:00
|
|
|
|
2016-05-04 14:19:46 +02:00
|
|
|
if not os.path.exists(os.path.join("build", gallery)):
|
|
|
|
os.makedirs(os.path.join("build", gallery))
|
2015-12-08 08:41:02 +01:00
|
|
|
|
2016-02-09 07:31:37 +01:00
|
|
|
# this should probably be a factory
|
|
|
|
Image.base_dir = os.path.join(os.getcwd(), gallery)
|
|
|
|
Image.target_dir = os.path.join(os.getcwd(), "build", gallery)
|
2016-05-04 10:09:45 +02:00
|
|
|
|
2016-04-29 12:40:34 +02:00
|
|
|
Video.base_dir = os.path.join(os.getcwd(), gallery)
|
|
|
|
Video.target_dir = os.path.join(os.getcwd(), "build", gallery)
|
2016-02-16 08:41:53 +01:00
|
|
|
|
2016-02-16 08:47:54 +01:00
|
|
|
template_to_render = page_template if gallery_settings.get("static") else gallery_index_template
|
2016-05-04 10:07:34 +02:00
|
|
|
|
|
|
|
index_html = open(os.path.join("build", gallery, "index.html"), "w")
|
|
|
|
|
|
|
|
index_html.write(template_to_render.render(
|
|
|
|
settings=settings,
|
|
|
|
gallery=gallery_settings,
|
|
|
|
Image=Image,
|
|
|
|
Video=Video,
|
|
|
|
link=gallery
|
|
|
|
).encode("Utf-8"))
|
2016-04-18 19:40:48 +02:00
|
|
|
|
2016-05-12 20:44:23 +02:00
|
|
|
if settings["rss"]:
|
|
|
|
feed_xml = open(os.path.join("build", "feed.xml"), "w")
|
|
|
|
|
|
|
|
feed_xml.write(feed_template.render(
|
|
|
|
settings=settings,
|
|
|
|
galleries=reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"]))
|
|
|
|
).encode("Utf-8"))
|
2015-12-08 08:07:24 +01:00
|
|
|
|
2015-12-10 00:51:21 +01:00
|
|
|
front_page_galleries_cover = reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"]))
|
2015-12-08 06:55:01 +01:00
|
|
|
|
2016-02-16 08:49:03 +01:00
|
|
|
# this should probably be a factory
|
2016-02-09 07:31:37 +01:00
|
|
|
Image.base_dir = os.getcwd()
|
|
|
|
Image.target_dir = os.path.join(os.getcwd(), "build")
|
2016-05-11 17:59:16 +02:00
|
|
|
|
2016-05-04 15:38:11 +02:00
|
|
|
Video.base_dir = os.getcwd()
|
|
|
|
Video.target_dir = os.path.join(os.getcwd(), "build")
|
2016-02-09 07:31:37 +01:00
|
|
|
|
2016-05-04 10:08:31 +02:00
|
|
|
index_html = open(os.path.join("build", "index.html"), "w")
|
|
|
|
|
|
|
|
index_html.write(index_template.render(
|
|
|
|
settings=settings,
|
|
|
|
galleries=front_page_galleries_cover,
|
2016-05-04 15:38:11 +02:00
|
|
|
Image=Image,
|
|
|
|
Video=Video
|
2016-05-04 10:08:31 +02:00
|
|
|
).encode("Utf-8"))
|
2016-02-09 07:31:37 +01:00
|
|
|
|
2015-12-08 10:42:00 +01:00
|
|
|
|
2015-12-08 06:55:01 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|