root / fabfile.py @ c6b41340
History | View | Annotate | Download (4.8 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.deb_packages = ['snf-common', 'snf-app', 'snf-ganeti-tools', 'snf-webproject'] |
48 |
env.capture = False
|
49 |
env.colors = True
|
50 |
|
51 |
# coloured logging
|
52 |
notice = lambda x: sys.stdout.write(yellow(x) + "\n") |
53 |
info = lambda x: sys.stdout.write(green(x) + "\n") |
54 |
error = lambda x: sys.stdout.write(red(x) + "\n") |
55 |
|
56 |
|
57 |
def dev(): |
58 |
env.develop = True
|
59 |
|
60 |
# wrap local to respect global capturing setting from env.capture
|
61 |
oldlocal = local |
62 |
def local(cmd, capture="default"): |
63 |
if capture != "default": |
64 |
capture = capture |
65 |
else:
|
66 |
capture = env.capture |
67 |
return oldlocal(cmd, capture=capture)
|
68 |
|
69 |
|
70 |
def package_root(p): |
71 |
return os.path.join(env.project_root, p)
|
72 |
|
73 |
|
74 |
def remove_pkg(p): |
75 |
notice("uninstalling package: %s" % p)
|
76 |
with lcd(package_root(p)):
|
77 |
with settings(warn_only=True): |
78 |
local("pip uninstall %s -y" % p, env.capture)
|
79 |
|
80 |
|
81 |
def build_pkg(p): |
82 |
info ("building package: %s" % p)
|
83 |
with lcd(package_root(p)):
|
84 |
with settings(warn_only=True): |
85 |
local("rm -r dist build")
|
86 |
local("python setup.py sdist")
|
87 |
|
88 |
|
89 |
def install_pkg(p): |
90 |
info("installing package: %s" % p)
|
91 |
with lcd(package_root(p)):
|
92 |
if env.develop:
|
93 |
local("python setup.py develop")
|
94 |
else:
|
95 |
local("python setup.py install")
|
96 |
|
97 |
|
98 |
def install(*packages): |
99 |
for p in packages: |
100 |
install_pkg("snf-%s" % p)
|
101 |
|
102 |
|
103 |
def buildall(): |
104 |
for p in env.packages: |
105 |
build_pkg(p) |
106 |
collectdists() |
107 |
|
108 |
|
109 |
def installall(): |
110 |
for p in env.packages: |
111 |
install_pkg(p) |
112 |
|
113 |
def collectdists(): |
114 |
if os.path.exists("./packages"): |
115 |
notice("removing 'packages' directory")
|
116 |
local("rm -r packages");
|
117 |
|
118 |
local("mkdir packages");
|
119 |
for p in env.packages: |
120 |
local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
|
121 |
|
122 |
def removeall(): |
123 |
for p in env.packages: |
124 |
remove_pkg(p) |
125 |
|
126 |
|
127 |
def remove(*packages): |
128 |
for p in packages: |
129 |
remove_pkg("snf-%s" % p)
|
130 |
|
131 |
|
132 |
#
|
133 |
# GIT helpers
|
134 |
#
|
135 |
|
136 |
|
137 |
def git(params, locl=True): |
138 |
cmd = local if locl else run |
139 |
return cmd("git %s" % params, capture=True) |
140 |
|
141 |
|
142 |
def branch(): |
143 |
return git("symbolic-ref HEAD").split("/")[-1] |
144 |
|
145 |
|
146 |
@contextmanager
|
147 |
def co(c): |
148 |
current_branch = branch(); |
149 |
git("checkout %s" % c)
|
150 |
yield
|
151 |
git("checkout %s" % current_branch)
|
152 |
|
153 |
|
154 |
#
|
155 |
# Debian packaging helpers
|
156 |
#
|
157 |
|
158 |
|
159 |
def builddeb(p, master="master", branch="debian-0.8"): |
160 |
with lcd(package_root(p)):
|
161 |
with settings(warn_only=True): |
162 |
local("mkdir .git")
|
163 |
local("python setup.py clean")
|
164 |
local("git add synnefo/versions/*.py -f")
|
165 |
local("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s \
|
166 |
--git-export=INDEX --git-ignore-new" % (master, branch))
|
167 |
local("rm -rf .git")
|
168 |
local("git reset synnefo/versions/*.py")
|
169 |
|
170 |
|
171 |
def builddeball(b="debian-0.8"): |
172 |
with co(b):
|
173 |
for p in env.deb_packages: |
174 |
builddeb(p, b) |
175 |
collectdebs() |
176 |
|
177 |
|
178 |
def collectdebs(): |
179 |
build_area = env.get('build_area', '../build-area') |
180 |
for p in env.deb_packages: |
181 |
local("cp %s/%s*.deb ./packages/" % (build_area, p))
|
182 |
|