From 745ebefc3d27a2500f64d2d3222b37780e5873b0 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Sun, 12 Jan 2020 13:28:48 -0600 Subject: [PATCH] Backport slides.zip addition --- .gitignore | 1 + slides/Dockerfile | 9 +++------ slides/build.sh | 1 + slides/index.py | 10 +++++----- slides/markmaker.py | 33 +++++++++++++++++++-------------- slides/runtime.txt | 1 + 6 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 slides/runtime.txt diff --git a/.gitignore b/.gitignore index 21ae9d25..6667a53c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ slides/*.yml.html slides/autopilot/state.yaml slides/index.html slides/past.html +slides/slides.zip node_modules ### macOS ### diff --git a/slides/Dockerfile b/slides/Dockerfile index c9390edb..d66413ec 100644 --- a/slides/Dockerfile +++ b/slides/Dockerfile @@ -1,7 +1,4 @@ -FROM alpine -RUN apk update -RUN apk add entr -RUN apk add py-pip -RUN apk add 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 diff --git a/slides/build.sh b/slides/build.sh index ca08e19f..9f18a169 100755 --- a/slides/build.sh +++ b/slides/build.sh @@ -14,6 +14,7 @@ once) ./appendcheck.py $YAML.html done fi + zip -qr slides.zip . && echo "Created slides.zip archive." ;; forever) diff --git a/slides/index.py b/slides/index.py index 2e59ae59..953feed9 100755 --- a/slides/index.py +++ b/slides/index.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # coding: utf-8 TEMPLATE=""" @@ -106,13 +106,13 @@ TEMPLATE=""" -""".decode("utf-8") +""" 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. @@ -160,10 +160,10 @@ with open("index.html", "w") as f: 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")) + )) diff --git a/slides/markmaker.py b/slides/markmaker.py index a01fbe02..bee80ff9 100755 --- a/slides/markmaker.py +++ b/slides/markmaker.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # transforms a YAML manifest into a HTML workshop file import glob @@ -26,12 +26,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): @@ -159,8 +166,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) @@ -183,14 +188,14 @@ try: 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("git@github.com:", "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="{}")) @@ -198,12 +203,12 @@ 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" diff --git a/slides/runtime.txt b/slides/runtime.txt new file mode 100644 index 00000000..475ba515 --- /dev/null +++ b/slides/runtime.txt @@ -0,0 +1 @@ +3.7