Repository navigation
Expand file tree
/
Copy pathcanvas.mk
More file actions
130 lines (115 loc) · 5.15 KB
/
Copy pathcanvas.mk
File metadata and controls
130 lines (115 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Canvas pages: weekly overview pages ("veckoöversikt") generated from the
# TimeEdit schedule and pushed with canvaslms. Included from ./Makefile.
#
# make schedule regenerate the schedule block in all PAGES
# make update-schedule re-download the ICS first, then regenerate
# make push-pages push changed PAGES to Canvas (existing pages only)
# make create-pages one-shot: create the pages in Canvas the first time
# make create-modules one-shot: create the Canvas modules in canvas-modules.txt
#
# COURSE is the nytid nickname (schedule, course code); CANVAS_COURSE is the
# canvaslms course regex and defaults to COURSE. To rehearse in a sandbox:
# make create-modules create-pages CANVAS_COURSE='^Sandbox dbosk$'
#
# The pages are the source of truth: Canvas strips the HTML-comment markers
# that veckoschema.py uses, so never pull these pages back from Canvas.
COURSE?= prgi26
CANVAS_COURSE?= ${COURSE}
ICS_URL?= $(shell nytid courses config ${COURSE} ics | sed 's/^ics = //')
ICS?= schedule.ics
VECKOSCHEMA?= bin/veckoschema.py
# Canvas modules in course order (one per line); one page goes first in each.
MODULES_FILE?= canvas-modules.txt
# Week pages get their schedule block filled by veckoschema.py ...
WEEK_PAGES+= modules/helloworld/vecka.md
WEEK_PAGES+= modules/variables/vecka.md
WEEK_PAGES+= modules/conditionals/vecka.md
WEEK_PAGES+= modules/iterations/vecka.md
WEEK_PAGES+= modules/classes/vecka.md
WEEK_PAGES+= modules/containers/vecka.md
WEEK_PAGES+= modules/files/vecka.md
WEEK_PAGES+= modules/graphics/vecka.md
WEEK_PAGES+= modules/overview/vecka-datorprov.md
WEEK_PAGES+= modules/project/vecka.md
# ... while these are pushed as they are.
PAGES+= modules/overview-python/pythondelen.md
PAGES+= modules/overview/changes.md
PAGES+= modules/overview-python/diagnostiskt-prov.md
PAGES+= modules/computational-thinking/lecture.md
PAGES+= modules/helloworld/lecture.md
PAGES+= modules/variables/lecture.md
PAGES+= modules/variables/lecture-functions.md
PAGES+= modules/variables/tutorial.md
PAGES+= modules/conditionals/lecture.md
PAGES+= modules/conditionals/tutorial.md
PAGES+= modules/iterations/lecture.md
PAGES+= modules/iterations/tutorial.md
PAGES+= modules/classes/lecture.md
PAGES+= modules/classes/tutorial.md
PAGES+= modules/containers/lecture.md
PAGES+= modules/containers/tutorial.md
PAGES+= modules/files/lecture.md
PAGES+= modules/files/tutorial.md
PAGES+= modules/graphics/lecture.md
PAGES+= modules/graphics/tutorial.md
PAGES+= ${WEEK_PAGES}
${ICS}:
curl -fsS "${ICS_URL}" -o $@.tmp && mv $@.tmp $@
${VECKOSCHEMA}: $(dir ${VECKOSCHEMA})veckoschema.nw
${MAKE} -C $(dir ${VECKOSCHEMA}) $(notdir ${VECKOSCHEMA})
.PHONY: schedule
schedule: ${ICS} ${VECKOSCHEMA}
python3 ${VECKOSCHEMA} --course ${COURSE} --ics ${ICS} --in-place ${WEEK_PAGES}
.PHONY: update-schedule
update-schedule:
${RM} ${ICS}
${MAKE} schedule
PUSH_STAMPDIR_PAGES:= .pushed-pages.d/$(shell printf '%s' '${CANVAS_COURSE}' | tr -c 'A-Za-z0-9' _)
.PHONY: push-pages
push-pages: $(addprefix ${PUSH_STAMPDIR_PAGES}/,${PAGES})
${PUSH_STAMPDIR_PAGES}/%: %
@mkdir -p $(dir $@)
canvaslms pages edit -c "${CANVAS_COURSE}" -f "$<"
@touch $@
# Lab instructions pushed into the FeedbackFruits peer-review assignments.
# Each instruction.md carries the Canvas assignment id in its `regex` field, so
# only that assignment is matched and only its name and description are sent;
# the LTI (FeedbackFruits) submission settings are left untouched. The body is
# converted with pandoc --mathjax so TeX math survives as \( ... \), which
# Canvas renders. --no-cache: canvaslms' object cache otherwise serves stale
# assignment names.
LAB_PAGES+= modules/variables/lab/instruction.md
LAB_PAGES+= modules/conditionals/lab/instruction.md
LAB_PAGES+= modules/iterations/lab/instruction.md
LAB_PAGES+= modules/classes/lab/instruction.md
LAB_PAGES+= modules/containers/lab/instruction.md
LAB_PAGES+= modules/files/lab/instruction.md
.PHONY: push-labs
push-labs: $(LAB_PAGES:.md=.canvas.html)
for f in $^; do \
canvaslms --no-cache assignments edit --html -c "${CANVAS_COURSE}" -f $$f || exit 1; \
done
%.canvas.html: %.md
python3 -c 'import sys, subprocess; \
s = open(sys.argv[1], encoding="utf-8").read(); \
_, fm, body = s.split("---\n", 2); \
html = subprocess.run(["pandoc", "-f", "markdown", "-t", "html", "--mathjax"], \
input=body, capture_output=True, text=True, check=True).stdout; \
open(sys.argv[2], "w", encoding="utf-8").write("---\n" + fm + "---\n" + html)' $< $@
.PHONY: create-pages
create-pages:
for page in ${PAGES}; do \
echo "Creating $$page in ${CANVAS_COURSE} ..."; \
canvaslms pages edit --create -c "${CANVAS_COURSE}" -f "$$page" || exit 1; \
done
# Modules are created in file order and appended after the existing ones;
# canvaslms refuses a duplicate name unless --allow-duplicate is given, so
# existing modules are reported and skipped rather than duplicated.
.PHONY: create-modules
create-modules: ${MODULES_FILE}
@while IFS= read -r module; do \
[ -n "$$module" ] || continue; \
echo "Creating module '$$module' in ${CANVAS_COURSE} ..."; \
canvaslms modules create -c "${CANVAS_COURSE}" "$$module" \
|| echo " (skipped: $$module)"; \
done < ${MODULES_FILE}