1
0
Fork 0
forked from github/pelican

Invoke: Make settings file name handling more DRY

Instead of repeating hard-coded 'pelicanconf.py' values throughout
Invoke's task.py template, assign default settings file names to
variables, and use those variables where applicable.
This commit is contained in:
Justin Mayer 2019-06-19 16:11:16 +02:00
commit 4b5610175f

View file

@ -10,12 +10,15 @@ from invoke.util import cd
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
SETTINGS_FILE_BASE = 'pelicanconf.py'
SETTINGS = {}
SETTINGS.update(DEFAULT_CONFIG)
LOCAL_SETTINGS = get_settings_from_file('pelicanconf.py')
LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
SETTINGS.update(LOCAL_SETTINGS)
CONFIG = {
'settings_base': SETTINGS_FILE_BASE,
'settings_publish': 'publishconf.py',
# Output path. Can be absolute or relative to tasks.py. Default: 'output'
'deploy_path': SETTINGS['OUTPUT_PATH'],
{% if ssh %}
@ -48,17 +51,17 @@ def clean(c):
@task
def build(c):
"""Build local version of site"""
c.run('pelican -s pelicanconf.py')
c.run('pelican -s {settings_base}'.format(**CONFIG))
@task
def rebuild(c):
"""`build` with the delete switch"""
c.run('pelican -d -s pelicanconf.py')
c.run('pelican -d -s {settings_base}'.format(**CONFIG))
@task
def regenerate(c):
"""Automatically regenerate site upon file modification"""
c.run('pelican -r -s pelicanconf.py')
c.run('pelican -r -s {settings_base}'.format(**CONFIG))
@task
def serve(c):
@ -84,7 +87,7 @@ def reserve(c):
@task
def preview(c):
"""Build production version of site"""
c.run('pelican -s publishconf.py')
c.run('pelican -s {settings_publish}'.format(**CONFIG))
@task
def livereload(c):
@ -115,7 +118,7 @@ def cf_upload(c):
@task
def publish(c):
"""Publish to production via rsync"""
c.run('pelican -s publishconf.py')
c.run('pelican -s {settings_publish}'.format(**CONFIG))
c.run(
'rsync --delete --exclude ".DS_Store" -pthrvz -c '
'{} {production}:{dest_path}'.format(