1 # Copyright 2011 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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.
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.
38 from contextlib import contextmanager
39 from fabric.api import *
40 from fabric.colors import *
42 env.project_root = "./"
45 env.packages = ['snf-pithos-lib', 'snf-pithos-backend', 'snf-pithos-app',
49 env.pypi_root = 'pypi'
51 'docs': ['docs.dev.grnet.gr'],
52 'pypi': ['docs.dev.grnet.gr']
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")
65 # wrap local to respect global capturing setting from env.capture
67 def local(cmd, capture="default"):
68 if capture != "default":
72 return oldlocal(cmd, capture=capture)
76 return os.path.join(env.project_root, 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)
87 info ("building package: %s" % p)
88 with lcd(package_root(p)):
90 local("rm -r dist build")
93 local("python setup.py egg_info -d sdist")
97 info("installing package: %s" % p)
98 with lcd(package_root(p)):
100 local("python setup.py develop")
102 local("python setup.py install")
105 def install(*packages):
107 install_pkg("snf-%s" % p)
111 for p in env.packages:
117 for p in env.packages:
122 if os.path.exists("./packages"):
123 notice("removing 'packages' directory")
124 local("rm -r packages");
126 local("mkdir packages");
127 for p in env.packages:
128 local("cp %s/dist/*.tar.gz ./packages/" % package_root(p));
132 for p in env.packages:
136 def remove(*packages):
138 remove_pkg("snf-%s" % p)
146 def git(params, locl=True):
147 cmd = local if locl else run
148 return cmd("git %s" % params, capture=True)
152 return git("symbolic-ref HEAD").split("/")[-1]
157 current_branch = branch();
158 git("checkout %s" % c)
159 # Use a try block to make sure we checkout the original branch.
164 git("checkout %s" % current_branch)
166 error("Could not checkout %s, you're still left at %s" % c)
169 # Debian packaging helpers
172 env.debian_branch = 'debian-0.9'
173 env.deb_packages = ['snf-pithos-lib', 'snf-pithos-backend',
174 'snf-pithos-tools', 'snf-pithos-app']
176 env.debrelease = False # Increase release number in Debian changelogs
177 env.upstream = 'packaging'
181 return local("git rev-list --all --date-order --max-count=1 %s" % f,
182 capture=True).strip()
185 def _diff_from_master(c,f):
186 return local("git log --oneline %s..%s %s" \
187 " | wc -l" % (c, env.upstream, f), capture=True)
191 with co(env.debian_branch):
192 local("git merge %s" % env.upstream)
193 with lcd(package_root(p)):
194 local("if [ ! -d .git ]; then mkdir .git; fi")
197 # Checking for new changes in packages
198 # has been removed temporarily.
199 # Always create a new Debian changelog entry.
200 ## Check for new changes in package dir
201 #diff = _diff_from_master(_last_commit("debian/changelog"), ".")
202 #vercmd = "git describe --tags --abbrev=0"\
203 # " | sed -rn '\''s/^v(.*)/\\1/p'\''"
204 #version = local(vercmd, capture=True)
207 # Run git-dch in snapshot mode.
208 # TODO: Support a --release mode in fabfile
209 local(("git-dch --debian-branch=%s --auto %s" %
211 "--release" if env.debrelease else "--snapshot")))
212 local(("git commit debian/changelog"
213 " -m 'Updated %s changelog'" % p))
214 notice(("Make sure to tag Debian release in %s" %
221 env.debrelease = True
228 def builddeb(p, master="packaging", branch="debian-0.9"):
230 info("Building debian package for %s" % p)
231 with lcd(package_root(p)):
232 local("git merge %s" % master)
233 local("if [ ! -d .git ]; then mkdir .git; fi")
234 local("python setup.py clean")
235 local("git add ./*/*/version.py -f")
236 local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
237 " --git-export=INDEX --git-ignore-new %s") %
238 (master, branch, "" if env.signdebs else "-us -uc"))
240 local("git reset ./*/*/version.py")
241 info("Done building debian package for %s" % p)
244 def builddeball(b="debian-0.9"):
245 for p in env.deb_packages:
246 builddeb(p=p, branch=b)
252 put("packages/*.tar.gz", 'www/pypi/')