Statistics
| Branch: | Tag: | Revision:

root / fabfile.py @ f9ea264b

History | View | Annotate | Download (6.9 kB)

1 6a8baac1 Kostas Papadimitriou
# Copyright 2011 GRNET S.A. All rights reserved.
2 6a8baac1 Kostas Papadimitriou
#
3 6a8baac1 Kostas Papadimitriou
# Redistribution and use in source and binary forms, with or
4 6a8baac1 Kostas Papadimitriou
# without modification, are permitted provided that the following
5 6a8baac1 Kostas Papadimitriou
# conditions are met:
6 6a8baac1 Kostas Papadimitriou
#
7 6a8baac1 Kostas Papadimitriou
#   1. Redistributions of source code must retain the above
8 6a8baac1 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
9 6a8baac1 Kostas Papadimitriou
#      disclaimer.
10 6a8baac1 Kostas Papadimitriou
#
11 6a8baac1 Kostas Papadimitriou
#   2. Redistributions in binary form must reproduce the above
12 6a8baac1 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
13 6a8baac1 Kostas Papadimitriou
#      disclaimer in the documentation and/or other materials
14 6a8baac1 Kostas Papadimitriou
#      provided with the distribution.
15 6a8baac1 Kostas Papadimitriou
#
16 6a8baac1 Kostas Papadimitriou
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6a8baac1 Kostas Papadimitriou
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6a8baac1 Kostas Papadimitriou
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6a8baac1 Kostas Papadimitriou
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6a8baac1 Kostas Papadimitriou
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6a8baac1 Kostas Papadimitriou
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6a8baac1 Kostas Papadimitriou
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6a8baac1 Kostas Papadimitriou
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6a8baac1 Kostas Papadimitriou
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6a8baac1 Kostas Papadimitriou
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6a8baac1 Kostas Papadimitriou
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6a8baac1 Kostas Papadimitriou
# POSSIBILITY OF SUCH DAMAGE.
28 6a8baac1 Kostas Papadimitriou
#
29 6a8baac1 Kostas Papadimitriou
# The views and conclusions contained in the software and
30 6a8baac1 Kostas Papadimitriou
# documentation are those of the authors and should not be
31 6a8baac1 Kostas Papadimitriou
# interpreted as representing official policies, either expressed
32 6a8baac1 Kostas Papadimitriou
# or implied, of GRNET S.A.
33 6a8baac1 Kostas Papadimitriou
#
34 6a8baac1 Kostas Papadimitriou
35 6a8baac1 Kostas Papadimitriou
import os
36 6a8baac1 Kostas Papadimitriou
import sys
37 6a8baac1 Kostas Papadimitriou
38 6a8baac1 Kostas Papadimitriou
from contextlib import contextmanager
39 6a8baac1 Kostas Papadimitriou
from fabric.api import *
40 6a8baac1 Kostas Papadimitriou
from fabric.colors import *
41 6a8baac1 Kostas Papadimitriou
42 6a8baac1 Kostas Papadimitriou
env.project_root = "./"
43 6a8baac1 Kostas Papadimitriou
env.develop = False
44 6a8baac1 Kostas Papadimitriou
env.autoremove = True
45 6e147ecc Antony Chazapis
env.packages = ['snf-pithos-backend', 'snf-pithos-app', 'snf-pithos-tools']
46 6a8baac1 Kostas Papadimitriou
env.capture = False
47 6a8baac1 Kostas Papadimitriou
env.colors = True
48 6a8baac1 Kostas Papadimitriou
env.pypi_root = 'pypi'
49 6a8baac1 Kostas Papadimitriou
env.roledefs = {
50 6a8baac1 Kostas Papadimitriou
    'docs': ['docs.dev.grnet.gr'],
51 6a8baac1 Kostas Papadimitriou
    'pypi': ['docs.dev.grnet.gr']
52 6a8baac1 Kostas Papadimitriou
}
53 6a8baac1 Kostas Papadimitriou
54 858e0ab9 Kostas Papadimitriou
55 858e0ab9 Kostas Papadimitriou
# colored logging
56 6a8baac1 Kostas Papadimitriou
notice = lambda x: sys.stdout.write(yellow(x) + "\n")
57 6a8baac1 Kostas Papadimitriou
info = lambda x: sys.stdout.write(green(x) + "\n")
58 6a8baac1 Kostas Papadimitriou
error = lambda x: sys.stdout.write(red(x) + "\n")
59 6a8baac1 Kostas Papadimitriou
60 6a8baac1 Kostas Papadimitriou
61 6a8baac1 Kostas Papadimitriou
def dev():
62 6a8baac1 Kostas Papadimitriou
    env.develop = True
