Add all-problem testing.
[course.git] / latex / test / write_problemlist.py
1 #!/usr/bin/env python
2
3 import os
4 import os.path
5
6
7 _this_dir = os.path.dirname(__file__)
8
9
10 def write_problemlist(problem_dir=None, blacklist=()):
11     # remove evidence from previous runs
12     for name in os.listdir(_this_dir):
13         if os.path.islink(name):
14             os.unlink(name)
15
16     # generate new symlinks and problemlist.tex
17     f = open(os.path.join(_this_dir, 'problemlist.tex'), 'w')
18     i = 1
19     for source in sorted(os.listdir(problem_dir)):
20         if source in blacklist:
21             continue
22         source_dir = os.path.join(problem_dir, source)
23         if not os.path.isdir(source_dir):
24             continue
25         f.write('\section{%s}' % source.replace('_', ' '))
26         for problem in sorted(os.listdir(source_dir)):
27             path = os.path.join(source_dir, problem)
28             if os.path.isfile(path):
29                 relpath = os.path.relpath(path, _this_dir)
30                 if path.endswith('.tex'):
31                     pname = 'problem%d.tex' % i
32                     i += 1
33                     f.write('\\input{%s}\n' % pname)
34                 else:  # utility file (e.g. image)
35                     pname = problem
36                 os.symlink(relpath, pname)
37     f.close()
38
39
40 if __name__ == '__main__':
41     write_problemlist(
42         problem_dir=os.path.join(_this_dir, '..', 'problems'),
43         blacklist=[
44             'Giancoli_6',
45             'Serway_and_Jewett_4',
46             'Serway_and_Jewett_4_venkat',
47             'Serway_and_Jewett_4_wking',
48 #            'Serway_and_Jewett_8',
49             'Thornton_and_Rex_3',
50             'Thornton_and_Rex_3_wking',
51             'Young_and_Freedman_12',
52             'wking',
53             ]
54         )