root / devtools / fabfile.py @ 48130d8d
History | View | Annotate | Download (9 kB)
1 |
# Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
#
|
34 |
|
35 |
import os |
36 |
import sys |
37 |
|
38 |
from contextlib import contextmanager |
39 |
from fabric.api import * |
40 |
from fabric.colors import * |
41 |
|
42 |
env.project_root = "./"
|
43 |
env.develop = False
|
44 |
env.autoremove = True
|
45 |
|
46 |
env.packages = ['snf-common', 'snf-cyclades-app', 'snf-cyclades-gtools', |
47 |
'snf-webproject', 'snf-pithos-backend', 'snf-pithos-app', |
48 |
'snf-pithos-tools', 'snf-astakos-app'] |
49 |
|
50 |
env.capture = False
|
51 |
env.colors = True
|
52 |
env.pypi_root = 'pypi'
|
53 |
env.roledefs = { |
54 |
'docs': ['docs.dev.grnet.gr'], |
55 |
'pypi': ['docs.dev.grnet.gr'] |
56 |
} |
57 |
|
58 |
|
59 |
# colored logging
|
60 |
notice = lambda x: sys.stdout.write(yellow(x) + "\n") |
61 |
info = lambda x: sys.stdout.write(green(x) + "\n") |
62 |
error = lambda x: sys.stdout.write(red(x) + "\n") |
63 |
|
64 |
|
65 |
def dev(): |
66 |
env.develop = True
|
67 |
|
68 |
|
69 |
# wrap local to respect global capturing setting from env.capture
|
70 |
oldlocal = local |
71 |
def local(cmd, capture="default"): |
72 |
if capture != "default": |
73 |
capture = capture |
74 |
else:
|
75 |
capture = env.capture |
76 |
return oldlocal(cmd, capture=capture)
|
77 |
|
78 |
|
79 |
def package_root(p): |
80 |
return os.path.join(env.project_root, p)
|
81 |
|
82 |
|
83 |
def remove_pkg(p): |
84 |
notice("uninstalling package: %s" % p)
|
85 |
with lcd(package_root(p)):
|
86 |
with settings(warn_only=True): |
87 |
local("pip uninstall %s -y" % p, env.capture)
|
88 |
|
89 |
|
90 |
def build_pkg(p): |
91 |
info ("building package: %s" % p)
|
92 |
with lcd(package_root(p)):
|
93 |
local("if [ -d dist ]; then rm -r dist; fi;")
|
94 |
local("if [ -d build ]; then rm -r build; fi;")
|
95 |
local("python setup.py egg_info -d sdist")
|
96 |
|
97 |
|
98 |
def install_pkg(p): |
99 |
info("installing package: %s" % p)
|
100 |
with lcd(package_root(p)):
|
101 |
if env.develop:
|
102 |
local("python setup.py develop")
|
103 |
else:
|
104 |
local("python setup.py install")
|
105 |
|
106 |
|
107 |
def install(*packages): |
108 |
for p in packages: |
109 |
install_pkg("snf-%s" % p)
|
110 |
|
111 |
|
112 |
def buildall(): |
113 |
for p in env.packages: |
114 |
build_pkg(p) |
115 |
collectdists() |
116 |
|
117 |
|
118 |
def installall(): |
119 |
for p in env.packages: |
120 |
install_pkg(p) |
121 |
|
122 |
|
123 |
def collectdists(): |
124 |
if os.path.exists("./packages"): |
125 |
notice("removing 'packages' directory")
|
126 |
local("rm -r packages");
|
127 |
|
128 |
local("mkdir packages");
|
129 |
for p in env.packages: |
130 |
local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
|
131 |
|
132 |
|
133 |
def removeall(): |
134 |
for p in env.packages: |
135 |
remove_pkg(p) |
136 |
|
137 |
|
138 |
def remove(*packages): |
139 |
for p in packages: |
140 |
remove_pkg("snf-%s" % p)
|
141 |
|
142 |
|
143 |
#
|
144 |
# GIT helpers
|
145 |
#
|
146 |
|
147 |
|
148 |
def git(params, locl=True): |
149 |
cmd = local if locl else run |
150 |
return cmd("git %s" % params, capture=True) |
151 |
|
152 |
|
153 |
def branch(): |
154 |
return git("symbolic-ref HEAD").split("/")[-1] |
155 |
|
156 |
|
157 |
@contextmanager
|
158 |
def co(c): |
159 |
current_branch = branch(); |
160 |
git("checkout %s" % c)
|
161 |
# Use a try block to make sure we checkout the original branch.
|
162 |
try:
|
163 |
yield
|
164 |
finally:
|
165 |
try:
|
166 |
git("checkout %s" % current_branch)
|
167 |
except Exception: |
168 |
error("Could not checkout %s, you're still left at %s" % c)
|
169 |
|
170 |
#
|
171 |
# Debian packaging helpers
|
172 |
#
|
173 |
|
174 |
env.debian_branch = 'debian'
|
175 |
env.deb_packages = ['snf-common', 'snf-cyclades-app', 'snf-cyclades-gtools', |
176 |
'snf-webproject', 'snf-pithos-backend', 'snf-pithos-tools', |
177 |
'snf-pithos-app', 'snf-astakos-app'] |
178 |
env.signdebs = True
|
179 |
env.debrelease = False # Increase release number in Debian changelogs |
180 |
|
181 |
def _last_commit(f): |
182 |
return local("git rev-list --all --date-order --max-count=1 %s" % f, |
183 |
capture=True).strip()
|
184 |
|
185 |
|
186 |
def _diff_from_master(c,f): |
187 |
return local("git log --oneline %s..master %s" \ |
188 |
" | wc -l" % (c, f), capture=True) |
189 |
|
190 |
|
191 |
def dch(p): |
192 |
with co(env.debian_branch):
|
193 |
local("git merge master")
|
194 |
local("git merge %s" % env.upstream)
|
195 |
with lcd(package_root(p)):
|
196 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
197 |
|
198 |
# FIXME:
|
199 |
# Checking for new changes in packages
|
200 |
# has been removed temporarily.
|
201 |
# Always create a new Debian changelog entry.
|
202 |
## Check for new changes in package dir
|
203 |
#diff = _diff_from_master(_last_commit("debian/changelog"), ".")
|
204 |
#vercmd = "git describe --tags --abbrev=0"\
|
205 |
# " | sed -rn '\''s/^v(.*)/\\1/p'\''"
|
206 |
#version = local(vercmd, capture=True)
|
207 |
#if int(diff) > 0:
|
208 |
if True: |
209 |
# Run git-dch in snapshot mode.
|
210 |
# TODO: Support a --release mode in fabfile
|
211 |
if not env.debrelease: |
212 |
notice(("Producing snapshot changelog entry, "
|
213 |
"use 'debrelease' to produce release entries."))
|
214 |
local(("git-dch --debian-branch=%s --auto %s" %
|
215 |
(env.debian_branch, |
216 |
"--release" if env.debrelease else "--snapshot"))) |
217 |
local(("git commit debian/changelog"
|
218 |
" -m 'Updated %s changelog'" % p))
|
219 |
notice(("Make sure to tag Debian release in %s" %
|
220 |
env.debian_branch)) |
221 |
|
222 |
local("rmdir .git")
|
223 |
|
224 |
|
225 |
def dchall(): |
226 |
for p in env.deb_packages: |
227 |
info("updating debian changelog for package: %s" % p)
|
228 |
dch(p) |
229 |
|
230 |
|
231 |
def debrelease(): |
232 |
env.debrelease = True
|
233 |
|
234 |
|
235 |
def signdebs(): |
236 |
env.signdebs = True
|
237 |
|
238 |
|
239 |
# Commands which automatically add and reset the version files which are not tracked by
|
240 |
# git. Those version files are created from each setup.py using the synnefo-common
|
241 |
# update_version, so we execute `python setup.py clean` to ensure that file gets
|
242 |
# created and git add will not fail. The reset of those files after each build
|
243 |
# certifies that succeded git checkouts will not fail due to existing local
|
244 |
# changes.
|
245 |
add_versions_cmd = "find . -regextype posix-egrep -regex \".*version.py$|.*\/synnefo\/versions\/.*py$\" -exec git add -f {} \;"
|
246 |
reset_versions_cmd = "find . -regextype posix-egrep -regex \".*version.py$|.*\/synnefo\/versions\/.*py$\" -exec git reset {} \;"
|
247 |
|
248 |
|
249 |
def builddeb(p, master="master", branch="debian-0.8"): |
250 |
with co(branch):
|
251 |
info("Building debian package for %s" % p)
|
252 |
with lcd(package_root(p)):
|
253 |
local("git merge master")
|
254 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
255 |
local("python setup.py clean")
|
256 |
local(add_versions_cmd) |
257 |
local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
|
258 |
" --git-export=INDEX --git-ignore-new %s") %
|
259 |
(master, branch, "" if env.signdebs else "-us -uc")) |
260 |
local("rm -rf .git")
|
261 |
local(reset_versions_cmd) |
262 |
info("Done building debian package for %s" % p)
|
263 |
|
264 |
|
265 |
def builddeball(b="debian-0.8"): |
266 |
for p in env.deb_packages: |
267 |
builddeb(p=p, branch=b) |
268 |
|
269 |
|
270 |
@roles('pypi') |
271 |
def uploadtars(): |
272 |
put("packages/*.tar.gz", 'www/pypi/') |
273 |
|
274 |
|
275 |
def cleandocs(): |
276 |
"""
|
277 |
Remove _build directories for each doc project
|
278 |
"""
|
279 |
|
280 |
# docs contains conf.py in root directory
|
281 |
if os.path.exists("docs/docs/_build"): |
282 |
local("rm -r docs/docs/_build")
|
283 |
|
284 |
for p in env.packages: |
285 |
buildpth = os.path.join(package_root(p), 'docs', '_build') |
286 |
if os.path.exists(buildpth):
|
287 |
local('rm -r %s' % buildpth)
|
288 |
|
289 |
|
290 |
def builddocs(): |
291 |
"""
|
292 |
Run sphinx builder for each project separately
|
293 |
"""
|
294 |
builddocs_cmd = "sphinx-build -b html -d _build/doctrees . _build/html"
|
295 |
|
296 |
# docs contains conf.py in root directory
|
297 |
with lcd("docs"): |
298 |
local(builddocs_cmd) |
299 |
|
300 |
for p in env.packages: |
301 |
info("Building %s docs" % p)
|
302 |
docspth = os.path.join(package_root(p), 'docs')
|
303 |
if os.path.exists(docspth):
|
304 |
with lcd(docspth):
|
305 |
local(builddocs_cmd) |