63 6a8baac1 Kostas Papadimitriou
64 858e0ab9 Kostas Papadimitriou
65 6a8baac1 Kostas Papadimitriou
# wrap local to respect global capturing setting from env.capture
66 6a8baac1 Kostas Papadimitriou
oldlocal = local
67 6a8baac1 Kostas Papadimitriou
def local(cmd, capture="default"):
68 6a8baac1 Kostas Papadimitriou
    if capture != "default":
69 6a8baac1 Kostas Papadimitriou
        capture = capture
70 6a8baac1 Kostas Papadimitriou
    else:
71 6a8baac1 Kostas Papadimitriou
        capture = env.capture
72 6a8baac1 Kostas Papadimitriou
    return oldlocal(cmd, capture=capture)
73 6a8baac1 Kostas Papadimitriou
74 6a8baac1 Kostas Papadimitriou
75 6a8baac1 Kostas Papadimitriou
def package_root(p):
76 6a8baac1 Kostas Papadimitriou
    return os.path.join(env.project_root, p)
77 6a8baac1 Kostas Papadimitriou
78 6a8baac1 Kostas Papadimitriou
79 6a8baac1 Kostas Papadimitriou
def remove_pkg(p):
80 6a8baac1 Kostas Papadimitriou
    notice("uninstalling package: %s" % p)
81 6a8baac1 Kostas Papadimitriou
    with lcd(package_root(p)):
82 6a8baac1 Kostas Papadimitriou
        with settings(warn_only=True):
83 6a8baac1 Kostas Papadimitriou
            local("pip uninstall %s -y" % p, env.capture)
84 6a8baac1 Kostas Papadimitriou
85 6a8baac1 Kostas Papadimitriou
86 6a8baac1 Kostas Papadimitriou
def build_pkg(p):
87 6a8baac1 Kostas Papadimitriou
    info ("building package: %s" % p)
88 6a8baac1 Kostas Papadimitriou
    with lcd(package_root(p)):
89 f388beb9 Kostas Papadimitriou
        try:
90 f388beb9 Kostas Papadimitriou
            local("rm -r dist build")
91 f388beb9 Kostas Papadimitriou
        except:
92 f388beb9 Kostas Papadimitriou
            pass
93 6a8baac1 Kostas Papadimitriou
        local("python setup.py egg_info -d sdist")
94 6a8baac1 Kostas Papadimitriou
95 6a8baac1 Kostas Papadimitriou
96 6a8baac1 Kostas Papadimitriou
def install_pkg(p):
97 6a8baac1 Kostas Papadimitriou
    info("installing package: %s" % p)
98 6a8baac1 Kostas Papadimitriou
    with lcd(package_root(p)):
99 6a8baac1 Kostas Papadimitriou
        if env.develop:
100 6a8baac1 Kostas Papadimitriou
            local("python setup.py develop")
101 6a8baac1 Kostas Papadimitriou
        else:
102 6a8baac1 Kostas Papadimitriou
            local("python setup.py install")
103 6a8baac1 Kostas Papadimitriou
104 6a8baac1 Kostas Papadimitriou
105 6a8baac1 Kostas Papadimitriou
def install(*packages):
106 6a8baac1 Kostas Papadimitriou
    for p in packages:
107 6a8baac1 Kostas Papadimitriou
        install_pkg("snf-%s" % p)
108 6a8baac1 Kostas Papadimitriou
109 6a8baac1 Kostas Papadimitriou
110 6a8baac1 Kostas Papadimitriou
def buildall():
111 6a8baac1 Kostas Papadimitriou
    for p in env.packages:
112 6a8baac1 Kostas Papadimitriou
        build_pkg(p)
113 6a8baac1 Kostas Papadimitriou
    collectdists()
114 6a8baac1 Kostas Papadimitriou
115 6a8baac1 Kostas Papadimitriou
116 6a8baac1 Kostas Papadimitriou
def installall():
117 6a8baac1 Kostas Papadimitriou
    for p in env.packages:
118 6a8baac1 Kostas Papadimitriou
        install_pkg(p)
119 6a8baac1 Kostas Papadimitriou
120 858e0ab9 Kostas Papadimitriou
121 6a8baac1 Kostas Papadimitriou
def collectdists():
122 6a8baac1 Kostas Papadimitriou
    if os.path.exists("./packages"):
123 6a8baac1 Kostas Papadimitriou
        notice("removing 'packages' directory")
124 6a8baac1 Kostas Papadimitriou
        local("rm -r packages");
125 6a8baac1 Kostas Papadimitriou
126 6a8baac1 Kostas Papadimitriou
    local("mkdir packages");
127 6a8baac1 Kostas Papadimitriou
    for p in env.packages:
128 6a8baac1 Kostas Papadimitriou
        local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
129 6a8baac1 Kostas Papadimitriou
130 858e0ab9 Kostas Papadimitriou
131 6a8baac1 Kostas Papadimitriou
def removeall():
132 6a8baac1 Kostas Papadimitriou
    for p in env.packages:
