Statistics
| Branch: | Tag: | Revision:

root / fabfile.py @ 77bdcdd0

History | View | Annotate | Download (6.1 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
env.pypi_root = 'pypi'
51
env.roledefs = {
52
    'docs': ['docs.dev.grnet.gr'],
53
    'pypi': ['docs.dev.grnet.gr']
54
}
55

    
56

    
57
# colored logging
58
notice = lambda x: sys.stdout.write(yellow(x) + "\n")
59
info = lambda x: sys.stdout.write(green(x) + "\n")
60
error = lambda x: sys.stdout.write(red(x) + "\n")
61

    
62
def dev():
63
    env.develop = True
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
        with settings(warn_only=True):
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

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

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

    
128

    
129
def removeall():
130
    for p in env.packages:
131
        remove_pkg(p)
132

    
133

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

    
138

    
139
#
140
# GIT helpers
141
#
142

    
143

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

    
148

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

    
152

    
153
@contextmanager
154
def co(c):
155
    current_branch = branch();
156
    git("checkout %s" % c)
157
    yield
158
    git("checkout %s" % current_branch)
159

    
160

    
161
#
162
# Debian packaging helpers
163
#
164

    
165
env.debian_branch = 'debian-0.8'
166

    
167

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

    
172

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

    
177

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

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

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

    
197

    
198
def builddeb(p, master="master", branch="debian-0.8"):
199
    with lcd(package_root(p)):
200
        local("git merge master")
201
        with settings(warn_only=True):
202
            local("ls .git || mkdir .git")
203
            local("python setup.py clean")
204
            local("git add synnefo/versions/*.py -f")
205
            local("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s \
206
--git-export=INDEX --git-ignore-new" % (master, branch))
207
            local("rm -rf .git")
208
            local("git reset synnefo/versions/*.py")
209

    
210

    
211
def builddeball(b="debian-0.8"):
212
    with co(b):
213
        for p in env.deb_packages:
214
            builddeb(p, b)
215
    collectdebs()
216

    
217

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

    
223

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