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