133 6a8baac1 Kostas Papadimitriou
        remove_pkg(p)
134 6a8baac1 Kostas Papadimitriou
135 6a8baac1 Kostas Papadimitriou
136 6a8baac1 Kostas Papadimitriou
def remove(*packages):
137 6a8baac1 Kostas Papadimitriou
    for p in packages:
138 6a8baac1 Kostas Papadimitriou
        remove_pkg("snf-%s" % p)
139 6a8baac1 Kostas Papadimitriou
140 6a8baac1 Kostas Papadimitriou
141 6a8baac1 Kostas Papadimitriou
#
142 6a8baac1 Kostas Papadimitriou
# GIT helpers
143 6a8baac1 Kostas Papadimitriou
#
144 6a8baac1 Kostas Papadimitriou
145 6a8baac1 Kostas Papadimitriou
146 6a8baac1 Kostas Papadimitriou
def git(params, locl=True):
147 6a8baac1 Kostas Papadimitriou
    cmd = local if locl else run
148 6a8baac1 Kostas Papadimitriou
    return cmd("git %s" % params, capture=True)
149 6a8baac1 Kostas Papadimitriou
150 6a8baac1 Kostas Papadimitriou
151 6a8baac1 Kostas Papadimitriou
def branch():
152 6a8baac1 Kostas Papadimitriou
    return git("symbolic-ref HEAD").split("/")[-1]
153 6a8baac1 Kostas Papadimitriou
154 6a8baac1 Kostas Papadimitriou
155 6a8baac1 Kostas Papadimitriou
@contextmanager
156 6a8baac1 Kostas Papadimitriou
def co(c):
157 6a8baac1 Kostas Papadimitriou
    current_branch = branch();
158 6a8baac1 Kostas Papadimitriou
    git("checkout %s" % c)
159 858e0ab9 Kostas Papadimitriou
    # Use a try block to make sure we checkout the original branch.
160 858e0ab9 Kostas Papadimitriou
    try:
161 858e0ab9 Kostas Papadimitriou
        yield
162 858e0ab9 Kostas Papadimitriou
    finally:
163 858e0ab9 Kostas Papadimitriou
        try:
164 858e0ab9 Kostas Papadimitriou
            git("checkout %s" % current_branch)
165 858e0ab9 Kostas Papadimitriou
        except Exception:
166 858e0ab9 Kostas Papadimitriou
            error("Could not checkout %s, you're still left at %s" % c)
167 6a8baac1 Kostas Papadimitriou
168 6a8baac1 Kostas Papadimitriou
#
169 6a8baac1 Kostas Papadimitriou
# Debian packaging helpers
170 6a8baac1 Kostas Papadimitriou
#
171 6a8baac1 Kostas Papadimitriou
172 f8e2494e Kostas Papadimitriou
env.debian_branch = 'debian-0.9'
173 6e147ecc Antony Chazapis
env.deb_packages = ['snf-pithos-backend', 'snf-pithos-tools', 'snf-pithos-app']
174 fa36b326 Vangelis Koukis
env.signdebs = False
175 858e0ab9 Kostas Papadimitriou
env.debrelease = False  # Increase release number in Debian changelogs
176 858e0ab9 Kostas Papadimitriou
env.upstream = 'packaging'
177 6a8baac1 Kostas Papadimitriou
178 858e0ab9 Kostas Papadimitriou
179 858e0ab9 Kostas Papadimitriou
def _last_commit(f):
180 858e0ab9 Kostas Papadimitriou
    return local("git rev-list --all --date-order --max-count=1 %s" % f,
181 858e0ab9 Kostas Papadimitriou
            capture=True).strip()
182 858e0ab9 Kostas Papadimitriou
183 858e0ab9 Kostas Papadimitriou
184 858e0ab9 Kostas Papadimitriou
def _diff_from_master(c,f):
185 858e0ab9 Kostas Papadimitriou
    return local("git log --oneline %s..%s %s" \
186 858e0ab9 Kostas Papadimitriou
                 " | wc -l" % (c, env.upstream, f), capture=True)
187 858e0ab9 Kostas Papadimitriou
188 858e0ab9 Kostas Papadimitriou
189 858e0ab9 Kostas Papadimitriou
def dch(p):
190 858e0ab9 Kostas Papadimitriou
    with co(env.debian_branch):
191 858e0ab9 Kostas Papadimitriou
        local("git merge %s" % env.upstream)
192 858e0ab9 Kostas Papadimitriou
        with lcd(package_root(p)):
193 858e0ab9 Kostas Papadimitriou
            local("if [ ! -d .git ]; then mkdir .git; fi")
