Add new settings for the source and destination directories.
This commit is contained in:
@@ -93,18 +93,18 @@ Help of the ``sigal build`` command
|
||||
::
|
||||
|
||||
$ sigal build [-h] [-d] [-v] [-f] [-c CONFIG] [-t THEME]
|
||||
input_dir [output_dir]
|
||||
[source] [destination]
|
||||
|
||||
Required arguments:
|
||||
|
||||
``input_dir``
|
||||
``source``
|
||||
Input directory
|
||||
|
||||
Optional arguments:
|
||||
|
||||
``output_dir``
|
||||
``destination``
|
||||
Output directory (default: ``_build/``)
|
||||
|
||||
Optional arguments:
|
||||
|
||||
``-h, --help``
|
||||
Show this help message and exit
|
||||
|
||||
@@ -118,7 +118,8 @@ Optional arguments:
|
||||
Show all message, including debug messages
|
||||
|
||||
``-c CONFIG, --config CONFIG``
|
||||
Configuration file (default: ``<input_dir>/sigal.conf.py``)
|
||||
Configuration file (default: ``sigal.conf.py`` in the current working
|
||||
directory)
|
||||
|
||||
``-t THEME, --theme THEME``
|
||||
Specify a theme directory, or a theme name for the themes included with Sigal
|
||||
@@ -167,6 +168,7 @@ Released on 2013-xx-xx.
|
||||
- Add a setting to disable the writing of HTML files.
|
||||
- Use Pilkit.
|
||||
- Remove multiprocessing.
|
||||
- Add new settings for the source and destination directories.
|
||||
|
||||
Version 0.3.3
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
@@ -76,9 +76,8 @@ def init():
|
||||
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/)')
|
||||
@arg('source', nargs='?', help='Input directory')
|
||||
@arg('destination', nargs='?', help='Output directory (default: _build/)')
|
||||
@arg('-f', '--force', help="Force the reprocessing of existing images")
|
||||
@arg('-v', '--verbose', help="Show all messages")
|
||||
@arg('-d', '--debug', help="Show all message, including debug messages")
|
||||
@@ -86,7 +85,7 @@ def init():
|
||||
"the current working directory)")
|
||||
@arg('-t', '--theme', help="Specify a theme directory, or a theme name for "
|
||||
"the themes included with Sigal")
|
||||
def build(input_dir, output_dir, debug=False, verbose=False, force=False,
|
||||
def build(source, destination, debug=False, verbose=False, force=False,
|
||||
config=None, theme=None):
|
||||
"""Run sigal to process a directory. """
|
||||
|
||||
@@ -95,15 +94,6 @@ def build(input_dir, output_dir, debug=False, verbose=False, force=False,
|
||||
init_logging(level=level)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if not os.path.isdir(input_dir):
|
||||
logger.error("Input directory '%s' does not exist.", input_dir)
|
||||
sys.exit(1)
|
||||
|
||||
if not os.path.relpath(output_dir, input_dir).startswith('..'):
|
||||
logger.error("Output directory should be outside of the input "
|
||||
"directory.")
|
||||
sys.exit(1)
|
||||
|
||||
logger.info("Reading settings ...")
|
||||
settings_file = config or _DEFAULT_CONFIG_FILE
|
||||
if not os.path.isfile(settings_file):
|
||||
@@ -111,7 +101,25 @@ def build(input_dir, output_dir, debug=False, verbose=False, force=False,
|
||||
sys.exit(1)
|
||||
settings = read_settings(settings_file)
|
||||
|
||||
gal = Gallery(settings, input_dir, output_dir, force=force, theme=theme)
|
||||
if source:
|
||||
settings['source'] = os.path.abspath(source)
|
||||
if destination:
|
||||
settings['destination'] = os.path.abspath(destination)
|
||||
|
||||
logger.debug("Input directory: '%s'", settings['source'])
|
||||
if not settings['source'] or not os.path.isdir(settings['source']):
|
||||
logger.error("Input directory '%s' does not exist.",
|
||||
settings['source'])
|
||||
sys.exit(1)
|
||||
|
||||
logger.debug("Output directory: '%s'", settings['destination'])
|
||||
if not os.path.relpath(settings['destination'],
|
||||
settings['source']).startswith('..'):
|
||||
logger.error("Output directory should be outside of the input "
|
||||
"directory.")
|
||||
sys.exit(1)
|
||||
|
||||
gal = Gallery(settings, force=force, theme=theme)
|
||||
gal.build()
|
||||
|
||||
|
||||
|
||||
@@ -142,26 +142,26 @@ class PathsDb(object):
|
||||
class Gallery(object):
|
||||
"Prepare images"
|
||||
|
||||
def __init__(self, settings, input_dir, output_dir, force=False,
|
||||
theme=None):
|
||||
def __init__(self, settings, force=False, theme=None):
|
||||
self.settings = settings
|
||||
self.force = force
|
||||
self.input_dir = os.path.abspath(input_dir)
|
||||
self.output_dir = os.path.abspath(output_dir)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
if self.settings['write_html']:
|
||||
self.writer = Writer(settings, output_dir, theme=theme)
|
||||
self.writer = Writer(settings, self.settings['destination'],
|
||||
theme=theme)
|
||||
|
||||
self.paths = PathsDb(self.input_dir, self.settings['ext_list'])
|
||||
self.paths = PathsDb(self.settings['source'],
|
||||
self.settings['ext_list'])
|
||||
self.paths.build()
|
||||
self.db = self.paths.db
|
||||
|
||||
def build(self):
|
||||
"Create the image gallery"
|
||||
|
||||
self.logger.info("Generate gallery in %s ...", self.output_dir)
|
||||
check_or_create_dir(self.output_dir)
|
||||
self.logger.info("Generate gallery in %s ...",
|
||||
self.settings['destination'])
|
||||
check_or_create_dir(self.settings['destination'])
|
||||
|
||||
# Compute the label with for the progress bar. The max value is 48
|
||||
# character = 80 - 32 for the progress bar.
|
||||
@@ -171,11 +171,12 @@ class Gallery(object):
|
||||
# loop on directories in reversed order, to process subdirectories
|
||||
# before their parent
|
||||
for path in reversed(self.db['paths_list']):
|
||||
imglist = [os.path.normpath(join(self.input_dir, path, f))
|
||||
imglist = [os.path.normpath(join(self.settings['source'], path, f))
|
||||
for f in self.db[path]['img']]
|
||||
|
||||
# output dir for the current path
|
||||
img_out = os.path.normpath(join(self.output_dir, path))
|
||||
img_out = os.path.normpath(join(self.settings['destination'],
|
||||
path))
|
||||
check_or_create_dir(img_out)
|
||||
|
||||
if len(imglist) != 0:
|
||||
|
||||
@@ -24,6 +24,8 @@ import logging
|
||||
import os
|
||||
|
||||
_DEFAULT_CONFIG = {
|
||||
'source': '',
|
||||
'destination': '_build',
|
||||
'img_size': (640, 480),
|
||||
'make_thumbs': True,
|
||||
'thumb_prefix': '',
|
||||
@@ -65,6 +67,13 @@ def read_settings(filename=None):
|
||||
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]
|
||||
if path and not os.path.isabs(path):
|
||||
settings[key] = os.path.abspath(os.path.normpath(os.path.join(
|
||||
os.path.dirname(filename), path)))
|
||||
|
||||
for key in ('img_size', 'thumb_size'):
|
||||
w, h = settings[key]
|
||||
if h > w:
|
||||
@@ -72,4 +81,5 @@ def read_settings(filename=None):
|
||||
logger.warning("The %s setting should be specified with the "
|
||||
"largest value first.", key)
|
||||
|
||||
|
||||
return settings
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
# to show the default. Default values are specified when modified in this
|
||||
# example config file
|
||||
|
||||
# Source directory. Can be set here or as the first argument of the `sigal
|
||||
# build` command
|
||||
source = 'pictures'
|
||||
|
||||
# Destination directory. Can be set here or as the second argument of the
|
||||
# `sigal build` command (default: '_build')
|
||||
# destination = '_build'
|
||||
|
||||
# Theme :
|
||||
# - colorbox (default), galleria, or the path to a custom theme directory
|
||||
theme = 'galleria'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
source = 'pictures'
|
||||
thumb_suffix = '.tn'
|
||||
thumb_size = (200, 150)
|
||||
keep_orig = True
|
||||
|
||||
Reference in New Issue
Block a user