diff --git a/sigal/__init__.py b/sigal/__init__.py index cd5b691..afe210e 100644 --- a/sigal/__init__.py +++ b/sigal/__init__.py @@ -39,6 +39,8 @@ from sigal.image import Gallery from sigal.settings import read_settings from sigal.theme import Theme +_DEFAULT_CONFIG_FILE = 'sigal.conf' + def main(): "main program" @@ -59,7 +61,7 @@ def main(): sys.exit(1) print ":: Reading settings ..." - settings = read_settings(args.input_dir) + settings = read_settings(os.path.join(args.input_dir, _DEFAULT_CONFIG_FILE)) if args.copyright: settings['copyright'] = args.copyright diff --git a/sigal/settings.py b/sigal/settings.py index de49a32..dc24742 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -20,20 +20,19 @@ import os import ConfigParser -CONFIG_FILE = 'sigal.conf' - _DEFAULT_CONFIG = { 'img_size': '640x480', 'thumb_prefix': '', 'thumb_size': '150x112', - 'thumb_dir': "thumbnail", + 'thumb_dir': 'thumbnail', 'square_thumb': 0, 'big_img': 0, - 'bigimg_dir': "big", + 'bigimg_dir': 'big', 'jpg_quality': 90, 'exif': 1, 'copyright': '', - 'fileExtList': ".jpg,.jpeg,.JPG,.JPEG,.png" + 'fileExtList': '.jpg,.jpeg,.JPG,.JPEG,.png', + 'theme': 'default' } @@ -45,16 +44,15 @@ def get_size(string): return tuple(size) -def read_settings(source_dir): +def read_settings(filename=None): "Read settings from a config file in the source_dir root" - # Read configuration file + # Read the default configuration config = ConfigParser.ConfigParser(defaults=_DEFAULT_CONFIG) - # Load a config file in the source_dir root - local_config = os.path.join(source_dir, CONFIG_FILE) - if os.path.isfile(local_config): - config.read(local_config) + # Load the config file + if filename and os.path.isfile(filename): + config.read(filename) settings = dict(config.items('sigal')) settings['jpg_quality'] = int(settings['jpg_quality']) diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..2a4d751 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python2 +# -*- coding:utf-8 -*- + +import os +import unittest + +from sigal.settings import read_settings + +class TestSettings(unittest.TestCase): + "Read a settings file and check that the configuration is well done." + + def setUp(self): + "Read the sample config file" + self.path = os.path.abspath(os.path.dirname(__file__)) + default_conf = os.path.join(self.path, 'sample', 'sigal.conf') + self.settings = read_settings(default_conf) + + def test_img_size(self): + "Test that image sizes are correctly read" + self.assertTupleEqual(self.settings['img_size'], (640, 480)) + self.assertTupleEqual(self.settings['thumb_size'], (150, 112)) + + def test_fileextlist(self): + self.assertListEqual(self.settings['fileextlist'], + ['.jpg', '.jpeg', '.JPG', '.JPEG', '.png']) + + def test_type_conversion(self): + self.assertEqual(self.settings['jpg_quality'], 90)