diff --git a/prosopopee/cache.py b/prosopopee/cache.py index 20b3ea0..cbbd79f 100644 --- a/prosopopee/cache.py +++ b/prosopopee/cache.py @@ -36,9 +36,26 @@ class Cache(object): return False + def image_needs_to_be_oritend(self, source, target, command): + if not os.path.exists(target): + return True + + if target not in self.cache: + return True + + cached_image = self.cache[target] + + if cached_image["size"] != os.path.getsize(source) or cached_image["command"] != command: + return True + + return False + def cache_thumbnail(self, source, target, image): self.cache[target] = {"size": os.path.getsize(source), "options": image.options} + def cache_auto_oriented_image(self, source, target, command): + self.cache[target] = {"size": os.path.getsize(source), "command": command} + def __del__(self): self.json.dump(self.cache, open(self.cache_file_path, "w")) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index f647b4c..c9d0a65 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -55,10 +55,16 @@ class Image(object): if not self.autoorient: shutil.copyfile(source, target) print source, "->", target - else: - command = "gm convert %s -strip -auto-orient %s" % (source, target) + return "" + + command = "gm convert %s -strip -auto-orient %s" % (source, target) + + if CACHE.image_needs_to_be_oritend(source, target, command): print command os.system(command) + CACHE.cache_auto_oriented_image(source, target, command) + else: + print "skipped %s since it's already generated (based on source unchanged size and images options)" % target return ""