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 like |
---|
18 | |
---|
19 | SHELL=/bin/sh |
---|
20 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/bin |
---|
21 | PYTHONPATH=.:/home/ole/inundation/anuga_core/source:/home/ole/lib/python/site-packages: |
---|
22 | |
---|
23 | # m h dom mon dow command |
---|
24 | 32 6,10,14,18,22 * * * ~/inundation/anuga_core/documentation/user_manual/update_anuga_user_manual.py > ~/inundation/anuga_core/documentation/user_manual/update_anuga.log |
---|
25 | # |
---|
26 | |
---|
27 | or |
---|
28 | |
---|
29 | # m h dom mon dow command |
---|
30 | 42 * * * * ~/inundation/anuga_core/documentation/user_manual/update_anuga_user_manual.py > ~/inundation/anuga_core/documentation/user_manual/update_anuga.log |
---|
31 | # |
---|
32 | |
---|
33 | Check function of crontab by reading mail using e.g. mutt |
---|
34 | |
---|
35 | |
---|
36 | Note UNIX only |
---|
37 | |
---|
38 | """ |
---|
39 | |
---|
40 | from os import system, chdir |
---|
41 | from os.path import expanduser, split, join |
---|
42 | from anuga.utilities.system_tools import get_revision_number, get_pathname_from_package |
---|
43 | from anuga.config import anuga_version |
---|
44 | from sys import argv |
---|
45 | |
---|
46 | # Determine absolute path for user manual |
---|
47 | |
---|
48 | # Path for ANUGA |
---|
49 | #anugapath = get_pathname_from_package('anuga') |
---|
50 | |
---|
51 | # Strip trailing source/anuga of path |
---|
52 | #basepath = split(split(anugapath)[0])[0] |
---|
53 | |
---|
54 | # Add local path to user_manual |
---|
55 | #docpath = join(join(basepath, 'documentation'), 'user_manual') |
---|
56 | texfiles = ['anuga_user_manual', |
---|
57 | 'anuga_installation_guide', |
---|
58 | 'anuga_whats_new', |
---|
59 | 'anuga_internal_tools'] |
---|
60 | |
---|
61 | #print 'Moving to', docpath |
---|
62 | #chdir(docpath) # Move to location of LaTeX files |
---|
63 | system('svn update') # Update from svn |
---|
64 | |
---|
65 | |
---|
66 | do_html = True |
---|
67 | if len(argv) > 1: |
---|
68 | if argv[1] == '--no_html': |
---|
69 | do_html = False |
---|
70 | else: |
---|
71 | msg = 'Unknown option: %s' %argv[1] |
---|
72 | raise Exception(msg) |
---|
73 | |
---|
74 | # Update version info |
---|
75 | fid = open('version.tex') |
---|
76 | lines = [] |
---|
77 | for line in fid.readlines(): |
---|
78 | if line.startswith('\\release'): |
---|
79 | line = '\\release{%s}\n' %(anuga_version) |
---|
80 | |
---|
81 | lines.append(line) |
---|
82 | fid.close() |
---|
83 | |
---|
84 | fid = open('version.tex', 'w') |
---|
85 | fid.writelines(lines) |
---|
86 | fid.close() |
---|
87 | |
---|
88 | print 'Updated version info:' |
---|
89 | for line in lines: |
---|
90 | print line.strip() |
---|
91 | |
---|
92 | for texfile in texfiles: |
---|
93 | print 'Processing %s' %texfile |
---|
94 | # Compile with LaTeX, makeindex etc |
---|
95 | for i in range(3): |
---|
96 | #system('latex --interaction=nonstopmode %s.tex' %texfile) |
---|
97 | system('pdflatex --interaction=nonstopmode -file-line-error %s.tex' %texfile) |
---|
98 | system('makeindex %s.idx' %texfile) |
---|
99 | system('makeindex mod%s.idx' %texfile) |
---|
100 | system('bibtex %s' %texfile) |
---|
101 | |
---|
102 | # Create pdf file |
---|
103 | #system('dvips %s -o %s.ps' %((texfile,)*2)) |
---|
104 | #system('ps2pdf %s.ps' %texfile) |
---|
105 | |
---|
106 | # Create html pages |
---|
107 | if do_html is True: |
---|
108 | system('latex2html %s' %texfile) |
---|
109 | else: |
---|
110 | print 'Skipping html version for %s as requested' %texfile |
---|
111 | |
---|
112 | # Clean-up |
---|
113 | #system('/bin/rm version.tex') |
---|
114 | system('svn update') # Restore version file |
---|
115 | |
---|
116 | |
---|
117 | # Print |
---|
118 | print 'User manual compiled' |
---|
119 | |
---|
120 | print 'Anuga version:', anuga_version |
---|
121 | print 'Build:', get_revision_number() |
---|
122 | system('date') |
---|
123 | |
---|