From 55f66f21cfefef3c0fee27cee00dd2c61008448a Mon Sep 17 00:00:00 2001 From: taziden Date: Fri, 5 Feb 2016 19:35:18 +0100 Subject: [PATCH 01/14] give more details about the public/private behavior --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e356b9a..e756f20 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ sub_title: it's a scary place, don't go there This settings.yaml will describe: * the title, subtitle and cover picture of your gallery that will be used on the homepage -* if your gallery is public +* if your gallery is public (if not, it will still be built but won't appear on the homepage) * the date of your gallery: this will be used on the homepage since **galleries are sorted anti chronologically** on it * the list of sections that will contains your gallery. A section will represent either one picture, a group of pictures or text. The different kind of sections will be explained in the next README section. From 799b816413405e00e24cb3a0d663391a7df39982 Mon Sep 17 00:00:00 2001 From: CapsLock Date: Sun, 17 Jan 2016 11:08:36 +0100 Subject: [PATCH 02/14] Quality of thumbnails can be changed in templates Signed-off-by: CapsLock --- prosopopee/prosopopee.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index c6ae00d..4294a79 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -60,7 +60,7 @@ class TemplateFunctions(): print source, "->", target return "" - def generate_thumbnail(self, image, gm_geometry): + def generate_thumbnail(self, image, gm_geometry, gm_quality=75): thumbnail_name = image.split(".") thumbnail_name[-2] += "-small" thumbnail_name = ".".join(thumbnail_name) @@ -68,7 +68,7 @@ class TemplateFunctions(): source, target = os.path.join(self.base_dir, image), os.path.join(self.target_dir, thumbnail_name) if CACHE.thumbnail_needs_to_be_generated(source, target): - command = "gm convert %s -resize %s %s" % (source, gm_geometry, target) + command = "gm convert %s -resize %s -quality %s" % (source, gm_geometry, gm_quality, target) print command os.system(command) From dca0f3623a5534c9196f553dcb907408d6c15861 Mon Sep 17 00:00:00 2001 From: CapsLock Date: Mon, 18 Jan 2016 00:15:18 +0100 Subject: [PATCH 03/14] footer type : s/generate/generated/ Signed-off-by: CapsLock --- prosopopee/templates/gallery-index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosopopee/templates/gallery-index.html b/prosopopee/templates/gallery-index.html index 902ffc9..1902c60 100644 --- a/prosopopee/templates/gallery-index.html +++ b/prosopopee/templates/gallery-index.html @@ -43,7 +43,7 @@ }); From 0ab845eada0afe227111feb63bdc05d07a11696f Mon Sep 17 00:00:00 2001 From: CapsLock Date: Mon, 18 Jan 2016 00:34:46 +0100 Subject: [PATCH 04/14] Now one can choose to override picture quality for thumbnails To use it, change this : - type: pictures-group images: - - image1.jpg - image2.jpg - - image3.jpg - image4.jpg To this : - type: pictures-group images: - - name: image1.jpg quality: 80 - image2.jpg - - image3.jpg - name: image4.jpg quality: 100 Next step would be to compress pictures instead of just copying them to reduce their size Signed-off-by: CapsLock --- prosopopee/prosopopee.py | 53 ++++++++++++++----- .../templates/sections/bordered-picture.html | 4 +- .../templates/sections/full-picture.html | 2 +- .../templates/sections/pictures-group.html | 2 +- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 4294a79..f4b4428 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -12,6 +12,15 @@ templates = Environment(loader=FileSystemLoader([os.path.realpath(os.path.join(o index_template = templates.get_template("index.html") gallery_index_template = templates.get_template("gallery-index.html") +DEFAULT_GM_QUALITY = 75 + +class CacheKeys(object): + SIZE = "size" + GM_QUALITY = "gm_quality" + +class ImageAttributes(object): + NAME = "name" + QUALITY = "quality" class Cache(object): cache_file_path = os.path.join(os.getcwd(), ".prosopopee_cache") @@ -22,20 +31,25 @@ class Cache(object): else: self.cache = {} - def thumbnail_needs_to_be_generated(self, source, target): + def thumbnail_needs_to_be_generated(self, source, target, gm_quality): if not os.path.exists(target): return True if target not in self.cache: return True - if self.cache[target] != os.path.getsize(source): + cache_data = self.cache[target] + + if cache_data[CacheKeys.SIZE] != os.path.getsize(source) or cache_data[CacheKeys.GM_QUALITY] != gm_quality: return True return False - def cache_thumbnail(self, source, target): - self.cache[target] = os.path.getsize(source) + def cache_thumbnail(self, source, target, gm_quality): + cache_data = {} + cache_data[CacheKeys.SIZE] = os.path.getsize(source) + cache_data[CacheKeys.GM_QUALITY] = gm_quality + self.cache[target] = cache_data def __del__(self): json.dump(self.cache, open(self.cache_file_path, "w")) @@ -48,33 +62,46 @@ class TemplateFunctions(): self.base_dir = base_dir self.target_dir = target_dir + def get_image_name(self, image): + if ImageAttributes.NAME not in image: + return image + + return image[ImageAttributes.NAME] + def copy_image(self, image): - source, target = os.path.join(self.base_dir, image), os.path.join(self.target_dir, image) + image_name = self.get_image_name(image) + source, target = os.path.join(self.base_dir, image_name), os.path.join(self.target_dir, image_name) # 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): # print "Skiped %s since the file hasn't been modified based on file size" % source # return "" - shutil.copyfile(source, target) + print source, "->", target return "" - def generate_thumbnail(self, image, gm_geometry, gm_quality=75): - thumbnail_name = image.split(".") + def generate_thumbnail(self, image, gm_geometry): + image_name = self.get_image_name(image) + thumbnail_name = image_name.split(".") thumbnail_name[-2] += "-small" thumbnail_name = ".".join(thumbnail_name) - source, target = os.path.join(self.base_dir, image), os.path.join(self.target_dir, thumbnail_name) + if ImageAttributes.QUALITY not in image: + gm_quality = DEFAULT_GM_QUALITY + else: + gm_quality = image[ImageAttributes.QUALITY] - if CACHE.thumbnail_needs_to_be_generated(source, target): - command = "gm convert %s -resize %s -quality %s" % (source, gm_geometry, gm_quality, target) + source, target = os.path.join(self.base_dir, image_name), os.path.join(self.target_dir, thumbnail_name) + + if CACHE.thumbnail_needs_to_be_generated(source, target, gm_quality): + command = "gm convert %s -resize %s -quality %s %s" % (source, gm_geometry, gm_quality, target) print command os.system(command) - CACHE.cache_thumbnail(source, target) + CACHE.cache_thumbnail(source, target, gm_quality) else: - print "skiped %s since it's already generated (based on source unchanged size)" % target + print "skiped %s since it's already generated (based on source unchanged size and thumbnail quality set in your gallery's settings.yaml)" % target return thumbnail_name diff --git a/prosopopee/templates/sections/bordered-picture.html b/prosopopee/templates/sections/bordered-picture.html index 65eb4ec..6c7ee0c 100644 --- a/prosopopee/templates/sections/bordered-picture.html +++ b/prosopopee/templates/sections/bordered-picture.html @@ -1,6 +1,6 @@ {{ helpers.copy_image(section.image) }}
- - + +
diff --git a/prosopopee/templates/sections/full-picture.html b/prosopopee/templates/sections/full-picture.html index 527512e..79c3e9d 100644 --- a/prosopopee/templates/sections/full-picture.html +++ b/prosopopee/templates/sections/full-picture.html @@ -1,5 +1,5 @@ {{ helpers.copy_image(section.image) }} -
+
{% if section.text %}
diff --git a/prosopopee/templates/sections/pictures-group.html b/prosopopee/templates/sections/pictures-group.html index 02c8f85..acbe708 100644 --- a/prosopopee/templates/sections/pictures-group.html +++ b/prosopopee/templates/sections/pictures-group.html @@ -4,7 +4,7 @@ {% for image in line %} {{ helpers.copy_image(image) }} From bd9d8f0cfdec7826ca7043b5cc7857b5e6ce84de Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 8 Feb 2016 04:55:34 +0100 Subject: [PATCH 05/14] [enh] handle cache version to avoid conflicts --- prosopopee/prosopopee.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index f4b4428..718724b 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -14,6 +14,8 @@ gallery_index_template = templates.get_template("gallery-index.html") DEFAULT_GM_QUALITY = 75 +CACHE_VERSION = 1 + class CacheKeys(object): SIZE = "size" GM_QUALITY = "gm_quality" @@ -29,6 +31,10 @@ class Cache(object): if os.path.exists(os.path.join(os.getcwd(), ".prosopopee_cache")): self.cache = json.load(open(self.cache_file_path, "r")) else: + self.cache = {"version": 1} + + if "version" not in self.cache or self.cache["version"] != CACHE_VERSION: + print "info: cache format as changed, prune cache" self.cache = {} def thumbnail_needs_to_be_generated(self, source, target, gm_quality): From b890b103eaf5678a3a2fb18c3d6e46e279745224 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 8 Feb 2016 04:56:38 +0100 Subject: [PATCH 06/14] [mod] autopep8 --- prosopopee/prosopopee.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 718724b..66eb19d 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -16,13 +16,16 @@ DEFAULT_GM_QUALITY = 75 CACHE_VERSION = 1 + class CacheKeys(object): - SIZE = "size" - GM_QUALITY = "gm_quality" + SIZE = "size" + GM_QUALITY = "gm_quality" + class ImageAttributes(object): - NAME = "name" - QUALITY = "quality" + NAME = "name" + QUALITY = "quality" + class Cache(object): cache_file_path = os.path.join(os.getcwd(), ".prosopopee_cache") @@ -63,6 +66,7 @@ class Cache(object): CACHE = Cache() + class TemplateFunctions(): def __init__(self, base_dir, target_dir, has_gm): self.base_dir = base_dir From c202cbbca6c7502d128edc1b7a3a2e06e2eeb48c Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 06:08:22 +0100 Subject: [PATCH 07/14] [mod] regenerate example build --- example/build/first_gallery/index.html | 23 +++++---- example/build/index.html | 3 +- example/build/static/css/style-page.css | 68 +++++++++++++++++-------- example/build/static/css/style.css | 21 ++++---- 4 files changed, 73 insertions(+), 42 deletions(-) diff --git a/example/build/first_gallery/index.html b/example/build/first_gallery/index.html index b52afd4..f73db53 100644 --- a/example/build/first_gallery/index.html +++ b/example/build/first_gallery/index.html @@ -3,13 +3,14 @@ + - my first gallery | Example gallery + my first gallery · Example gallery @@ -115,17 +116,19 @@ \ No newline at end of file diff --git a/example/build/index.html b/example/build/index.html index 691ec04..2531083 100644 --- a/example/build/index.html +++ b/example/build/index.html @@ -2,6 +2,7 @@ + @@ -40,7 +41,7 @@

.

\ No newline at end of file diff --git a/example/build/static/css/style-page.css b/example/build/static/css/style-page.css index 11ff15e..fe019dc 100644 --- a/example/build/static/css/style-page.css +++ b/example/build/static/css/style-page.css @@ -12,7 +12,7 @@ body { } section { - margin-bottom: 64px; + margin-bottom: 80px; } a { @@ -51,7 +51,7 @@ a { text-transform: uppercase; font-size: 5.5vw; letter-spacing: 4px; - font-family: sans-serif; + font-family: 'montserrat', sans-serif; margin-left: 10%; margin-right: 10%; margin-bottom: 1px; @@ -61,30 +61,30 @@ a { font-weight: normal; font-style: italic; font-size: 2.2vw; - font-family: serif; + font-family: 'crimson', serif; margin-top: 1px; } .full-picture .datetime { text-transform: uppercase; - font-family: serif; + font-family: 'crimson', serif; letter-spacing: 2px; } .bordered-picture img { - height: 80%; - width: 80%; - margin-left: 10%; - margin-right: 10%; + height: 77%; + width: 77%; + margin-left: 11.5%; + margin-right: 11.5%; } .pictures-line { - min-width: 80%; - width: 80%; - margin-left: 10%; - margin-right: 10%; + min-width: 77%; + width: 77%; + margin-left: 11.5%; + margin-right: 11.5%; display: flex; - margin-bottom: 15px; + margin-bottom: 0.5em; } .pictures-line .picture img { @@ -93,22 +93,47 @@ a { } .pictures-line .separator { - min-width: 15px; + min-width: 0.5em; } .text { text-align: center; - font-size: 25px; - margin-left: 15%; - margin-right: 15%; + font-family: 'crimson', serif; + font-size: 1.6em; + line-height: 1.8em; + margin-left: 21%; + margin-right: 21%; + color: black; +} + +.paragraph { + text-align: left; + font-family: 'crimson', serif; + font-size: 1em; + margin-left: 21%; + margin-right: 21%; color: #333; } +.paragraph h2 { + font-family: 'montserrat', sans-serif; + font-weight: normal; + font-size: 2.5em; + text-transform: uppercase; + color: black; + line-height: 1.4em; +} + +.paragraph p { + line-height: 2em; + +} + footer { - margin-top: 7em; + margin-top: 6em; text-align: center; position: relative; - font-family: serif; + font-family: 'crimson', serif; font-size: 11px; color: #555; background-color: #EEE; @@ -154,7 +179,8 @@ footer { justify-content: center; text-align: center; text-transform: uppercase; - font-family: sans-serif; + font-family: 'montserrat', sans-serif; + font-weight: bold; } footer p { @@ -164,6 +190,6 @@ footer p { footer a { text-decoration: none; font-weight: 600; - font-family: sans-serif; + font-family: 'montserrat', sans-serif; color: #111; } diff --git a/example/build/static/css/style.css b/example/build/static/css/style.css index ff1b104..e08e151 100644 --- a/example/build/static/css/style.css +++ b/example/build/static/css/style.css @@ -1,6 +1,6 @@ body { color: #222; - font-family: sans-serif; + font-family: 'montserrat', sans-serif; background-color: #FBFBFB; margin: 0; } @@ -17,10 +17,11 @@ body { .galleries-line { width: 100%; height: 100%; + margin-bottom: -4px; /* YOLO */ } .covers-1 .gallery-square { - width: 47%; + width: 100%; height: 100%; margin: auto; padding-bottom: 47%; @@ -28,12 +29,12 @@ body { } .covers-2 .gallery-square { - width: 47%; + width: 50%; height: 100%; - float: left; - margin: 0 1.5% 3%; + margin: 0 0 0; padding-bottom: 47%; position: relative; + display: inline-block; } .covers-3 .gallery-square { @@ -110,7 +111,7 @@ body { color: #444; font-style: italic; font-weight: normal; - font-family: serif; + font-family: 'crimson', serif; margin-top: .5em; } @@ -131,13 +132,13 @@ body { font-style: italic; margin-top: 0; margin-bottom: .7em; - font-family: serif; + font-family: 'crimson', serif; font-weight: normal; } .gallery-datetime { margin-bottom: 1em; - font-family: serif; + font-family: 'crimson', serif; text-transform: uppercase; letter-spacing: 2px; font-size: 11px; @@ -147,7 +148,7 @@ footer { margin-top: 7em; text-align: center; position: relative; - font-family: serif; + font-family: 'crimson', serif; font-size: 11px; color: #555; background-color: #EEE; @@ -163,6 +164,6 @@ footer p { footer a { text-decoration: none; font-weight: 600; - font-family: sans-serif; + font-family: 'montserrat', sans-serif; color: #111; } From a1c5e75aa3eb290d18f67f1e6126d5ff7bfa87e0 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 06:30:43 +0100 Subject: [PATCH 08/14] [mod] start refactoring to a simplification of capslock patch --- prosopopee/prosopopee.py | 62 +++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 66eb19d..e386426 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -17,14 +17,19 @@ DEFAULT_GM_QUALITY = 75 CACHE_VERSION = 1 -class CacheKeys(object): - SIZE = "size" - GM_QUALITY = "gm_quality" +class Image(object): + def __init__(self, options): + # assuming string + if not isinstance(options, dict): + name = options + options = {"name": options} + self.name = name + self.quality = options.get("quality", DEFAULT_GM_QUALITY) + self.options = options # used for caching, if it's modified -> regenerate -class ImageAttributes(object): - NAME = "name" - QUALITY = "quality" + def __repr__(self): + return self.name class Cache(object): @@ -40,25 +45,22 @@ class Cache(object): print "info: cache format as changed, prune cache" self.cache = {} - def thumbnail_needs_to_be_generated(self, source, target, gm_quality): + def thumbnail_needs_to_be_generated(self, source, target, image): if not os.path.exists(target): return True if target not in self.cache: return True - cache_data = self.cache[target] + cached_thumbnail = self.cache[target] - if cache_data[CacheKeys.SIZE] != os.path.getsize(source) or cache_data[CacheKeys.GM_QUALITY] != gm_quality: + if cached_thumbnail["size"] != os.path.getsize(source) or cached_thumbnail["options"] != image.options: return True return False - def cache_thumbnail(self, source, target, gm_quality): - cache_data = {} - cache_data[CacheKeys.SIZE] = os.path.getsize(source) - cache_data[CacheKeys.GM_QUALITY] = gm_quality - self.cache[target] = cache_data + def cache_thumbnail(self, source, target, image): + self.cache[target] = {"size": os.path.getsize(source), "options": image.options} def __del__(self): json.dump(self.cache, open(self.cache_file_path, "w")) @@ -72,15 +74,9 @@ class TemplateFunctions(): self.base_dir = base_dir self.target_dir = target_dir - def get_image_name(self, image): - if ImageAttributes.NAME not in image: - return image - - return image[ImageAttributes.NAME] - def copy_image(self, image): - image_name = self.get_image_name(image) - source, target = os.path.join(self.base_dir, image_name), os.path.join(self.target_dir, image_name) + image = Image(image) + source, target = os.path.join(self.base_dir, image.name), os.path.join(self.target_dir, image.name) # 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): @@ -92,26 +88,20 @@ class TemplateFunctions(): return "" def generate_thumbnail(self, image, gm_geometry): - image_name = self.get_image_name(image) - thumbnail_name = image_name.split(".") + image = Image(image) + thumbnail_name = image.name.split(".") thumbnail_name[-2] += "-small" thumbnail_name = ".".join(thumbnail_name) - if ImageAttributes.QUALITY not in image: - gm_quality = DEFAULT_GM_QUALITY - else: - gm_quality = image[ImageAttributes.QUALITY] + source, target = os.path.join(self.base_dir, image.name), os.path.join(self.target_dir, thumbnail_name) - source, target = os.path.join(self.base_dir, image_name), os.path.join(self.target_dir, thumbnail_name) - - if CACHE.thumbnail_needs_to_be_generated(source, target, gm_quality): - command = "gm convert %s -resize %s -quality %s %s" % (source, gm_geometry, gm_quality, target) + if CACHE.thumbnail_needs_to_be_generated(source, target, image): + command = "gm convert %s -resize %s -quality %s %s" % (source, gm_geometry, image.quality, target) print command os.system(command) - - CACHE.cache_thumbnail(source, target, gm_quality) + CACHE.cache_thumbnail(source, target, image) else: - print "skiped %s since it's already generated (based on source unchanged size and thumbnail quality set in your gallery's settings.yaml)" % target + print "skiped %s since it's already generated (based on source unchanged size and images options set in your gallery's settings.yaml)" % target return thumbnail_name @@ -184,7 +174,7 @@ def main(): front_page_galleries_cover = reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"])) - open(os.path.join("build", "index.html"), "w").write(index_template.render(settings=settings, galleries=front_page_galleries_cover, helpers=TemplateFunctions(os.getcwd(), os.path.join(os.getcwd(), "build"), has_gm=has_gm)).encode("Utf-8")) + open(os.path.join("build", "index.html"), "w").write(index_template.render(settings=settings, galleries=front_page_galleries_cover, Image=Image, helpers=TemplateFunctions(os.getcwd(), os.path.join(os.getcwd(), "build"), has_gm=has_gm)).encode("Utf-8")) if __name__ == '__main__': From cfba36bd6c03158fb3fac66fd42c98f3dc764955 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 06:35:31 +0100 Subject: [PATCH 09/14] [mod] don't try to work without gm anymore --- prosopopee/prosopopee.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index e386426..6b2899e 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -117,10 +117,9 @@ def error(test, error_message): def main(): - has_gm = True if os.system("which gm > /dev/null") != 0: - has_gm = False - sys.stderr.write("WARNING: I can't locate the 'gm' binary, I won't be able to resize images.\n") + sys.stderr.write("ERROR: I can't locate the 'gm' binary, I won't be able to resize images, please install the 'graphicsmagick' package.\n") + sys.exit(1) error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a settings.yaml in the current working directory") From 3ee90704bc813c47d8784b68c701bb72cebdf6ad Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 07:30:23 +0100 Subject: [PATCH 10/14] [fix] save CACHE version in cache, otherwise don't make sens --- prosopopee/prosopopee.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 6b2899e..3ed77e9 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -39,11 +39,11 @@ class Cache(object): if os.path.exists(os.path.join(os.getcwd(), ".prosopopee_cache")): self.cache = json.load(open(self.cache_file_path, "r")) else: - self.cache = {"version": 1} + self.cache = {"version": CACHE_VERSION} if "version" not in self.cache or self.cache["version"] != CACHE_VERSION: print "info: cache format as changed, prune cache" - self.cache = {} + self.cache = {"version": CACHE_VERSION} def thumbnail_needs_to_be_generated(self, source, target, image): if not os.path.exists(target): From a2d04eb3ce1d5c0be5eedf16e5b6cf6973da439e Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 07:30:45 +0100 Subject: [PATCH 11/14] [fix] very strange behavior of python interpretor --- prosopopee/prosopopee.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 3ed77e9..0aff029 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -35,7 +35,12 @@ class Image(object): class Cache(object): cache_file_path = os.path.join(os.getcwd(), ".prosopopee_cache") - def __init__(self): + def __init__(self, json): + # fix: I need to keep a reference to json because for whatever reason + # modules are set to None during python shutdown thus totally breaking + # the __del__ call to save the cache + # This wonderfully stupid behavior has been fixed in 3.4 (which nobody uses) + self.json = json if os.path.exists(os.path.join(os.getcwd(), ".prosopopee_cache")): self.cache = json.load(open(self.cache_file_path, "r")) else: @@ -63,10 +68,11 @@ class Cache(object): self.cache[target] = {"size": os.path.getsize(source), "options": image.options} def __del__(self): - json.dump(self.cache, open(self.cache_file_path, "w")) + self.json.dump(self.cache, open(self.cache_file_path, "w")) -CACHE = Cache() +CACHE = Cache(json=json) + class TemplateFunctions(): From 1866d6279e75498156bd4e85b35bf97376364e1d Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 07:31:37 +0100 Subject: [PATCH 12/14] [mod] merge images and templates class into one, go full OO --- prosopopee/prosopopee.py | 65 +++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 0aff029..06c0e50 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -17,21 +17,6 @@ DEFAULT_GM_QUALITY = 75 CACHE_VERSION = 1 -class Image(object): - def __init__(self, options): - # assuming string - if not isinstance(options, dict): - name = options - options = {"name": options} - - self.name = name - self.quality = options.get("quality", DEFAULT_GM_QUALITY) - self.options = options # used for caching, if it's modified -> regenerate - - def __repr__(self): - return self.name - - class Cache(object): cache_file_path = os.path.join(os.getcwd(), ".prosopopee_cache") @@ -74,15 +59,23 @@ class Cache(object): CACHE = Cache(json=json) +class Image(object): + base_dir = "" + target_dir = "" -class TemplateFunctions(): - def __init__(self, base_dir, target_dir, has_gm): - self.base_dir = base_dir - self.target_dir = target_dir + def __init__(self, options): + # assuming string + if not isinstance(options, dict): + name = options + options = {"name": options} - def copy_image(self, image): - image = Image(image) - source, target = os.path.join(self.base_dir, image.name), os.path.join(self.target_dir, image.name) + self.name = name + self.quality = options.get("quality", DEFAULT_GM_QUALITY) + self.options = options.copy() # used for caching, if it's modified -> regenerate + del self.options["name"] + + def copy(self): + source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, self.name) # 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): @@ -93,24 +86,26 @@ class TemplateFunctions(): print source, "->", target return "" - def generate_thumbnail(self, image, gm_geometry): - image = Image(image) - thumbnail_name = image.name.split(".") + def generate_thumbnail(self, gm_geometry): + thumbnail_name = self.name.split(".") thumbnail_name[-2] += "-small" thumbnail_name = ".".join(thumbnail_name) - source, target = os.path.join(self.base_dir, image.name), os.path.join(self.target_dir, thumbnail_name) + source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, thumbnail_name) - if CACHE.thumbnail_needs_to_be_generated(source, target, image): - command = "gm convert %s -resize %s -quality %s %s" % (source, gm_geometry, image.quality, target) + if CACHE.thumbnail_needs_to_be_generated(source, target, self): + command = "gm convert %s -resize %s -quality %s %s" % (source, gm_geometry, self.quality, target) print command os.system(command) - CACHE.cache_thumbnail(source, target, image) + CACHE.cache_thumbnail(source, target, self) else: print "skiped %s since it's already generated (based on source unchanged size and images options set in your gallery's settings.yaml)" % target return thumbnail_name + def __repr__(self): + return self.name + def error(test, error_message): if test: @@ -175,11 +170,19 @@ def main(): if not os.path.exists(os.path.join("build", gallery)): os.makedirs(os.path.join("build", gallery)) - open(os.path.join("build", gallery, "index.html"), "w").write(gallery_index_template.render(settings=settings, gallery=gallery_settings, helpers=TemplateFunctions(os.path.join(os.getcwd(), gallery), os.path.join(os.getcwd(), "build", gallery), has_gm=has_gm)).encode("Utf-8")) + # 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) + + open(os.path.join("build", gallery, "index.html"), "w").write(gallery_index_template.render(settings=settings, gallery=gallery_settings, Image=Image).encode("Utf-8")) front_page_galleries_cover = reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"])) - open(os.path.join("build", "index.html"), "w").write(index_template.render(settings=settings, galleries=front_page_galleries_cover, Image=Image, helpers=TemplateFunctions(os.getcwd(), os.path.join(os.getcwd(), "build"), has_gm=has_gm)).encode("Utf-8")) + Image.base_dir = os.getcwd() + Image.target_dir = os.path.join(os.getcwd(), "build") + + open(os.path.join("build", "index.html"), "w").write(index_template.render(settings=settings, galleries=front_page_galleries_cover, Image=Image).encode("Utf-8")) + if __name__ == '__main__': From acccb41ff055aae3035759bae90af456e151e79b Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 07:31:52 +0100 Subject: [PATCH 13/14] [mod] update sections templates for new behavior --- prosopopee/templates/index.html | 4 +++- prosopopee/templates/sections/bordered-picture.html | 7 ++++--- prosopopee/templates/sections/full-picture.html | 5 +++-- prosopopee/templates/sections/panorama.html | 5 +++-- prosopopee/templates/sections/pictures-group.html | 7 ++++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/prosopopee/templates/index.html b/prosopopee/templates/index.html index 4869b10..b866c4b 100644 --- a/prosopopee/templates/index.html +++ b/prosopopee/templates/index.html @@ -31,7 +31,9 @@ {% if gallery.date %}{% endif %}
- + {% set cover = Image(gallery.cover) %} + {{ cover.copy() }} +
{% endfor %} diff --git a/prosopopee/templates/sections/bordered-picture.html b/prosopopee/templates/sections/bordered-picture.html index 6c7ee0c..294c454 100644 --- a/prosopopee/templates/sections/bordered-picture.html +++ b/prosopopee/templates/sections/bordered-picture.html @@ -1,6 +1,7 @@ -{{ helpers.copy_image(section.image) }} +{% set image = Image(section.image) %} +{{ image.copy()}}
- - + +
diff --git a/prosopopee/templates/sections/full-picture.html b/prosopopee/templates/sections/full-picture.html index 79c3e9d..48eb774 100644 --- a/prosopopee/templates/sections/full-picture.html +++ b/prosopopee/templates/sections/full-picture.html @@ -1,5 +1,6 @@ -{{ helpers.copy_image(section.image) }} -
+{% set image = Image(section.image) %} +{{ image.copy() }} +
{% if section.text %}
diff --git a/prosopopee/templates/sections/panorama.html b/prosopopee/templates/sections/panorama.html index 3d260a3..a9e2767 100644 --- a/prosopopee/templates/sections/panorama.html +++ b/prosopopee/templates/sections/panorama.html @@ -1,4 +1,5 @@ -{{ helpers.copy_image(section.image) }} +{% set image = Image(section.image) %} +{{ image.copy() }}
- +
diff --git a/prosopopee/templates/sections/pictures-group.html b/prosopopee/templates/sections/pictures-group.html index acbe708..bc9a282 100644 --- a/prosopopee/templates/sections/pictures-group.html +++ b/prosopopee/templates/sections/pictures-group.html @@ -2,10 +2,11 @@ {% for line in section.images %}
{% for image in line %} - {{ helpers.copy_image(image) }} + {% set image = Image(image) %} + {{ image.copy() }} {% if not loop.last %} From cfbfab8d33dda62d05a54120cc7d792b99ec60e4 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 9 Feb 2016 07:32:06 +0100 Subject: [PATCH 14/14] [mod] regenerate example gallery --- example/build/first_gallery/index.html | 26 +++++++++++++++++--------- example/build/index.html | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/example/build/first_gallery/index.html b/example/build/first_gallery/index.html index f73db53..bbe7100 100644 --- a/example/build/first_gallery/index.html +++ b/example/build/first_gallery/index.html @@ -16,6 +16,7 @@ +
@@ -29,6 +30,7 @@
+
@@ -44,15 +46,6 @@
+
diff --git a/example/build/index.html b/example/build/index.html index 2531083..27a1605 100644 --- a/example/build/index.html +++ b/example/build/index.html @@ -31,6 +31,8 @@
+ +