root / fabfile.py @ 6e147ecc
History | View | Annotate | Download (6.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 |
env.packages = ['snf-pithos-backend', 'snf-pithos-app', 'snf-pithos-tools'] |
46 |
env.capture = False
|
47 |
env.colors = True
|
48 |
env.pypi_root = 'pypi'
|
49 |
env.roledefs = { |
50 |
'docs': ['docs.dev.grnet.gr'], |
51 |
'pypi': ['docs.dev.grnet.gr'] |
52 |
} |
53 |
|
54 |
|
55 |
# colored logging
|
56 |
notice = lambda x: sys.stdout.write(yellow(x) + "\n") |
57 |
info = lambda x: sys.stdout.write(green(x) + "\n") |
58 |
error = lambda x: sys.stdout.write(red(x) + "\n") |
59 |
|
60 |
|
61 |
def dev(): |
62 |
env.develop = True
|
63 |
|
64 |
|
65 |
# wrap local to respect global capturing setting from env.capture
|
66 |
oldlocal = local |
67 |
def local(cmd, capture="default"): |
68 |
if capture != "default": |
69 |
capture = capture |
70 |
else:
|
71 |
capture = env.capture |
72 |
return oldlocal(cmd, capture=capture)
|
73 |
|
74 |
|
75 |
def package_root(p): |
76 |
return os.path.join(env.project_root, p)
|
77 |
|
78 |
|
79 |
def remove_pkg(p): |
80 |
notice("uninstalling package: %s" % p)
|
81 |
with lcd(package_root(p)):
|
82 |
with settings(warn_only=True): |
83 |
local("pip uninstall %s -y" % p, env.capture)
|
84 |
|
85 |
|
86 |
def build_pkg(p): |
87 |
info ("building package: %s" % p)
|
88 |
with lcd(package_root(p)):
|
89 |
try:
|
90 |
local("rm -r dist build")
|
91 |
except:
|
92 |
pass
|
93 |
local("python setup.py egg_info -d sdist")
|
94 |
|
95 |
|
96 |
def install_pkg(p): |
97 |
info("installing package: %s" % p)
|
98 |
with lcd(package_root(p)):
|
99 |
if env.develop:
|
100 |
local("python setup.py develop")
|
101 |
else:
|
102 |
local("python setup.py install")
|
103 |
|
104 |
|
105 |
def install(*packages): |
106 |
for p in packages: |
107 |
install_pkg("snf-%s" % p)
|
108 |
|
109 |
|
110 |
def buildall(): |
111 |
for p in env.packages: |
112 |
build_pkg(p) |
113 |
collectdists() |
114 |
|
115 |
|
116 |
def installall(): |
117 |
for p in env.packages: |
118 |
install_pkg(p) |
119 |
|
120 |
|
121 |
def collectdists(): |
122 |
if os.path.exists("./packages"): |
123 |
notice("removing 'packages' directory")
|
124 |
local("rm -r packages");
|
125 |
|
126 |
local("mkdir packages");
|
127 |
for p in env.packages: |
128 |
local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
|
129 |
|
130 |
|
131 |
def removeall(): |
132 |
for p in env.packages: |
133 |
remove_pkg(p) |
134 |
|
135 |
|
136 |
def remove(*packages): |
137 |
for p in packages: |
138 |
remove_pkg("snf-%s" % p)
|
139 |
|
140 |
|
141 |
#
|
142 |
# GIT helpers
|
143 |
#
|
144 |
|
145 |
|
146 |
def git(params, locl=True): |
147 |
cmd = local if locl else run |
148 |
return cmd("git %s" % params, capture=True) |
149 |
|
150 |
|
151 |
def branch(): |
152 |
return git("symbolic-ref HEAD").split("/")[-1] |
153 |
|
154 |
|
155 |
@contextmanager
|
156 |
def co(c): |
157 |
current_branch = branch(); |
158 |
git("checkout %s" % c)
|
159 |
# Use a try block to make sure we checkout the original branch.
|
160 |
try:
|
161 |
yield
|
162 |
finally:
|
163 |
try:
|
164 |
git("checkout %s" % current_branch)
|
165 |
except Exception: |
166 |
error("Could not checkout %s, you're still left at %s" % c)
|
167 |
|
168 |
#
|
169 |
# Debian packaging helpers
|
170 |
#
|
171 |
|
172 |
env.debian_branch = 'debian-0.9'
|
173 |
env.deb_packages = ['snf-pithos-backend', 'snf-pithos-tools', 'snf-pithos-app'] |
174 |
env.signdebs = False
|
175 |
env.debrelease = False # Increase release number in Debian changelogs |
176 |
env.upstream = 'packaging'
|
177 |
|
178 |
|
179 |
def _last_commit(f): |
180 |
return local("git rev-list --all --date-order --max-count=1 %s" % f, |
181 |
capture=True).strip()
|
182 |
|
183 |
|
184 |
def _diff_from_master(c,f): |
185 |
return local("git log --oneline %s..%s %s" \ |
186 |
" | wc -l" % (c, env.upstream, f), capture=True) |
187 |
|
188 |
|
189 |
def dch(p): |
190 |
with co(env.debian_branch):
|
191 |
local("git merge %s" % env.upstream)
|
192 |
with lcd(package_root(p)):
|
193 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
194 |
|
195 |
# FIXME:
|
196 |
# Checking for new changes in packages
|
197 |
# has been removed temporarily.
|
198 |
# Always create a new Debian changelog entry.
|
199 |
## Check for new changes in package dir
|
200 |
#diff = _diff_from_master(_last_commit("debian/changelog"), ".")
|
201 |
#vercmd = "git describe --tags --abbrev=0"\
|
202 |
# " | sed -rn '\''s/^v(.*)/\\1/p'\''"
|
203 |
#version = local(vercmd, capture=True)
|
204 |
#if int(diff) > 0:
|
205 |
if True: |
206 |
# Run git-dch in snapshot mode.
|
207 |
# TODO: Support a --release mode in fabfile
|
208 |
local(("git-dch --debian-branch=%s --auto %s" %
|
209 |
(env.debian_branch, |
210 |
"--release" if env.debrelease else "--snapshot"))) |
211 |
local(("git commit debian/changelog"
|
212 |
" -m 'Updated %s changelog'" % p))
|
213 |
notice(("Make sure to tag Debian release in %s" %
|
214 |
env.debian_branch)) |
215 |
|
216 |
local("rmdir .git")
|
217 |
|
218 |
|
219 |
def debrelease(): |
220 |
env.debrelease = True
|
221 |
|
222 |
|
223 |
def signdebs(): |
224 |
env.signdebs = True
|
225 |
|
226 |
|
227 |
def builddeb(p, master="packaging", branch="debian-0.9"): |
228 |
with co(branch):
|
229 |
info("Building debian package for %s" % p)
|
230 |
with lcd(package_root(p)):
|
231 |
local("git merge %s" % master)
|
232 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
233 |
local("python setup.py clean")
|
234 |
local("git add ./*/*/version.py -f")
|
235 |
local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
|
236 |
" --git-export=INDEX --git-ignore-new %s") %
|
237 |
(master, branch, "" if env.signdebs else "-us -uc")) |
238 |
local("rm -rf .git")
|
239 |
local("git reset ./*/*/version.py")
|
240 |
info("Done building debian package for %s" % p)
|
241 |
|
242 |
|
243 |
def builddeball(b="debian-0.9"): |
244 |
for p in env.deb_packages: |
245 |
builddeb(p=p, branch=b) |
246 |
|
247 |
|
248 |
|
249 |
@roles('pypi') |
250 |
def uploadtars(): |
251 |
put("packages/*.tar.gz", 'www/pypi/') |
252 |
|