-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
99 lines (79 loc) · 2.46 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
from fabric.api import *
import os
import socket
def lrun(*args, **kwargs):
func = local if socket.gethostname() == 'ngtshead' else run
return func(*args, **kwargs)
def change_dir(*args, **kwargs):
func = lcd if socket.gethostname() == 'ngtshead' else cd
return func(*args, **kwargs)
env.use_ssh_config = True
env.hosts = ['ngtshead']
PIPELINE_DIR = '/ngts/pipedev/ZLP'
change_to_pipeline_dir = lambda: change_dir(PIPELINE_DIR)
@task
def update():
'''
Push current changes and update on ngtshead
'''
push_local()
update_remote()
@task
def push_local(remote='origin', branch='master'):
'''
Push <remote>/<branch> to remote
'''
local('git push {remote} {branch}'.format(remote=remote, branch=branch))
@task
def update_remote(remote='origin', branch='master'):
'''
Checkout <remote>/<branch> on ngtshead and update submodules
'''
with change_to_pipeline_dir():
lrun('git fetch {remote}'.format(remote=remote))
lrun('git checkout {branch}'.format(branch=branch))
lrun('git merge --ff {remote}/{branch}'.format(remote=remote, branch=branch))
lrun('git submodule update')
# Update each submodule completely
lrun('git submodule foreach git submodule update --init --recursive')
@task
def test_remote(sourcedir='source20150817'):
'''
Run test on ngtshead with <sourcedir>
'''
update()
with change_to_pipeline_dir():
lrun('./test.sh {sourcedir}'.format(sourcedir=sourcedir))
def submodules(fname):
root_dir = os.path.realpath(os.path.dirname(fname))
with open(fname) as infile:
for line in infile:
if 'path' in line:
stub = line.strip().split('=')[-1].strip()
yield os.path.join(root_dir, stub)
@task
def update_submodules():
'''
Update all submodules to origin/master
'''
for path in submodules('.gitmodules'):
with lcd(path):
local('git fetch origin')
local('git checkout origin/master')
@task
def install_python_packages():
'''
Install the required python packages.
'''
has_conda = local('conda 2>/dev/null >/dev/null').return_code == 0
if has_conda:
local('conda install --file requirements.conda.txt')
local('pip install -r requirements.txt')
@task
def init():
'''
Initialises the pipeline repository
'''
install_python_packages()
local('git submodule init')
local('git submodule update')