root / fabfile.py @ 61909d3e
History | View | Annotate | Download (8.7 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 |
env.packages = ['snf-common', 'snf-cyclades-app', 'snf-cyclades-gtools', |
46 |
'snf-webproject']
|
47 |
env.capture = False
|
48 |
env.colors = True
|
49 |
env.pypi_root = 'pypi'
|
50 |
env.roledefs = { |
51 |
'docs': ['docs.dev.grnet.gr'], |
52 |
'pypi': ['docs.dev.grnet.gr'] |
53 |
} |
54 |
|
55 |
|
56 |
# colored logging
|
57 |
notice = lambda x: sys.stdout.write(yellow(x) + "\n") |
58 |
info = lambda x: sys.stdout.write(green(x) + "\n") |
59 |
error = lambda x: sys.stdout.write(red(x) + "\n") |
60 |
|
61 |
|
62 |
def dev(): |
63 |
env.develop = True
|
64 |
|
65 |
|
66 |
# wrap local to respect global capturing setting from env.capture
|
67 |
oldlocal = local |
68 |
def local(cmd, capture="default"): |
69 |
if capture != "default": |
70 |
capture = capture |
71 |
else:
|
72 |
capture = env.capture |
73 |
return oldlocal(cmd, capture=capture)
|
74 |
|
75 |
|
76 |
def package_root(p): |
77 |
return os.path.join(env.project_root, p)
|
78 |
|
79 |
|
80 |
def remove_pkg(p): |
81 |
notice("uninstalling package: %s" % p)
|
82 |
with lcd(package_root(p)):
|
83 |
with settings(warn_only=True): |
84 |
local("pip uninstall %s -y" % p, env.capture)
|
85 |
|
86 |
|
87 |
def build_pkg(p): |
88 |
info ("building package: %s" % p)
|
89 |
with lcd(package_root(p)):
|
90 |
local("if [ -d dist ]; then rm -r dist; fi;")
|
91 |
local("if [ -d build ]; then rm -r build; fi;")
|
92 |
local("python setup.py egg_info -d sdist")
|
93 |
|
94 |
|
95 |
def install_pkg(p): |
96 |
info("installing package: %s" % p)
|
97 |
with lcd(package_root(p)):
|
98 |
if env.develop:
|
99 |
local("python setup.py develop")
|
100 |
else:
|
101 |
local("python setup.py install")
|
102 |
|
103 |
|
104 |
def install(*packages): |
105 |
for p in packages: |
106 |
install_pkg("snf-%s" % p)
|
107 |
|
108 |
|
109 |
def buildall(): |
110 |
for p in env.packages: |
111 |
build_pkg(p) |
112 |
collectdists() |
113 |
|
114 |
|
115 |
def installall(): |
116 |
for p in env.packages: |
117 |
install_pkg(p) |
118 |
|
119 |
|
120 |
def collectdists(): |
121 |
if os.path.exists("./packages"): |
122 |
notice("removing 'packages' directory")
|
123 |
local("rm -r packages");
|
124 |
|
125 |
local("mkdir packages");
|
126 |
for p in env.packages: |
127 |
local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
|
128 |
|
129 |
|
130 |
def removeall(): |
131 |
for p in env.packages: |
132 |
remove_pkg(p) |
133 |
|
134 |
|
135 |
def remove(*packages): |
136 |
for p in packages: |
137 |
remove_pkg("snf-%s" % p)
|
138 |
|
139 |
|
140 |
#
|
141 |
# GIT helpers
|
142 |
#
|
143 |
|
144 |
|
145 |
def git(params, locl=True): |
146 |
cmd = local if locl else run |
147 |
return cmd("git %s" % params, capture=True) |
148 |
|
149 |
|
150 |
def branch(): |
151 |
return git("symbolic-ref HEAD").split("/")[-1] |
152 |
|
153 |
|
154 |
@contextmanager
|
155 |
def co(c): |
156 |
current_branch = branch(); |
157 |
git("checkout %s" % c)
|
158 |
# Use a try block to make sure we checkout the original branch.
|
159 |
try:
|
160 |
yield
|
161 |
finally:
|
162 |
try:
|
163 |
git("checkout %s" % current_branch)
|
164 |
except Exception: |
165 |
error("Could not checkout %s, you're still left at %s" % c)
|
166 |
|
167 |
#
|
168 |
# Debian packaging helpers
|
169 |
#
|
170 |
|
171 |
env.debian_branch = 'debian-0.8'
|
172 |
env.deb_packages = ['snf-common', 'snf-cyclades-app', 'snf-cyclades-gtools', 'snf-webproject'] |
173 |
env.signdebs = False
|
174 |
env.debrelease = False # Increase release number in Debian changelogs |
175 |
|
176 |
|
177 |
|
178 |
def _last_commit(f): |
179 |
return local("git rev-list --all --date-order --max-count=1 %s" % f, |
180 |
capture=True).strip()
|
181 |
|
182 |
|
183 |
def _diff_from_master(c,f): |
184 |
return local("git log --oneline %s..master %s" \ |
185 |
" | wc -l" % (c, f), capture=True) |
186 |
|
187 |
|
188 |
def dch(p): |
189 |
with co(env.debian_branch):
|
190 |
local("git merge master")
|
191 |
with lcd(package_root(p)):
|
192 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
193 |
|
194 |
# FIXME:
|
195 |
# Checking for new changes in packages
|
196 |
# has been removed temporarily.
|
197 |
# Always create a new Debian changelog entry.
|
198 |
## Check for new changes in package dir
|
199 |
#diff = _diff_from_master(_last_commit("debian/changelog"), ".")
|
200 |
#vercmd = "git describe --tags --abbrev=0"\
|
201 |
# " | sed -rn '\''s/^v(.*)/\\1/p'\''"
|
202 |
#version = local(vercmd, capture=True)
|
203 |
#if int(diff) > 0:
|
204 |
if True: |
205 |
# Run git-dch in snapshot mode.
|
206 |
# TODO: Support a --release mode in fabfile
|
207 |
if not env.debrelease: |
208 |
notice(("Producing snapshot changelog entry, "
|
209 |
"use 'debrelease' to produce release entries."))
|
210 |
local(("git-dch --debian-branch=%s --auto %s" %
|
211 |
(env.debian_branch, |
212 |
"--release" if env.debrelease else "--snapshot"))) |
213 |
local(("git commit debian/changelog"
|
214 |
" -m 'Updated %s changelog'" % p))
|
215 |
notice(("Make sure to tag Debian release in %s" %
|
216 |
env.debian_branch)) |
217 |
|
218 |
local("rmdir .git")
|
219 |
|
220 |
|
221 |
def dchall(): |
222 |
for p in env.deb_packages: |
223 |
info("updating debian changelog for package: %s" % p)
|
224 |
dch(p) |
225 |
|
226 |
|
227 |
def debrelease(): |
228 |
env.debrelease = True
|
229 |
|
230 |
|
231 |
def signdebs(): |
232 |
env.signdebs = True
|
233 |
|
234 |
|
235 |
# Commands which automatically add and reset the version files which are not tracked by
|
236 |
# git. Those version files are created from each setup.py using the synnefo-common
|
237 |
# update_version, so we execute `python setup.py clean` to ensure that file gets
|
238 |
# created and git add will not fail. The reset of those files after each build
|
239 |
# certifies that succeded git checkouts will not fail due to existing local
|
240 |
# changes.
|
241 |
add_versions_cmd = "find . -regextype posix-egrep -regex \".*version.py$|.*\/synnefo\/versions\/.*py$\" -exec git add -f {} \;"
|
242 |
reset_versions_cmd = "find . -regextype posix-egrep -regex \".*version.py$|.*\/synnefo\/versions\/.*py$\" -exec git reset {} \;"
|
243 |
|
244 |
|
245 |
def builddeb(p, master="master", branch="debian-0.8"): |
246 |
with co(branch):
|
247 |
info("Building debian package for %s" % p)
|
248 |
with lcd(package_root(p)):
|
249 |
local("git merge master")
|
250 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
251 |
local("python setup.py clean")
|
252 |
local(add_versions_cmd) |
253 |
local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
|
254 |
" --git-export=INDEX --git-ignore-new %s") %
|
255 |
(master, branch, "" if env.signdebs else "-us -uc")) |
256 |
local("rm -rf .git")
|
257 |
local(reset_versions_cmd) |
258 |
info("Done building debian package for %s" % p)
|
259 |
|
260 |
|
261 |
def builddeball(b="debian-0.8"): |
262 |
for p in env.deb_packages: |
263 |
builddeb(p=p, branch=b) |
264 |
|
265 |
|
266 |
@roles('pypi') |
267 |
def uploadtars(): |
268 |
put("packages/*.tar.gz", 'www/pypi/') |
269 |
|
270 |
|
271 |
def cleandocs(): |
272 |
"""
|
273 |
Remove _build directories for each doc project
|
274 |
"""
|
275 |
|
276 |
# docs contains conf.py in root directory
|
277 |
if os.path.exists("docs/docs/_build"): |
278 |
local("rm -r docs/docs/_build")
|
279 |
|
280 |
for p in env.packages: |
281 |
buildpth = os.path.join(package_root(p), 'docs', '_build') |
282 |
if os.path.exists(buildpth):
|
283 |
local('rm -r %s' % buildpth)
|
284 |
|
285 |
|
286 |
def builddocs(): |
287 |
"""
|
288 |
Run sphinx builder for each project separately
|
289 |
"""
|
290 |
builddocs_cmd = "sphinx-build -b html -d _build/doctrees . _build/html"
|
291 |
|
292 |
# docs contains conf.py in root directory
|
293 |
with lcd("docs"): |
294 |
local(builddocs_cmd) |
295 |
|
296 |
for p in env.packages: |
297 |
info("Building %s docs" % p)
|
298 |
docspth = os.path.join(package_root(p), 'docs')
|
299 |
if os.path.exists(docspth):
|
300 |
with lcd(docspth):
|
301 |
local(builddocs_cmd) |