-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfabfile.py
141 lines (102 loc) · 3.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from fabric.api import env, run, cd, sudo
from fabric.api import task
import json
from fabric.colors import green, blue, red
def _pull_git(cwd, branch=""):
with cd(_build_cwd(cwd)):
run('git pull origin {0}'.format(branch))
def _build_local(cwd):
with cd(_build_cwd(cwd)):
sudo('python setup.py install')
def _build_cwd(subdir):
return '/home/{0}/{1}'.format(env.user, subdir)
def _update_pipeline(branch=""):
_pull_git('semantics_pipeline', branch)
def _update_preprocessing(branch=''):
_pull_git('semantics-preprocessing', branch)
def _update_owscapable(branch=''):
_pull_git('OwsCapable', branch)
def _build_preprocessing():
_build_local('semantics-preprocessing')
def _build_owscapable():
_build_local('OwsCapable')
def _clear_outputs(empties):
# list of directory paths (pipes/cleaned/*)
with cd(_build_cwd('semantics_pipeline')):
for empty in empties.split(';'):
run('rm -rf %s' % empty)
def _run_pipeline(workflow, local_config, local_directory, start, end, interval):
with cd(_build_cwd('semantics_pipeline')):
run('python workflow_manager.py -w {0} -d {1} -c {2} -s {3} -e {4} -i {5}'.format(
workflow, local_directory, local_config, start, end, interval))
def _query_solr(connection, query, directory, start, end, interval):
with cd(_build_cwd('semantics_pipeline')):
run('python local/solr_tasks.py -c {0} -q {1} -d {2} -i {3} -s {4} -e {5}'.format(
connection,
query,
directory,
interval,
start,
end
))
@task
def set_server(conf):
with open(conf, 'r') as f:
config = json.loads(f.read())
env.user = config.get('server', {}).get('user')
env.hosts = [config.get('server', {}).get('host')]
env.key_filename = [config.get('server', {}).get('key_path')]
@task
def clear_pipeline(clean_directories=""):
if not clean_directories:
print(red('Directory list empty. No deletes.'))
return
_clear_outputs(clean_directories)
@task
def deploy_pipeline(branch=""):
_update_pipeline(branch)
print(green('semantics_pipeline deploy complete!'))
@task
def deploy_processing(branch=""):
_update_preprocessing(branch)
_build_preprocessing()
print(green('semantics-preprocessing deploy complete!'))
@task
def deploy_owscapable(branch=""):
_update_owscapable(branch)
_build_owscapable()
print(green('OwsCapable deploy complete!'))
@task
def run_remote_pipeline(conf):
with open(conf, 'r') as f:
config = json.loads(f.read())
workflow = config.get('workflow', {})
_run_pipeline(
workflow.get('workflow'),
workflow.get('local_config'),
workflow.get('local_directory'),
workflow.get('start'),
workflow.get('end'),
workflow.get('interval')
)
@task
def return_pipeline_counts(directories):
counts = []
with cd(_build_cwd('semantics_pipeline')):
for d in directories.split(';'):
counts.append((d, run('ls -l {0} | wc -l'.format(d))))
for d, c in counts:
print(blue('{0} contains {1} files'.format(d, c)))
@task
def query_solr(conf):
with open(conf, 'r') as f:
config = json.loads(f.read())
solr = config.get('solr', {})
_query_solr(
'"{0}"'.format(solr.get('connection', '')),
'"{0}"'.format(solr.get('query', '')),
solr.get('directory'),
solr.get('start'),
solr.get('stop'),
solr.get('interval')
)