]>
Commit | Line | Data |
---|---|---|
159e3ef8 VB |
1 | from fabric.api import * |
2 | ||
3 | import os | |
4 | import glob | |
5 | import hashlib | |
6 | import tempfile | |
7 | import shutil | |
8 | ||
9 | os.umask(0022) | |
10 | env.shell = "/bin/sh -c" | |
11 | env.command_prefixes = [ 'export PATH=$HOME/.virtualenvs/hyde/bin:$PATH', | |
12 | 'export VIRTUAL_ENV=$HOME/.virtualenvs/hyde' ] | |
13 | ||
14 | def _hyde(args): | |
15 | return local('python ../hyde/h %s' % args) | |
16 | ||
17 | def gen(): | |
18 | """Generate dev content""" | |
19 | _hyde('gen') | |
20 | ||
21 | def serve(): | |
22 | """Serve dev content""" | |
23 | _hyde('serve -a 0.0.0.0') | |
24 | ||
25 | def 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 | ||
73 | def push(): | |
74 | """Push production content to remote locations""" | |
301cc77e VB |
75 | local("git push origin gh-pages") |
76 | local("git push origin website") |