Menu

[r6558]: / trunk / py4science / workbook / update_problems.py  Maximize  Restore  History

Download this file

37 lines (27 with data), 1.1 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
#!/usr/bin/env python
"""Update the problems (skeletons and solutions) relative to their source.
"""
import os
from glob import glob
from os import system as sh
from IPython.genutils import target_outdated
# Constants
SRC_DIR = '../examples' # source dir for the examples
UPDATE = './mkprob.py' # executable to make problems (in SRC_DIR)
PROBLEMS_DIR = 'problems' # directory for problem output (in this dir)
if __name__ == '__main__':
problems = [f for f in os.listdir(PROBLEMS_DIR) if f.endswith('.py')]
os.chdir(SRC_DIR)
to_update = []
for f in problems:
skel = os.path.join('skel',f.replace('.py','_skel.py'))
soln = os.path.join('soln',f.replace('.py','_soln.py'))
src = [f]
if target_outdated(skel,src) or target_outdated(soln,src):
to_update.append(f)
if to_update:
targets = ' '.join(to_update)
print 'Updating the following problems:\n',targets
sh('%s %s' % (UPDATE,targets))
else:
print 'All targets up to date, nothing to do.'