-
Notifications
You must be signed in to change notification settings - Fork 151
/
make-student-nb.bash
executable file
·78 lines (61 loc) · 1.93 KB
/
make-student-nb.bash
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
#!/bin/bash
# This script generates the "student-notebooks" folder with student versions of
# the workshops in the "notebooks" folder. It also updates the TOC and keyword
# index based on the workshops in the "notebooks" folder.
# Make sure you have already installed nbgrader
# (https://nbgrader.readthedocs.io/en/stable/user_guide/installation.html)
# and nbpages (https://pypi.org/project/nbpages/).
# i.e. `pip install nbgrader nbpages notedown python-Levenshtein`
# make sure to terminate on any errors...
set -e
# Update TOC and indexes
nbpages
# Re-creating student-notebooks folder
rm -r student-notebooks
nbgrader quickstart student-notebooks
cp nbgrader_config.py student-notebooks
# Copying notebooks in instructor's folder to the new source folder in student-notebooks folder
for i in ./notebooks/*.ipynb
do
s=${i##*/}
fname=${s%.ipynb}
mkdir ./student-notebooks/source/$fname
cp $i ./student-notebooks/source/$fname/$fname.ipynb
done
# Create assignments in release folder
pushd student-notebooks
for i in ./source/*
do
s=${i##*/}
if [ ${s} != 'header.ipynb' ]
then
nbgrader db assignment add ${s}
nbgrader generate_assignment ${s}
fi
done
# Delete source folder
rm -r source
# Re-format student-notebooks folder and delete release folder
for i in ./release/*
do
s=${i##*/}
fname=${s%.ipynb}
if [ ${fname} != 'ps1' ]
then
chmod 777 $i/*
cp $i/* ./$fname.ipynb
fi
done
rm -r release
# Copy over the Media and other folders to student-notebooks folder
cp -r ../notebooks/Media ./Media
cp -r ../notebooks/expected_outputs ./expected_outputs
cp -r ../notebooks/outputs ./outputs
cp -r ../notebooks/inputs ./inputs
# Edit TOC and index so that links are to the student versions
sed 's/\/notebooks\//\/student-notebooks\//g' toc.ipynb > _toc.ipynb
sed 's/\/notebooks\//\/student-notebooks\//g' index.ipynb > _index.ipynb
# Remove old toc file and index file
rm toc.ipynb
rm index.ipynb
popd