Statistics
| Branch: | Tag: | Revision:

root / fabfile.py @ e4740989

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
    yield
155
    git("checkout %s" % current_branch)
156

    
157

    
158
#
159
# Debian packaging helpers
160
#
161

    
162
env.debian_branch = 'debian-0.8'
163
env.deb_packages = ['snf-common', 'snf-app', 'snf-ganeti-tools', 'snf-webproject']
164
env.signdebs = True
165

    
166

    
167
def _last_commit(f):
168
    return local("git rev-list --all --date-order --max-count=1 %s" % f,
169
            capture=True).strip()
170

    
171

    
172
def _diff_from_master(c,f):
173
    return local("git log --oneline %s..master %s" \
174
                 " | wc -l" % (c, f), capture=True)
175

    
176

    
177
def dch(p):
178
    with co(env.debian_branch):
179
        local("git merge master")
180
        with lcd(package_root(p)):
181
            local("ls .git || mkdir .git")
182

    
183
            # check for new changes in package dir
184
            diff = _diff_from_master(_last_commit("debian/changelog"), ".")
185
            vercmd  = "git describe --tags --abbrev=0 "\
186
                      " | sed -rn '\''s/^v(.*)/\\1/p'\''"
187
            version = local(vercmd, capture=True)
188
            if int(diff) > 0:
189
                local("git-dch --debian-branch=%s --auto " \
190
                      "--spawn-editor=always -N%s" % (env.debian_branch, version))
191
                local("git commit debian/changelog " \
192
                      "-m 'Updated %s changelog'" % p)
193

    
194
            local("rm -r .git")
195

    
196

    
197
def nosigndebs():
198
    env.signdebs = False
199

    
200

    
201
def builddeb(p, master="master", branch="debian-0.8"):
202
    with co(branch):
203
        with lcd(package_root(p)):
204
            local("git merge master")
205
            local("if [ ! -d .git ]; then mkdir .git; fi")
206
            local("python setup.py clean")
207
            local("git add synnefo/versions/*.py -f")
208
            local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
209
                   " --git-export=INDEX --git-ignore-new %s") %
210
                   (master, branch, "" if env.signdebs else "-us -uc"))
211
            local("rm -rf .git")
212
            local("git reset synnefo/versions/*.py")
213

    
214

    
215
def builddeball(b="debian-0.8"):
216
    for p in env.deb_packages:
217
        builddeb(p, b)
218
    collectdebs()
219

    
220

    
221
def collectdebs():
222
    build_area = env.get('build_area', '../build-area')
223
    for p in env.deb_packages:
224
        local("cp %s/%s*.deb ./packages/" % (build_area, p))
225

    
226
@roles('pypi')
227
def uploadtars():
228
    put("packages/*.tar.gz", 'www/pypi/')
229