]> git.ipfire.org Git - thirdparty/lldpd.git/blame - fabfile.py
installation: update homebrew output
[thirdparty/lldpd.git] / fabfile.py
CommitLineData
159e3ef8
VB
1from fabric.api import *
2
3import os
4import glob
5import hashlib
6import tempfile
7import shutil
8
9os.umask(0022)
10env.shell = "/bin/sh -c"
11env.command_prefixes = [ 'export PATH=$HOME/.virtualenvs/hyde/bin:$PATH',
12 'export VIRTUAL_ENV=$HOME/.virtualenvs/hyde' ]
13
14def _hyde(args):
15 return local('python ../hyde/h %s' % args)
16
17def gen():
18 """Generate dev content"""
19 _hyde('gen')
20
21def serve():
22 """Serve dev content"""
23 _hyde('serve -a 0.0.0.0')
24
25def build():
26 """Build production content"""
27 # Generate the website from scratch
28 local("rm -rf deploy")
ddc2faf5
VB
29 conf = "site-production.yaml"
30 _hyde('gen -c %s' % conf)
159e3ef8
VB
31
32 # Compute hash for media files
33 with lcd("deploy"):
34 for p in [ 'media/js/*.js',
35 'media/css/*.css' ]:
36 files = glob.glob("%s/%s" % (env.lcwd, p))
37 for f in files:
38 # Compute hash
39 md5 = hashlib.md5()
40 md5.update(file(f).read())
41 md5 = md5.hexdigest()[:8]
42 f = f[len(env.lcwd)+1:]
43 print "[+] MD5 hash for %s is %s" % (f, md5)
44 # New name
45 root, ext = os.path.splitext(f)
46 newname = "%s.%s%s" % (root, md5, ext)
47 # Symlink
6365a602 48 local("cp %s %s" % (f, newname))
159e3ef8
VB
49 # Fix HTML
50 local(r"find . -name '*.html' -type f -print0 | xargs -r0 sed -i "
51 '"'
ddc2faf5 52 r"s@\([\"']\)\([^\"']*\)%s\1@\1\2%s\1@g"
159e3ef8
VB
53 '"' % (f, newname))
54
55 lldpdir = os.getcwd()
56 tempdir = tempfile.mkdtemp()
57 try:
58 with lcd(tempdir):
59 local("git clone %s -b gh-pages ." % lldpdir)
6365a602 60 local("rsync -ac --exclude=.git %s/deploy/ ." % lldpdir)
159e3ef8
VB
61 local("git add .")
62 local("git diff --stat HEAD")
63 answer = prompt("More diff?", default="yes")
64 if answer.lower().startswith("y"):
65 local("git diff --word-diff HEAD")
66 answer = prompt("Keep?", default="yes")
67 if answer.lower().startswith("y"):
68 local('git commit -a -m "Update generated copy of website"')
69 local('git push origin')
70 finally:
71 shutil.rmtree(tempdir)
72
73def push():
74 """Push production content to remote locations"""
301cc77e
VB
75 local("git push origin gh-pages")
76 local("git push origin website")