From a2ae29b5c7272bc09772a6bc5ff5de47fd3b9c7b Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Wed, 17 Feb 2016 17:53:30 +0100 Subject: [PATCH] [enh] put default gm settings in a global dict, can be overridden in root settings.yaml --- prosopopee/prosopopee.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 1551b21..37bc31f 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -16,6 +16,11 @@ page_template = templates.get_template("page.html") DEFAULT_GM_QUALITY = 75 DEFAULT_GM_AUTOORIENT = False +gm_settings = { + "quality" : 75, + "auto-orient" : True +} + CACHE_VERSION = 1 @@ -69,13 +74,8 @@ class Image(object): # assuming string if not isinstance(options, dict): options = {"name": options} - - if not options.has_key("quality"): - options["quality"] = DEFAULT_GM_QUALITY - if not options.has_key("autoorient"): - options["autoorient"] = DEFAULT_GM_AUTOORIENT - self.options = options.copy() # used for caching, if it's modified -> regenerate + self.options.update(gm_settings) @property def name(self): @@ -87,7 +87,7 @@ class Image(object): @property def autoorient(self): - return self.options["autoorient"] + return self.options["auto-orient"] def copy(self): source, target = os.path.join(self.base_dir, self.name), os.path.join(self.target_dir, self.name) @@ -151,15 +151,10 @@ 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("auto-orient"): - global DEFAULT_GM_AUTOORIENT - DEFAULT_GM_AUTOORIENT = settings.get("auto-orient") - - if settings.get("quality"): - global DEFAULT_GM_QUALITY - DEFAULT_GM_QUALITY = settings.get("quality") - + + if settings.get("gm_settings"): + gm_settings.update( settings.get("gm_settings") ) + front_page_galleries_cover = [] 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()))