-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
67 lines (60 loc) · 1.95 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
import sys
import json
import os
from fabric.api import cd, env, run, task, require, sudo, local
from fabric.colors import green, red, white, yellow, blue
from fabric.contrib.console import confirm
from fabric.contrib.files import exists
from fabric.operations import get
from fabric import state
from fabutils import boolean
from datetime import date
from time import gmtime, strftime
from fabutils.env import set_env_from_json_file
from fabutils.tasks import ursync_project, ulocal, urun
@task
def environment(env_name, debug=False):
"""
Creates the configurations for the environment in which tasks will run.
"""
schemas_dir = "conf/json_schemas/"
state.output['running'] = boolean(debug)
state.output['stdout'] = boolean(debug)
print "Establishing environment " + blue(env_name, bold=True) + "..."
try:
set_env_from_json_file(
'environments.json',
env_name,
schemas_dir + "environment_schema.json"
)
env.env_name = env_name
env.confirm_task = True
env.is_vagrant = False
if env_name == "vagrant":
result = ulocal('vagrant ssh-config | grep IdentityFile',
capture=True)
env.key_filename = result.split()[1].replace('"', '')
env.is_vagrant = True
except ValueError:
print red("environments.json has wrong format.", bold=True)
sys.exit(1)
@task
def sync_files():
"""
Sync modified files and establish necessary permissions in selected environment.
"""
require('group', 'public_dir')
print white("Uploading code to server...", bold=True)
ursync_project(
local_dir='./',
remote_dir=env.public_dir,
exclude=env.exclude,
delete=True,
default_opts='-chrtvzP'
)
@task
def execute(command=""):
env.command = command
with cd('{public_dir}'.format(**env)):
run('{command}'.format(**env))