194 858e0ab9 Kostas Papadimitriou
195 858e0ab9 Kostas Papadimitriou
            # FIXME:
196 858e0ab9 Kostas Papadimitriou
            # Checking for new changes in packages
197 858e0ab9 Kostas Papadimitriou
            # has been removed temporarily.
198 858e0ab9 Kostas Papadimitriou
            # Always create a new Debian changelog entry.
199 858e0ab9 Kostas Papadimitriou
            ## Check for new changes in package dir
200 858e0ab9 Kostas Papadimitriou
            #diff = _diff_from_master(_last_commit("debian/changelog"), ".")
201 858e0ab9 Kostas Papadimitriou
            #vercmd  = "git describe --tags --abbrev=0"\
202 858e0ab9 Kostas Papadimitriou
            #          " | sed -rn '\''s/^v(.*)/\\1/p'\''"
203 858e0ab9 Kostas Papadimitriou
            #version = local(vercmd, capture=True)
204 858e0ab9 Kostas Papadimitriou
            #if int(diff) > 0:
205 858e0ab9 Kostas Papadimitriou
            if True:
206 858e0ab9 Kostas Papadimitriou
                # Run git-dch in snapshot mode.
207 858e0ab9 Kostas Papadimitriou
                # TODO: Support a --release mode in fabfile
208 858e0ab9 Kostas Papadimitriou
                local(("git-dch --debian-branch=%s --auto %s" %
209 858e0ab9 Kostas Papadimitriou
                       (env.debian_branch,
210 858e0ab9 Kostas Papadimitriou
                        "--release" if env.debrelease else "--snapshot")))
211 858e0ab9 Kostas Papadimitriou
                local(("git commit debian/changelog"
212 858e0ab9 Kostas Papadimitriou
                       " -m 'Updated %s changelog'" % p))
213 858e0ab9 Kostas Papadimitriou
                notice(("Make sure to tag Debian release in %s" %
214 858e0ab9 Kostas Papadimitriou
                        env.debian_branch))
215 858e0ab9 Kostas Papadimitriou
216 858e0ab9 Kostas Papadimitriou
            local("rmdir .git")
217 858e0ab9 Kostas Papadimitriou
218 858e0ab9 Kostas Papadimitriou
219 858e0ab9 Kostas Papadimitriou
def debrelease():
220 858e0ab9 Kostas Papadimitriou
    env.debrelease = True
221 858e0ab9 Kostas Papadimitriou
222 858e0ab9 Kostas Papadimitriou
223 fa36b326 Vangelis Koukis
def signdebs():
224 fa36b326 Vangelis Koukis
    env.signdebs = True
225 858e0ab9 Kostas Papadimitriou
226 858e0ab9 Kostas Papadimitriou
227 f8e2494e Kostas Papadimitriou
def builddeb(p, master="packaging", branch="debian-0.9"):
228 858e0ab9 Kostas Papadimitriou
    with co(branch):
229 858e0ab9 Kostas Papadimitriou
        info("Building debian package for %s" % p)
230 858e0ab9 Kostas Papadimitriou
        with lcd(package_root(p)):
231 858e0ab9 Kostas Papadimitriou
            local("git merge %s" % master)
232 858e0ab9 Kostas Papadimitriou
            local("if [ ! -d .git ]; then mkdir .git; fi")
233 6a8baac1 Kostas Papadimitriou
            local("python setup.py clean")
234 858e0ab9 Kostas Papadimitriou
            local("git add ./*/*/version.py -f")
235 858e0ab9 Kostas Papadimitriou
            local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
236 858e0ab9 Kostas Papadimitriou
                   " --git-export=INDEX --git-ignore-new %s") %
237 858e0ab9 Kostas Papadimitriou
                   (master, branch, "" if env.signdebs else "-us -uc"))
238 6a8baac1 Kostas Papadimitriou
            local("rm -rf .git")
239 858e0ab9 Kostas Papadimitriou
            local("git reset ./*/*/version.py")
240 858e0ab9 Kostas Papadimitriou
        info("Done building debian package for %s" % p)
241 6a8baac1 Kostas Papadimitriou
242 6a8baac1 Kostas Papadimitriou
243 f8e2494e Kostas Papadimitriou
def builddeball(b="debian-0.9"):
244 858e0ab9 Kostas Papadimitriou
    for p in env.deb_packages:
245 f3204cb9 Vangelis Koukis
        builddeb(p=p, branch=b)
246 6a8baac1 Kostas Papadimitriou
247 6a8baac1 Kostas Papadimitriou
248 6a8baac1 Kostas Papadimitriou
249 6a8baac1 Kostas Papadimitriou
@roles('pypi')
250 6a8baac1 Kostas Papadimitriou
def uploadtars():
251 6a8baac1 Kostas Papadimitriou
    put("packages/*.tar.gz", 'www/pypi/')