From eebce98142bfdbe2132713edda608fc81a1fd9df Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 23 Feb 2013 00:24:54 +0100 Subject: [PATCH] Add an init subcommand, to copy a sample config file in the current directory. --- docs/index.rst | 2 +- sigal/__init__.py | 14 ++++++++- sigal/templates/sigal.conf.py | 55 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 sigal/templates/sigal.conf.py diff --git a/docs/index.rst b/docs/index.rst index 19c7fb8..ff635cb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -103,7 +103,7 @@ The configuration for the gallery must be set in ``/sigal.conf.py``. An example file with explanations on the settings is available in ``tests/sample/sigal.conf.py`` and is shown below: -.. literalinclude:: ../tests/sample/sigal.conf.py +.. literalinclude:: ../sigal/templates/sigal.conf.py :language: python diff --git a/sigal/__init__.py b/sigal/__init__.py index bf6a537..cd0c03b 100644 --- a/sigal/__init__.py +++ b/sigal/__init__.py @@ -36,6 +36,7 @@ __author__ = "Simon Conseil" __version__ = "0.2" __license__ = "MIT" +import codecs import logging import os import sys @@ -67,6 +68,17 @@ def init_logging(level=logging.INFO): logger.addHandler(handler) +def init(): + """Copy a sample config file in the current directory.""" + + from pkg_resources import resource_string + conf = resource_string(__name__, 'templates/sigal.conf.py') + + with codecs.open('sigal.conf.py', 'w', 'utf-8') as f: + f.write(conf) + print "Sample config file created: sigal.conf.py" + + @arg('input-dir', help='Input directory') @arg('output-dir', nargs='?', default='_build', help='Output directory (default: _build/)') @@ -136,5 +148,5 @@ def serve(path): def main(): parser = ArghParser(description='Simple static gallery generator.', version=__version__) - parser.add_commands([build, serve]) + parser.add_commands([init, build, serve]) parser.dispatch() diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py new file mode 100644 index 0000000..e85b9ad --- /dev/null +++ b/sigal/templates/sigal.conf.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# +# All configuration values have a default; values that are commented out serve +# to show the default. Default values are specified when modified in this +# example config file + +# Theme : +# - colorbox (default), galleria, or the path to a custom theme directory +theme = 'galleria' + +# Size of resized image +img_size = (640, 480) + +# Generate thumbnails +# make_thumbs = True + +# Subdirectory of the thumbnails +# thumb_dir = 'thumbnails' + +# Prefix and/or suffix for thumbnail names (default: '') +# thumb_prefix = +# thumb_suffix = '.tn' + +# Thumbnail size (default: (150, 112)) +thumb_size = (200, 150) + +# Crop the image to fill the box +# thumb_fit = True + +# Keep original image (default: False) +# keep_orig = True + +# Subdirectory for original images +# orig_dir = 'original' + +# Jpeg options +# jpg_options = {'quality': 85, +# 'optimize': True, +# 'progressive': True} + +# Add index.html to the URLs +# index_in_url = False + +# A list of links (tuples (title, URL)) +# links = [('Example link', 'http://example.org'), +# ('Another link', 'http://example.org')] + +# Keep exif metadatas in output image (default: False) +# copy_exif = True + +# Add a copyright text on the image (default: '') +# copyright = "An example copyright message" + +# Google Analytics tracking code (UA-xxxx-x) +# google_analytics = ''