How to use the sigal.settings.read_settings function in sigal

To help you get started, we’ve selected a few sigal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saimn / sigal / tests / test_settings.py View on Github external
def test_img_sizes(tmpdir):
    """Test that image size is swaped if needed."""

    conf = tmpdir.join('sigal.conf.py')
    conf.write("thumb_size = (150, 200)")

    settings = read_settings(str(conf))
    assert settings['thumb_size'] == (200, 150)
github saimn / sigal / tests / test_zip.py View on Github external
def make_gallery(**kwargs):
    default_conf = os.path.join(SAMPLE_DIR, 'sigal.conf.py')
    settings = read_settings(default_conf)
    settings['source'] = SAMPLE_SOURCE
    settings.update(kwargs)
    return Gallery(settings, ncpu=1)
github saimn / sigal / tests / test_settings.py View on Github external
def test_theme_path(tmpdir):
    """Test that image size is swaped if needed."""

    tmpdir.join('theme').mkdir()
    tmpdir.join('theme').join('templates').mkdir()
    conf = tmpdir.join('sigal.conf.py')
    conf.write("theme = 'theme'")

    settings = read_settings(str(conf))
    assert settings['theme'] == tmpdir.join('theme')
github saimn / sigal / sigal / __init__.py View on Github external
elif verbose:
        level = logging.INFO
    elif quiet:
        level = logging.ERROR
    else:
        level = logging.WARNING

    init_logging(__name__, level=level)
    logger = logging.getLogger(__name__)

    if not os.path.isfile(config):
        logger.error("Settings file not found: %s", config)
        sys.exit(1)

    start_time = time.time()
    settings = read_settings(config)

    for key in ('source', 'destination', 'theme'):
        arg = locals()[key]
        if arg is not None:
            settings[key] = os.path.abspath(arg)
        logger.info("%12s : %s", key.capitalize(), settings[key])

    if not settings['source'] or not os.path.isdir(settings['source']):
        logger.error("Input directory not found: %s", settings['source'])
        sys.exit(1)

    # on windows os.path.relpath raises a ValueError if the two paths are on
    # different drives, in that case we just ignore the exception as the two
    # paths are anyway not relative
    relative_check = True
    try:
github saimn / sigal / sigal / __init__.py View on Github external
def serve(destination, port, config):
    """Run a simple web server."""
    if os.path.exists(destination):
        pass
    elif os.path.exists(config):
        settings = read_settings(config)
        destination = settings.get('destination')
        if not os.path.exists(destination):
            sys.stderr.write("The '{}' directory doesn't exist, maybe try "
                             "building first?\n".format(destination))
            sys.exit(1)
    else:
        sys.stderr.write("The {destination} directory doesn't exist "
                         "and the config file ({config}) could not be read.\n"
                         .format(destination=destination, config=config))
        sys.exit(2)

    print('DESTINATION : {}'.format(destination))
    os.chdir(destination)
    Handler = server.SimpleHTTPRequestHandler
    httpd = socketserver.TCPServer(("", port), Handler, False)
    print(" * Running on http://127.0.0.1:{}/".format(port))