8 _this_dir = os.path.dirname(__file__)
11 def write_problemlist(problem_dir=None, blacklist=(), symlink=False):
12 # remove evidence from previous runs
13 for name in os.listdir(_this_dir):
14 if os.path.islink(name):
17 # generate new symlinks and problemlist.tex
18 f = open(os.path.join(_this_dir, 'problemlist.tex'), 'w')
21 for source in sorted(os.listdir(problem_dir)):
22 if source in blacklist:
24 source_dir = os.path.join(problem_dir, source)
25 if not os.path.isdir(source_dir):
27 f.write('\\section{%s}\n' % source.replace('_', ' '))
28 for problem in sorted(os.listdir(source_dir)):
29 path = os.path.join(source_dir, problem)
30 if os.path.isfile(path):
32 relpath = os.path.relpath(path, _this_dir)
33 if path.endswith('.tex'):
35 pname = 'problem%d.tex' % i
39 f.write('\\input{%s}\n' % pname)
40 else: # utility file (e.g. image)
41 pname = '.'.join(problem.split('.')[-2:])
44 if symlink or force_link:
45 if os.path.islink(pname):
46 ha = hashlib.sha1(open(relpath, 'r').read()).digest()
47 hb = hashlib.sha1(open(pname, 'r').read()).digest()
48 assert ha == hb, (relpath, pname)
50 os.symlink(relpath, pname)
54 if __name__ == '__main__':
56 problem_dir=os.path.join(_this_dir, '..', 'problems'),
59 'Serway_and_Jewett_4',
60 # 'Serway_and_Jewett_4_venkat',
61 # 'Serway_and_Jewett_4_wking',
62 # 'Serway_and_Jewett_8',
63 # 'Thornton_and_Rex_3_wking',
64 # 'Young_and_Freedman_12',