#!/usr/bin/env python ############################################################################ # # MODULE: mkhtml.py # AUTHOR(S): Markus Neteler, Glynn Clements # PURPOSE: create HTML manual page snippets # COPYRIGHT: (C) 2007,2009 Glynn Clements and the GRASS Development Team # # This program is free software under the GNU General Public # License (>=v2). Read the file COPYING that comes with GRASS # for details. # ############################################################################# import sys import os import string import re pgm = sys.argv[1] src_file = "%s.html" % pgm tmp_file = "%s.tmp.html" % pgm header_tmpl = string.Template(\ """ GRASS GIS Manual: ${PGM} GRASS logo

NAME

${PGM} """) footer_tmpl = string.Template(\ """

Main index - $INDEXNAME index - Full index

© 2003-2009 GRASS Development Team

""") def read_file(name): try: f = open(name, 'rb') s = f.read() f.close() return s except IOError: return "" src_data = read_file(src_file) if not re.search('', src_data, re.IGNORECASE): tmp_data = read_file(tmp_file) if not re.search('', tmp_data, re.IGNORECASE): sys.stdout.write(header_tmpl.substitute(PGM = pgm)) if tmp_data: for line in tmp_data.splitlines(True): if not re.search('|', line, re.IGNORECASE): sys.stdout.write(line) sys.stdout.write(src_data) # if is found, suppose a complete html is provided. # otherwise, generate module class reference: if re.search('', src_data, re.IGNORECASE): sys.exit() index_names = { 'd': 'display', 'db': 'database', 'g': 'general', 'i': 'imagery', 'm': 'misc', 'pg': 'postGRASS', 'ps': 'postscript', 'p': 'paint', 'r': 'raster', 'r3': 'raster3D', 's': 'sites', 'v': 'vector' } mod_class = pgm.split('.', 1)[0] index_name = index_names.get(mod_class, mod_class) sys.stdout.write(footer_tmpl.substitute(INDEXNAME = index_name))