]>
git.ipfire.org Git - thirdparty/lldpd.git/blob - tasks.py
1 from invoke
import task
10 os
.environ
["PATH"] = os
.path
.expanduser('~/.virtualenvs/hyde/bin') \
11 + os
.pathsep
+ os
.environ
["PATH"]
14 def confirm(question
, default
=False):
20 response
= input("{0} [{1}] ".format(question
, suffix
))
21 response
= response
.lower().strip() # Normalize
25 if response
in ["y", "yes"]:
27 if response
in ["n", "no"]:
29 err
= "I didn't understand you. Please specify '(y)es' or '(n)o'."
30 print(err
, file=sys
.stderr
)
35 """Generate dev content"""
41 """Regenerate dev content"""
42 c
.run('rm -rf deploy')
47 """Serve dev content"""
48 c
.run('hyde -x serve -a 0.0.0.0')
53 """Build production content"""
54 # Generate the website from scratch
55 c
.run("rm -rf deploy")
56 conf
= "site-production.yaml"
57 c
.run('hyde -x gen -c %s' % conf
)
59 # Compute hash for media files
61 for p
in ['media/js/*.js',
63 files
= glob
.glob("%s/%s" % (c
.cwd
, p
))
67 md5
.update(open(f
, 'rb').read())
68 md5
= md5
.hexdigest()[:8]
70 print("[+] MD5 hash for %s is %s" % (f
, md5
))
72 root
, ext
= os
.path
.splitext(f
)
73 newname
= "%s.%s%s" % (root
, md5
, ext
)
75 c
.run("cp %s %s" % (f
, newname
))
77 c
.run(r
"find . -name '*.html' -type f -print0 | xargs -r0 sed -i "
79 r
"s@\([\"']\)\([^\"']*\
)%s\
1@\
1\
2%s\
1@g"
83 tempdir = tempfile.mkdtemp()
86 c.run("git clone %s -b gh-pages ." % lldpdir)
87 c.run("rsync -ac --exclude=.git %s/deploy/ ." % lldpdir)
89 c.run("git diff --stat HEAD || true", pty=True)
90 if confirm("More diff?", default=True):
91 c.run("env GIT_PAGER=less git diff --word-diff HEAD || true", pty=True)
92 if confirm("Keep?", default=True):
93 c.run('git commit
-a
-m
"Update generated copy of website"')
94 c.run('git push origin
')
96 shutil.rmtree(tempdir)