-
Notifications
You must be signed in to change notification settings - Fork 19
/
fabfile.py
52 lines (41 loc) · 1.67 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from fabric.api import put, sudo, local, run, cd, prefix, task, abort, env
from fabric.contrib.console import confirm
import os.path
import sys
def load_settings():
import yaml
if os.path.exists('config.local.yml'):
config_file = 'config.local.yml'
with open(config_file) as config_file_handle:
site_config = yaml.load(config_file_handle.read())
env.blug_content_dir = site_config['output_dir']
env.public_html_dir = site_config['public_html_dir']
env.remote_staging_dir = site_config['remote_staging_dir']
@task
def check_git_status():
status_lines = local('git status --porcelain', capture=True)
if status_lines and not confirm('Working directory not clean! Deploy anyway?'):
abort('Working directory not clean')
@task
def generate_site():
with prefix('source /usr/bin/virtualenvwrapper.sh'), prefix('workon blug'):
local('python blug.py generate')
def copy_to_remote():
load_settings()
check_git_status()
if not os.path.exists(env.blug_content_dir):
sys.exit('{} is not a valid path on the local machine'.format(env.blug_content_dir))
if os.path.exists('content.tar.gz'):
os.unlink('content.tar.gz')
local('tar -cf content.tar ' + env.blug_content_dir)
local('gzip content.tar')
with cd(env.remote_staging_dir):
run('rm -rf *')
put('content.tar.gz', env.remote_staging_dir)
run('tar -xzf content.tar.gz')
sudo('rm -rf {public_html_dir}/*'.format(public_html_dir=env.public_html_dir))
sudo('cp -rp {source}/* {dest}'.format(source=env.blug_content_dir, dest=env.public_html_dir))
@task
def deploy():
generate_site()
copy_to_remote()