ya2 · news · projects · code · about

refactoring of functional tests
[pmachines.git] / lib / tools / pdfsingle.py
CommitLineData
8ee66edd
FC
1# python lib/tools/pdfsingle.py path/to/file.py
2from os import chdir, getcwd, system
3from os.path import dirname, basename, exists
4from sys import argv
5
6
7class InsideDir:
8
9 def __init__(self, dir_):
10 self.dir = dir_
11 self.old_dir = getcwd()
12
13 def __enter__(self):
14 chdir(self.dir)
15
16 def __exit__(self, exc_type, exc_val, exc_tb):
17 chdir(self.old_dir)
18
19
20filename = argv[1]
21name = basename(filename)
22path = dirname(filename)
23noext = name.rsplit('.', 1)[0]
24test_tmpl = "tail -n +1 {found} " + \
25 "| sed 's/==> /# ==> /' > tmp.txt ; enscript --font=Courier10 " + \
26 "--continuous-page-numbers --no-header --pretty-print=python " + \
27 "-o - tmp.txt | psnup -2 -P letter -p a4 -m12 | ps2pdf - {name}.pdf ; rm tmp.txt"
28 #"-o - tmp.txt | ps2pdf - {name}.pdf ; rm tmp.txt"
29found = filename
30with InsideDir('tests/' + path):
31 if exists('test_' + name):
32 found += ' lib/tests/%s/test_%s' % (path, name)
33test_cmd = test_tmpl.format(name=noext, found=found)
34system(test_cmd)
35#system('pdfnup --nup 2x1 -o {noext}.pdf {noext}.pdf'.format(noext=noext))