Statistics
| Branch: | Tag: | Revision:

root / fabfile.py @ 096f0cc3

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-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

    
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("rm -r dist build")
91
        local("python setup.py egg_info -d sdist")
92

    
93

    
94
def install_pkg(p):
95
    info("installing package: %s" % p)
96
    with lcd(package_root(p)):
97
        if env.develop:
98
            local("python setup.py develop")
99
        else:
100
            local("python setup.py install")
101

    
102

    
103
def install(*packages):
104
    for p in packages:
105
        install_pkg("snf-%s" % p)
106

    
107

    
108
def buildall():
109
    for p in env.packages:
110
        build_pkg(p)
111
    collectdists()
112

    
113

    
114
def installall():
115
    for p in env.packages:
116
        install_pkg(p)
117

    
118
def collectdists():
119
    if os.path.exists("./packages"):
120
        notice("removing 'packages' directory")
121
        local("rm -r packages");
122

    
123
    local("mkdir packages");
124
    for p in env.packages:
125
        local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
126

    
127
def removeall():
128
    for p in env.packages:
129
        remove_pkg(p)
130

    
131

    
132
def remove(*packages):
133
    for p in packages:
134
        remove_pkg("snf-%s" % p)
135

    
136

    
137
#
138
# GIT helpers
139
#
140

    
141

    
142
def git(params, locl=True):
143
    cmd = local if locl else run
144
    return cmd("git %s" % params, capture=True)
145

    
146

    
147
def branch():
148
    return git("symbolic-ref HEAD").split("/")[-1]
149

    
150

    
151
@contextmanager
152
def co(c):
153
    current_branch = branch();
154
    git("checkout %s" % c)
155
    # Use a try block to make sure we checkout the original branch.
156
    try:
157
        yield
158
    finally:
159
        try:
160
            git("checkout %s" % current_branch)
161
        except Exception:
162
            error("Could not checkout %s, you're still left at %s" % c)
163

    
164
#
165
# Debian packaging helpers
166
#
167

    
168
env.debian_branch = 'debian-0.8'
169
env.deb_packages = ['snf-common', 'snf-app', 'snf-ganeti-tools', 'snf-webproject']
170
env.signdebs = True
171
env.debrelease = False  # Increase release number in Debian changelogs
172

    
173

    
174
def _last_commit(f):
175
    return local("git rev-list --all --date-order --max-count=1 %s" % f,
176
            capture=True).strip()
177

    
178

    
179
def _diff_from_master(c,f):
180
    return local("git log --oneline %s..master %s" \
181
                 " | wc -l" % (c, f), capture=True)
182

    
183

    
184
def dch(p):
185
    with co(env.debian_branch):
186
        local("git merge master")
187
        with lcd(package_root(p)):
188
            local("if [ ! -d .git ]; then mkdir .git; fi")
189

    
190
            # FIXME:
191
            # Checking for new changes in packages
192
            # has been removed temporarily.
193
            # Always create a new Debian changelog entry.
194
            ## Check for new changes in package dir
195
            #diff = _diff_from_master(_last_commit("debian/changelog"), ".")
196
            #vercmd  = "git describe --tags --abbrev=0"\
197
            #          " | sed -rn '\''s/^v(.*)/\\1/p'\''"
198
            #version = local(vercmd, capture=True)
199
            #if int(diff) > 0:
200
            if True:
201
                # Run git-dch in snapshot mode.
202
                # TODO: Support a --release mode in fabfile
203
                local(("git-dch --debian-branch=%s --auto %s" %
204
                       (env.debian_branch,
205
                        "--release" if env.debrelease else "--snapshot")))
206
                local(("git commit debian/changelog"
207
                       " -m 'Updated %s changelog'" % p))
208
                notice(("Make sure to tag Debian release in %s" %
209
                        env.debian_branch))
210
            
211
            local("rmdir .git")
212

    
213

    
214
def debrelease():
215
    env.debrelease = True
216

    
217

    
218
def nosigndebs():
219
    env.signdebs = False
220

    
221

    
222
def builddeb(p, master="master", branch="debian-0.8"):
223
    with co(branch):
224
        info("Building debian package for %s" % p)
225
        with lcd(package_root(p)):
226
            local("git merge master")
227
            local("if [ ! -d .git ]; then mkdir .git; fi")
228
            local("python setup.py clean")
229
            local("git add synnefo/versions/*.py -f")
230
            local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
231
                   " --git-export=INDEX --git-ignore-new %s") %
232
                   (master, branch, "" if env.signdebs else "-us -uc"))
233
            local("rm -rf .git")
234
            local("git reset synnefo/versions/*.py")
235
        info("Done building debian package for %s" % p)
236

    
237

    
238
def builddeball(b="debian-0.8"):
239
    for p in env.deb_packages:
240
        builddeb(p, b)
241

    
242

    
243
@roles('pypi')
244
def uploadtars():
245
    put("packages/*.tar.gz", 'www/pypi/')