#!/usr/bin/env python ############################################################################ # # MODULE: mkhtml.py # AUTHOR(S): Markus Neteler # Glynn Clements # Martin Landa # PURPOSE: Create HTML manual page snippets # COPYRIGHT: (C) 2007, 2009, 2011-2012 by 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 from datetime import datetime pgm = sys.argv[1] src_file = "%s.html" % pgm tmp_file = "%s.tmp.html" % pgm header_base = """ GRASS GIS Manual: ${PGM} GRASS logo
""" header_nopgm = """

${PGM}

""" header_pgm = """

NAME

${PGM} """ footer_index = string.Template(\ """

Main index - ${INDEXNAMECAP} index - Topics index - Full index

© 2003-${YEAR} GRASS Development Team, GRASS GIS ${GRASS_VERSION} Reference Manual

""") footer_noindex = string.Template(\ """

Main index - Topics index - Full index

© 2003-${YEAR} GRASS Development Team, GRASS GIS ${GRASS_VERSION} Reference Manual

""") 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) name = re.search('()', src_data, re.IGNORECASE) if name: pgm = name.group(2).strip().split('-', 1)[0].strip() desc = re.search('()', src_data, re.IGNORECASE) if desc: pgm = desc.group(2).strip() header_tmpl = string.Template(header_base + header_nopgm) else: header_tmpl = string.Template(header_base + header_pgm) 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', 'ps': 'postscript', 'p' : 'paint', 'r' : 'raster', 'r3': 'raster3D', 's' : 'sites', 't' : 'temporal', 'v' : 'vector' } index = re.search('()', src_data, re.IGNORECASE) if index: index_name_cap = index_name = index.group(2).strip() else: mod_class = pgm.split('.', 1)[0] index_name = index_names.get(mod_class, '') index_name_cap = index_name.title() grass_version = os.getenv("VERSION_NUMBER", "unknown") year = os.getenv("VERSION_DATE") if not year: year = str(datetime.now().year) if index_name: sys.stdout.write(footer_index.substitute(INDEXNAME = index_name, INDEXNAMECAP = index_name_cap, YEAR = year, GRASS_VERSION = grass_version)) else: sys.stdout.write(footer_noindex.substitute(YEAR = year, GRASS_VERSION = grass_version))