-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
163 lines (133 loc) · 3.91 KB
/
pavement.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Copyright (c) 2010-2012 Adi Roiban.
# See LICENSE for details.
'''
Build script for Chevah Server buildbot slave.
It should work on all operating system, including Windows.
'''
import sys
import os
from paver.easy import cmdopts, needs, task, consume_args, pushd
from paver.tasks import help
BUILD_PACKAGES = [
# Main slave package.
# We specify a custom twisted package, to use our patched version.
'twisted==15.5.0.chevah7',
'buildbot-slave==0.8.11.pre.143.gac88f1b.c1',
'zope.interface==3.8.0',
# Required for some unicode handling.
'unidecode',
]
from brink.pavement_commons import (
clean,
default,
harness,
lint,
pave,
SETUP,
)
# Make pyflakes shut up.
clean
default
harness
help
lint
SETUP['folders']['source'] = 'src'
SETUP['buildbot']['server'] = 'buildbot.chevah.com'
SETUP['buildbot']['web_url'] = 'https://chevah.com/buildbot/'
SETUP['pypi']['index_url'] = 'http://pypi.chevah.com/simple'
option_name = (
'name=',
'n',
'Name of the buildslave. '
'Must be a name configured in the buildbot master.',
)
@task
def deps():
"""
Copy external dependencies.
"""
print('Installing dependencies to %s...' % (pave.path.build))
pave.pip(
command='install',
arguments=BUILD_PACKAGES,
)
@task
def build():
'''Copy the required files for running buildbot.'''
target = pave.path.build
pave.fs.copyFolder(source=['src'], destination=[target, 'slave'])
ip = pave.getIPAddress()
pave.fs.appendContentToFile(
destination=[target, 'slave', 'info', 'host'],
content='\n' + ip + '\n')
@task
@consume_args
def buildslave(args):
'''Run the buildslave command.'''
from buildslave.scripts import runner
new_args = ['buildslave']
new_args.extend(args)
sys.argv = new_args
with pushd(pave.fs.join(pave.path.build, 'slave')):
runner.run()
@task
@needs('deps', 'build')
@cmdopts([option_name])
def start(options):
'''Start the slave buildbot.'''
_remove_empty_pid_file()
from buildslave.scripts import runner
# Set buildslave name to be used in buildbot.tac.
sys.buildslave_name = pave.getOption(
options, 'start', 'name', default_value=pave.getHostname())
new_args = [
'buildslave', 'start', pave.fs.join([pave.path.build, 'slave'])]
sys.argv = new_args
runner.run()
@task
def stop():
'''Stop the master buildbot.'''
from buildslave.scripts import runner
new_args = [
'buildslave', 'stop', pave.fs.join([pave.path.build, 'slave'])]
sys.argv = new_args
runner.run()
@task
@needs('build')
@cmdopts([option_name])
def debug(options):
'''Run the buildslave without forking in background.'''
_remove_empty_pid_file()
# Set buildslave name to be used in buildbot.tac.
sys.buildslave_name = pave.getOption(
options, 'debug', 'name', default_value=pave.getHostname())
argv = [
'twistd',
'--no_save',
'--nodaemon',
'--logfile=-',
'--python=buildbot.tac',
]
sys.argv = argv
try:
from setproctitle import setproctitle
setproctitle # Shut up the linter.
except ImportError:
setproctitle = lambda t: None
setproctitle('buildbot-slave')
from twisted.scripts import twistd
with pushd(pave.fs.join([pave.path.build, 'slave'])):
twistd.run()
def _remove_empty_pid_file():
"""
Remove zero-sized PID file from Twisted. Otherwise, Twisted fails to start.
"""
pid_name = 'twistd.pid'
with pushd(pave.fs.join([pave.path.build, 'slave'])):
if not os.path.exists(pid_name):
# All good, there is no PID file, nothing to do.
return
if os.stat(pid_name).st_size == 0:
# PID file is empty. Remove it to prevent Twisted bailing out.
print('Removing zero-sized PID file from Twisted: %s' % (pid_name))
os.remove(pid_name)