diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index a7fc488..312f39c 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -8,7 +8,7 @@ import shutil from jinja2 import Environment, FileSystemLoader from .cache import CACHE -from .utils import error +from .utils import error, warning, okgreen SETTINGS = { "show_date": True, @@ -47,11 +47,11 @@ class Image(object): } command = "gm convert {source} {auto-orient} {strip} {quality} {resize} {target}".format(**gm_switches) - print command + warning("Generation", source) os.system(command) CACHE.cache_picture(source, target, options) else: - print "skipped %s since it's already generated (based on source unchanged size and images options set in your gallery's settings.yaml)" % target + okgreen("Skipped", source + "it's already generated") def copy(self): source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, self.name) @@ -97,6 +97,8 @@ def main(): 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") + if settings.get("rss") or settings.get("share"): + error(settings.get("url"), "If you want the rss and the social network share work, you should specify url in main settings") if settings.get("settings", {}).get("gm"): SETTINGS["gm"].update(settings["settings"]["gm"]) @@ -114,13 +116,14 @@ def main(): os.makedirs("build") theme = settings.get("settings", {}).get("theme", "exposure") - + error(os.path.exists(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme)), "'%s' is not an existing theme, available themes are '%s'" % (theme, "', '".join(os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes"))))) 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") + feed_template = templates.get_template("feed.xml") # XXX recursively merge directories if os.path.exists(os.path.join(os.getcwd(), "build", "static")): @@ -161,6 +164,9 @@ def main(): template_to_render = page_template if gallery_settings.get("static") else gallery_index_template open(os.path.join("build", gallery, "index.html"), "w").write(template_to_render.render(settings=settings, gallery=gallery_settings, Image=Image, link=gallery).encode("Utf-8")) + + if settings.get("rss"): + open(os.path.join("build", "feed.xml"), "w").write(feed_template.render(settings=settings, link=gallery, galleries=reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"]))).encode("Utf-8")) front_page_galleries_cover = reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"])) diff --git a/prosopopee/themes/exposure/templates/base.html b/prosopopee/themes/exposure/templates/base.html index d98e3d4..3f11aa9 100644 --- a/prosopopee/themes/exposure/templates/base.html +++ b/prosopopee/themes/exposure/templates/base.html @@ -4,7 +4,9 @@ {% block css %} {% endblock %} - + {% if settings.rss -%} + + {% endif -%} {{ settings.title }} diff --git a/prosopopee/themes/exposure/templates/feed.xml b/prosopopee/themes/exposure/templates/feed.xml new file mode 100644 index 0000000..0d685fe --- /dev/null +++ b/prosopopee/themes/exposure/templates/feed.xml @@ -0,0 +1,23 @@ + + + + {{ settings.title }} + {{ settings.sub_title }} + {{ settings.url }} + + + {% for gallery in galleries %} + {% set absolute_url = settings.url + "/" + gallery.link -%} + + {{ gallery.title }} + {{ absolute_url }} + {{ gallery.link }} + {% if gallery.sub_title -%} + {{ gallery.sub_title }} + {% endif -%} + {{ gallery.date }} + + {% endfor %} + + + diff --git a/prosopopee/themes/material/templates/base.html b/prosopopee/themes/material/templates/base.html index 35f0c7f..14adb8d 100644 --- a/prosopopee/themes/material/templates/base.html +++ b/prosopopee/themes/material/templates/base.html @@ -4,7 +4,9 @@ {% block css %} {% endblock %} - + {% if settings.rss -%} + + {% endif -%} {{ settings.title }} diff --git a/prosopopee/themes/material/templates/feed.xml b/prosopopee/themes/material/templates/feed.xml new file mode 100644 index 0000000..0d685fe --- /dev/null +++ b/prosopopee/themes/material/templates/feed.xml @@ -0,0 +1,23 @@ + + + + {{ settings.title }} + {{ settings.sub_title }} + {{ settings.url }} + + + {% for gallery in galleries %} + {% set absolute_url = settings.url + "/" + gallery.link -%} + + {{ gallery.title }} + {{ absolute_url }} + {{ gallery.link }} + {% if gallery.sub_title -%} + {{ gallery.sub_title }} + {% endif -%} + {{ gallery.date }} + + {% endfor %} + + + diff --git a/prosopopee/utils.py b/prosopopee/utils.py index aab9762..7f2adc8 100644 --- a/prosopopee/utils.py +++ b/prosopopee/utils.py @@ -1,11 +1,24 @@ import sys +class bcolors: + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + def error(test, error_message): if test: return - sys.stderr.write(error_message) + sys.stderr.write(bcolors.FAIL + "Abort : " + bcolors.ENDC + error_message) sys.stderr.write("\n") - sys.stderr.write("Abort.\n") sys.exit(1) + +def warning(logging, warning_message): + sys.stderr.write( "%s%s : %s%s" % (bcolors.WARNING, logging, bcolors.ENDC, warning_message)) + sys.stderr.write("\n") + +def okgreen(logging, ok_message): + sys.stderr.write( "%s%s : %s%s" % (bcolors.OKGREEN, logging, bcolors.ENDC, ok_message)) + sys.stderr.write("\n")