Skip to content

Commit

Permalink
Upgrade slide generator to python3; generate a zip file too
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetazzo committed Jan 12, 2020
1 parent 1385a1b commit 6a814cf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ slides/*.yml.html
slides/autopilot/state.yaml
slides/index.html
slides/past.html
slides/slides.zip
node_modules

### macOS ###
Expand Down
6 changes: 3 additions & 3 deletions slides/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.9
RUN apk add --no-cache entr py-pip git
FROM alpine:3.11
RUN apk add --no-cache entr py3-pip git zip
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN pip3 install -r requirements.txt
1 change: 1 addition & 0 deletions slides/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ once)
./appendcheck.py $YAML.html
done
fi
zip -qr slides.zip . && echo "Created slides.zip archive."
;;

forever)
Expand Down
10 changes: 5 additions & 5 deletions slides/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# coding: utf-8

FLAGS=dict(
Expand Down Expand Up @@ -132,13 +132,13 @@
</table>
</div>
</body>
</html>""".decode("utf-8")
</html>"""

import datetime
import jinja2
import yaml

items = yaml.load(open("index.yaml"))
items = yaml.safe_load(open("index.yaml"))

# Items with a date correspond to scheduled sessions.
# Items without a date correspond to self-paced content.
Expand Down Expand Up @@ -187,10 +187,10 @@
past_workshops=past_workshops,
self_paced=self_paced,
recorded_workshops=recorded_workshops
).encode("utf-8"))
))

with open("past.html", "w") as f:
f.write(template.render(
title="Container Training",
all_past_workshops=past_workshops
).encode("utf-8"))
))
33 changes: 19 additions & 14 deletions slides/markmaker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# transforms a YAML manifest into a HTML workshop file

import glob
Expand All @@ -20,12 +20,19 @@ def anchor(title):
return "toc-" + title


def interstitials_generator():
images = [url.strip() for url in open("interstitials.txt") if url.strip()]
while True:
for image in images:
yield image
interstitials = interstitials_generator()
class Interstitials(object):

def __init__(self):
self.index = 0
self.images = [url.strip() for url in open("interstitials.txt") if url.strip()]

def next(self):
index = self.index % len(self.images)
index += 1
return self.images[index]


interstitials = Interstitials()


def insertslide(markdown, title):
Expand Down Expand Up @@ -154,8 +161,6 @@ def gentoc(tree, path=()):
# Returns: (epxandedmarkdown,[list of titles])
# The list of titles can be nested.
def processchapter(chapter, filename):
if isinstance(chapter, unicode):
return processchapter(chapter.encode("utf-8"), filename)
if isinstance(chapter, str):
if "\n" in chapter:
titles = re.findall("^# (.*)", chapter, re.MULTILINE)
Expand All @@ -179,27 +184,27 @@ def processchapter(chapter, filename):
if "REPOSITORY_URL" in os.environ:
repo = os.environ["REPOSITORY_URL"]
else:
repo = subprocess.check_output(["git", "config", "remote.origin.url"])
repo = subprocess.check_output(["git", "config", "remote.origin.url"]).decode("ascii")
repo = repo.strip().replace("[email protected]:", "https://github.com/")
if "BRANCH" in os.environ:
branch = os.environ["BRANCH"]
else:
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("ascii")
branch = branch.strip()
base = subprocess.check_output(["git", "rev-parse", "--show-prefix"])
base = subprocess.check_output(["git", "rev-parse", "--show-prefix"]).decode("ascii")
base = base.strip().strip("/")
urltemplate = ("{repo}/tree/{branch}/{base}/{filename}"
.format(repo=repo, branch=branch, base=base, filename="{}"))
except:
logging.exception("Could not generate repository URL; generating local URLs instead.")
urltemplate = "file://{pwd}/{filename}".format(pwd=os.environ["PWD"], filename="{}")
try:
commit = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
commit = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("ascii")
except:
logging.exception("Could not figure out HEAD commit.")
commit = "??????"
try:
dirtyfiles = subprocess.check_output(["git", "status", "--porcelain"])
dirtyfiles = subprocess.check_output(["git", "status", "--porcelain"]).decode("ascii")
except:
logging.exception("Could not figure out repository cleanliness.")
dirtyfiles = "?? git status --porcelain failed"
Expand Down
1 change: 1 addition & 0 deletions slides/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7

0 comments on commit 6a814cf

Please sign in to comment.