root / fabfile.py @ 98df1105
History | View | Annotate | Download (6.2 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-app', 'snf-ganeti-tools', 'snf-webproject', |
46 |
'snf-okeanos-site']
|
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 |
# coloured 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 |
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 |
local("rm -r dist build")
|
90 |
local("python setup.py egg_info -d sdist")
|
91 |
|
92 |
|
93 |
def install_pkg(p): |
94 |
info("installing package: %s" % p)
|
95 |
with lcd(package_root(p)):
|
96 |
if env.develop:
|
97 |
local("python setup.py develop")
|
98 |
else:
|
99 |
local("python setup.py install")
|
100 |
|
101 |
|
102 |
def install(*packages): |
103 |
for p in packages: |
104 |
install_pkg("snf-%s" % p)
|
105 |
|
106 |
|
107 |
def buildall(): |
108 |
for p in env.packages: |
109 |
build_pkg(p) |
110 |
collectdists() |
111 |
|
112 |
|
113 |
def installall(): |
114 |
for p in env.packages: |
115 |
install_pkg(p) |
116 |
|
117 |
def collectdists(): |
118 |
if os.path.exists("./packages"): |
119 |
notice("removing 'packages' directory")
|
120 |
local("rm -r packages");
|
121 |
|
122 |
local("mkdir packages");
|
123 |
for p in env.packages: |
124 |
local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
|
125 |
|
126 |
def removeall(): |
127 |
for p in env.packages: |
128 |
remove_pkg(p) |
129 |
|
130 |
|
131 |
def remove(*packages): |
132 |
for p in packages: |
133 |
remove_pkg("snf-%s" % p)
|
134 |
|
135 |
|
136 |
#
|
137 |
# GIT helpers
|
138 |
#
|
139 |
|
140 |
|
141 |
def git(params, locl=True): |
142 |
cmd = local if locl else run |
143 |
return cmd("git %s" % params, capture=True) |
144 |
|
145 |
|
146 |
def branch(): |
147 |
return git("symbolic-ref HEAD").split("/")[-1] |
148 |
|
149 |
|
150 |
@contextmanager
|
151 |
def co(c): |
152 |
current_branch = branch(); |
153 |
git("checkout %s" % c)
|
154 |
# Use a try block to make sure we checkout the original branch.
|
155 |
try:
|
156 |
yield
|
157 |
finally:
|
158 |
git("checkout %s" % current_branch)
|
159 |
|
160 |
|
161 |
#
|
162 |
# Debian packaging helpers
|
163 |
#
|
164 |
|
165 |
env.debian_branch = 'debian-0.8'
|
166 |
env.deb_packages = ['snf-common', 'snf-app', 'snf-ganeti-tools', 'snf-webproject'] |
167 |
env.signdebs = True
|
168 |
|
169 |
|
170 |
def _last_commit(f): |
171 |
return local("git rev-list --all --date-order --max-count=1 %s" % f, |
172 |
capture=True).strip()
|
173 |
|
174 |
|
175 |
def _diff_from_master(c,f): |
176 |
return local("git log --oneline %s..master %s" \ |
177 |
" | wc -l" % (c, f), capture=True) |
178 |
|
179 |
|
180 |
def dch(p): |
181 |
with co(env.debian_branch):
|
182 |
local("git merge master")
|
183 |
with lcd(package_root(p)):
|
184 |
local("ls .git || mkdir .git")
|
185 |
|
186 |
# check for new changes in package dir
|
187 |
diff = _diff_from_master(_last_commit("debian/changelog"), ".") |
188 |
vercmd = "git describe --tags --abbrev=0 "\
|
189 |
" | sed -rn '\''s/^v(.*)/\\1/p'\''"
|
190 |
version = local(vercmd, capture=True)
|
191 |
if int(diff) > 0: |
192 |
local("git-dch --debian-branch=%s --auto " \
|
193 |
"--spawn-editor=always -N%s" % (env.debian_branch, version))
|
194 |
local("git commit debian/changelog " \
|
195 |
"-m 'Updated %s changelog'" % p)
|
196 |
|
197 |
local("rm -r .git")
|
198 |
|
199 |
|
200 |
def nosigndebs(): |
201 |
env.signdebs = False
|
202 |
|
203 |
|
204 |
def builddeb(p, master="master", branch="debian-0.8"): |
205 |
with co(branch):
|
206 |
info("Building debian package for %s" % p)
|
207 |
with lcd(package_root(p)):
|
208 |
local("git merge master")
|
209 |
local("if [ ! -d .git ]; then mkdir .git; fi")
|
210 |
local("python setup.py clean")
|
211 |
local("git add synnefo/versions/*.py -f")
|
212 |
local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
|
213 |
" --git-export=INDEX --git-ignore-new %s") %
|
214 |
(master, branch, "" if env.signdebs else "-us -uc")) |
215 |
local("rm -rf .git")
|
216 |
local("git reset synnefo/versions/*.py")
|
217 |
info("Done building debian package for %s" % p)
|
218 |
|
219 |
|
220 |
def builddeball(b="debian-0.8"): |
221 |
for p in env.deb_packages: |
222 |
builddeb(p, b) |
223 |
|
224 |
|
225 |
@roles('pypi') |
226 |
def uploadtars(): |
227 |
put("packages/*.tar.gz", 'www/pypi/') |