diff --git a/sigal/__init__.py b/sigal/__init__.py index ec07a01..5b57292 100644 --- a/sigal/__init__.py +++ b/sigal/__init__.py @@ -89,12 +89,11 @@ def build(source, destination, debug=False, verbose=False, force=False, config=None, theme=None): """Run sigal to process a directory. """ - level = (debug and logging.DEBUG) or (verbose and logging.INFO) \ - or logging.WARNING + level = ((debug and logging.DEBUG) or (verbose and logging.INFO) + or logging.WARNING) init_logging(level=level) logger = logging.getLogger(__name__) - logger.info("Reading settings ...") settings_file = config or _DEFAULT_CONFIG_FILE if not os.path.isfile(settings_file): logger.error("Settings file not found (%s)", settings_file) diff --git a/sigal/settings.py b/sigal/settings.py index 7150132..cf63aec 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -59,20 +59,29 @@ def read_settings(filename=None): """Read settings from a config file in the source_dir root.""" logger = logging.getLogger(__name__) + logger.info("Reading settings ...") settings = _DEFAULT_CONFIG.copy() + settings_path = os.path.dirname(filename) if filename: + logger.debug("Settings file: %s", filename) tempdict = {} execfile(filename, tempdict) settings.update((k, v) for k, v in tempdict.iteritems() if k not in ['__builtins__']) # Make the paths relative to the settings file - for key in ['source', 'destination']: - path = settings[key] + paths = ['source', 'destination'] + + if os.path.isdir(os.path.join(settings_path, settings['theme'])): + paths.append('theme') + + for p in paths: + path = settings[p] if path and not os.path.isabs(path): - settings[key] = os.path.abspath(os.path.normpath(os.path.join( - os.path.dirname(filename), path))) + settings[p] = os.path.abspath(os.path.normpath(os.path.join( + settings_path, path))) + logger.debug("%s : %s -> %s", p, path, settings[p]) for key in ('img_size', 'thumb_size'): w, h = settings[key] @@ -81,5 +90,4 @@ def read_settings(filename=None): logger.warning("The %s setting should be specified with the " "largest value first.", key) - return settings diff --git a/tests/test_settings.py b/tests/test_settings.py index b08047d..55d736f 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -5,12 +5,13 @@ import pytest from sigal.settings import read_settings, get_thumb +CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) + @pytest.fixture(scope='module') def settings(): """Read the sample config file.""" - path = os.path.abspath(os.path.dirname(__file__)) - return read_settings(os.path.join(path, 'sample', 'sigal.conf.py')) + return read_settings(os.path.join(CURRENT_DIR, 'sample', 'sigal.conf.py')) def test_read_settings(settings): @@ -18,6 +19,8 @@ def test_read_settings(settings): assert settings['img_size'] == (640, 480) assert settings['thumb_size'] == (200, 150) assert settings['thumb_suffix'] == '.tn' + assert settings['source'] == os.path.join(CURRENT_DIR, 'sample', + 'pictures') def test_thumb(settings): @@ -40,3 +43,17 @@ thumb_size = (150, 200) settings = read_settings(str(conf)) assert settings['thumb_size'] == (200, 150) + + +def test_theme_path(tmpdir): + """Test that image size is swaped if needed.""" + + tmpdir.join('theme').mkdir() + conf = tmpdir.join('sigal.conf.py') + conf.write("""# -*- coding: utf-8 -*- + +theme = 'theme' +""") + + settings = read_settings(str(conf)) + assert settings['theme'] == tmpdir.join('theme')