1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """Update, compile and create PDF and HTML from LaTeX file |
---|
4 | |
---|
5 | Usage: |
---|
6 | python update_anuga_user_manual.py <options> |
---|
7 | |
---|
8 | Options: |
---|
9 | --no_html: Skip automatic generation of html version |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | This script can for example be run from a cronjob: |
---|
14 | |
---|
15 | crontab -e |
---|
16 | |
---|
17 | with content |
---|
18 | |
---|
19 | SHELL=/bin/sh |
---|
20 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/bin |
---|
21 | |
---|
22 | # m h dom mon dow command |
---|
23 | 42 * * * * ~/inundation/anuga_core/documentation/user_manual/update_anuga_user_manual.py > ~/inundation/anuga_core/documentation/user_manual/update_anuga.log |
---|
24 | # |
---|
25 | |
---|
26 | |
---|
27 | Note UNIX only |
---|
28 | |
---|
29 | """ |
---|
30 | |
---|
31 | from os import system, chdir |
---|
32 | from os.path import expanduser |
---|
33 | from anuga.abstract_2d_finite_volumes.util import get_revision_number |
---|
34 | from anuga.anuga_config import major_revision |
---|
35 | from sys import argv |
---|
36 | |
---|
37 | |
---|
38 | anugapath = expanduser('~/inundation/anuga_core/documentation/user_manual') |
---|
39 | texfiles = ['anuga_user_manual', 'anuga_installation_guide'] |
---|
40 | |
---|
41 | chdir(anugapath) # Move to location of LaTeX files |
---|
42 | system('svn update') # Update from svn |
---|
43 | |
---|
44 | |
---|
45 | do_html = True |
---|
46 | if len(argv) > 1: |
---|
47 | if argv[1] == '--no_html': |
---|
48 | do_html = False |
---|
49 | else: |
---|
50 | msg = 'Unknown option: %s' %argv[1] |
---|
51 | raise Exception(msg) |
---|
52 | |
---|
53 | # Update version info |
---|
54 | fid = open('version.tex') |
---|
55 | lines = [] |
---|
56 | for line in fid.readlines(): |
---|
57 | if line.startswith('\\release'): |
---|
58 | line = '\\release{%s\\_%d}\n' %(major_revision, |
---|
59 | get_revision_number()) |
---|
60 | lines.append(line) |
---|
61 | fid.close() |
---|
62 | |
---|
63 | fid = open('version.tex', 'w') |
---|
64 | fid.writelines(lines) |
---|
65 | fid.close() |
---|
66 | |
---|
67 | print 'Updated version info:' |
---|
68 | for line in lines: |
---|
69 | print line.strip() |
---|
70 | |
---|
71 | #print 'Major revision', major_revision |
---|
72 | #print 'build', get_revision_number() |
---|
73 | |
---|
74 | |
---|
75 | for texfile in texfiles: |
---|
76 | print 'Processing %s' %texfile |
---|
77 | # Compile with LaTeX, makeindex etc |
---|
78 | for i in range(3): |
---|
79 | #system('latex --interaction=nonstopmode %s.tex' %texfile) |
---|
80 | system('pdflatex --interaction=nonstopmode %s.tex' %texfile) |
---|
81 | system('makeindex %s.idx' %texfile) |
---|
82 | system('makeindex mod%s.idx' %texfile) |
---|
83 | system('bibtex %s' %texfile) |
---|
84 | |
---|
85 | # Create pdf file |
---|
86 | #system('dvips %s -o %s.ps' %((texfile,)*2)) |
---|
87 | #system('ps2pdf %s.ps' %texfile) |
---|
88 | |
---|
89 | # Create html pages |
---|
90 | if do_html is True: |
---|
91 | system('latex2html %s' %texfile) |
---|
92 | else: |
---|
93 | print 'Skipping html version for %s as requested' %texfile |
---|
94 | |
---|