Feat: start using invoke

This commit is contained in:
Bertrand Benjamin 2020-07-01 14:54:16 +02:00
parent 4c5168e0ac
commit c28db4d91a
1 changed files with 25 additions and 4 deletions

View File

@ -17,15 +17,26 @@ LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
SETTINGS.update(LOCAL_SETTINGS) SETTINGS.update(LOCAL_SETTINGS)
CONFIG = { CONFIG = {
'current_path': os.getcwd(),
'settings_base': SETTINGS_FILE_BASE, 'settings_base': SETTINGS_FILE_BASE,
'settings_publish': 'publishconf.py', 'settings_publish': 'publishconf.py',
'year_subfolder': '',
# Output path. Can be absolute or relative to tasks.py. Default: 'output' # Output path. Can be absolute or relative to tasks.py. Default: 'output'
'deploy_path': SETTINGS['OUTPUT_PATH'], 'deploy_path': SETTINGS['OUTPUT_PATH'],
'fake_path': '../output/',
# Remote server configuration # Remote server configuration
'ssh_user': 'sshcontent', 'ssh_user': 'sshcontent',
'ssh_host': 'Embrevade', 'ssh_host': 'Embrevade',
'ssh_port': '22', 'ssh_port': '22',
'ssh_path': '/var/www', 'ssh_path': '/home/sshcontent/opytex.org/www/',
# Rsync config
'rsync_exclude': '--exclude "pymath" --exclude "opytex" --exclude "enseignements"',
# Port for `serve` # Port for `serve`
'port': 8000, 'port': 8000,
} }
@ -40,6 +51,7 @@ def clean(c):
@task @task
def build(c): def build(c):
"""Build local version of site""" """Build local version of site"""
c.run('lessc {current_path}/theme/static/stylesheet/style.less {current_path}/theme/static/stylesheet/style.min.css -x'.format(**CONFIG))
c.run('pelican -s {settings_base}'.format(**CONFIG)) c.run('pelican -s {settings_base}'.format(**CONFIG))
@task @task
@ -107,9 +119,18 @@ def publish(c):
"""Publish to production via rsync""" """Publish to production via rsync"""
c.run('pelican -s {settings_publish}'.format(**CONFIG)) c.run('pelican -s {settings_publish}'.format(**CONFIG))
c.run( c.run(
'rsync --delete --exclude ".DS_Store" -pthrvz -c ' 'rsync --delete {rsync_exclude} -pthrvz -c '
'-e "ssh -p {ssh_port}" ' '-e "ssh " '
'{} {ssh_user}@{ssh_host}:{ssh_path}'.format( '{} {ssh_host}:{ssh_path}'.format(
CONFIG['deploy_path'].rstrip('/') + '/', CONFIG['deploy_path'].rstrip('/') + '/',
**CONFIG)) **CONFIG))
@task(
pre=[build]
)
def fake(c):
""" Mimic a push to server """
print('{fake_path}{year_subfolder}'.format(**CONFIG))
os.makedirs('{fake_path}{year_subfolder}'.format(**CONFIG), exist_ok=True)
c.run('rsync -P -rvzc --delete {rsync_exclude} {deploy_path}/ {fake_path}{year_subfolder} --cvs-exclude'.format(**CONFIG))