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-backend', 'snf-pithos-app', 'snf-pithos-tools']
48 env.pypi_root = 'pypi'
50 'docs': ['docs.dev.grnet.gr'],
51 'pypi': ['docs.dev.grnet.gr']
56 notice = lambda x: sys.stdout.write(yellow(x) + "\n")
57 info = lambda x: sys.stdout.write(green(x) + "\n")
58 error = lambda x: sys.stdout.write(red(x) + "\n")
65 # wrap local to respect global capturing setting from env.capture
69 def local(cmd, capture="default"):
70 if capture != "default":
74 return oldlocal(cmd, capture=capture)
78 return os.path.join(env.project_root, p)
82 notice("uninstalling package: %s" % p)
83 with lcd(package_root(p)):
84 with settings(warn_only=True):
85 local("pip uninstall %s -y" % p, env.capture)
89 info("building package: %s" % p)
90 with lcd(package_root(p)):
92 local("rm -r dist build")
95 local("python setup.py egg_info -d sdist")
99 info("installing package: %s" % p)
100 with lcd(package_root(p)):
102 local("python setup.py develop")
104 local("python setup.py install")
107 def install(*packages):
109 install_pkg("snf-%s" % p)
113 for p in env.packages:
119 for p in env.packages:
124 if os.path.exists("./packages"):
125 notice("removing 'packages' directory")
126 local("rm -r packages")
128 local("mkdir packages")
129 for p in env.packages:
130 local("cp %s/dist/*.tar.gz ./packages/" % package_root(p))
134 for p in env.packages:
138 def remove(*packages):
140 remove_pkg("snf-%s" % p)
148 def git(params, locl=True):
149 cmd = local if locl else run
150 return cmd("git %s" % params, capture=True)
154 return git("symbolic-ref HEAD").split("/")[-1]
159 current_branch = branch()
160 git("checkout %s" % c)
161 # Use a try block to make sure we checkout the original branch.
166 git("checkout %s" % current_branch)
168 error("Could not checkout %s, you're still left at %s" % c)
171 # Debian packaging helpers
174 env.debian_branch = 'debian-0.9'
175 env.deb_packages = ['snf-pithos-backend', 'snf-pithos-tools', 'snf-pithos-app']
177 env.debrelease = False # Increase release number in Debian changelogs
178 env.upstream = 'packaging'
182 return local("git rev-list --all --date-order --max-count=1 %s" % f,
183 capture=True).strip()
186 def _diff_from_master(c, f):
187 return local("git log --oneline %s..%s %s"
188 " | wc -l" % (c, env.upstream, f), capture=True)
192 with co(env.debian_branch):
193 local("git merge %s" % env.upstream)
194 with lcd(package_root(p)):
195 local("if [ ! -d .git ]; then mkdir .git; fi")
198 # Checking for new changes in packages
199 # has been removed temporarily.
200 # Always create a new Debian changelog entry.
201 ## Check for new changes in package dir
202 #diff = _diff_from_master(_last_commit("debian/changelog"), ".")
203 #vercmd = "git describe --tags --abbrev=0"\
204 # " | sed -rn '\''s/^v(.*)/\\1/p'\''"
205 #version = local(vercmd, capture=True)
208 # Run git-dch in snapshot mode.
209 # TODO: Support a --release mode in fabfile
210 local(("git-dch --debian-branch=%s --auto %s" %
212 "--release" if env.debrelease else "--snapshot")))
213 local(("git commit debian/changelog"
214 " -m 'Updated %s changelog'" % p))
215 notice(("Make sure to tag Debian release in %s" %
222 env.debrelease = True
229 def builddeb(p, master="packaging", branch="debian-0.9"):
231 info("Building debian package for %s" % p)
232 with lcd(package_root(p)):
233 local("git merge %s" % master)
234 local("if [ ! -d .git ]; then mkdir .git; fi")
235 local("python setup.py clean")
236 local("git add ./*/*/version.py -f")
237 local(("git-buildpackage --git-upstream-branch=%s --git-debian-branch=%s"
238 " --git-export=INDEX --git-ignore-new %s") %
239 (master, branch, "" if env.signdebs else "-us -uc"))
241 local("git reset ./*/*/version.py")
242 info("Done building debian package for %s" % p)
245 def builddeball(b="debian-0.9"):
246 for p in env.deb_packages:
247 builddeb(p=p, branch=b)
252 put("packages/*.tar.gz", 'www/pypi/')