#!/usr/bin/env python # -*- coding: utf-8 -*- # utilities for generating HTML indices # (c) 2003-2015 by the GRASS Development Team, Markus Neteler, Glynn Clements, Luca Delucchi import sys import os import string from datetime import datetime ## TODO: better fix this in include/Make/Html.make, see bug RT #5361 # exclude following list of modules from help index: exclude_mods = [ "i.find", "r.watershed.ram", "r.watershed.seg", "v.topo.check", "helptext.html"] # these modules don't use G_parser() desc_override = { "g.parser": "Provides automated parser, GUI, and help support for GRASS scipts.", "r.li.daemon": "Support module for r.li landscape index calculations." } ############################################################################ header1_tmpl = string.Template(\ r""" ${title} """) macosx_tmpl = string.Template(\ r""" """) header2_tmpl = string.Template(\ r"""
GRASS logo

GRASS GIS ${grass_version} Reference Manual

Geographic Resources Analysis Support System, commonly referred to as GRASS, is a Geographic Information System (GIS) used for geospatial data management and analysis, image processing, graphics/maps production, spatial modeling, and visualization. GRASS is currently used in academic and commercial settings around the world, as well as by many governmental agencies and environmental consulting companies.

This reference manual details the use of modules distributed with Geographic Resources Analysis Support System (GRASS), an open source (GNU GPLed), image processing and geographic information system (GIS).

""") #" overview_tmpl = string.Template(\ r"""

 Quick Introduction

 Graphical User Interface

 Display

 General

 Addons

 Raster processing

 3D raster processing

 Image processing

 Vector processing

 Database

 Temporal processing

 Cartography

 Miscellaneous & Variables

 Python

""") #" footer_tmpl = string.Template(\ r"""

Help Index | Topics Index | Keywords Index | Full Index

© 2003-${year} GRASS Development Team, GRASS GIS ${grass_version} Reference Manual

""") #" cmd2_tmpl = string.Template(\ r"""

${cmd_label} commands (${cmd}.*)

""") #" desc1_tmpl = string.Template(\ r""" """) #" toc = \ r"""

Table of contents

""" #" modclass_intro_tmpl = string.Template(\ r"""Go to ${modclass} introduction | topics

""") #" modclass_tmpl = string.Template(\ r"""Go back to help overview

${modclass} commands:

${basename} ${desc}
""") #" desc2_tmpl = string.Template(\ r""" """) #" full_index_header = \ r""" Go back to help overview """ #" message_tmpl = string.Template(\ r"""Generated HTML docs in ${html_dir}/index.html ---------------------------------------------------------------------- Following modules are missing the 'modulename.html' file in src code: """) #" moduletopics_tmpl = string.Template(\ r"""
  • ${name}
  • """ ) #" headertopics_tmpl = \ r"""
    GRASS logo

    Topics

    ${basename} ${desc}
    """) #" ############################################################################ def check_for_desc_override(basename): return desc_override.get(basename) def read_file(name): f = open(name, 'rb') s = f.read() f.close() return s def write_file(name, contents): f = open(name, 'wb') f.write(contents) f.close() def try_mkdir(path): try: os.mkdir(path) except OSError as e: pass def replace_file(name): temp = name + ".tmp" if os.path.exists(name) and os.path.exists(temp) and read_file(name) == read_file(temp): os.remove(temp) else: try: os.remove(name) except OSError as e: pass os.rename(temp, name) def copy_file(src, dst): write_file(dst, read_file(src)) def html_files(cls = None): for cmd in sorted(os.listdir(html_dir)): if cmd.endswith(".html") and \ (cls in [None, '*'] or cmd.startswith(cls + ".")) and \ (cls != '*' or len(cmd.split('.')) >= 3) and \ cmd not in ["full_index.html", "index.html"] and \ cmd not in exclude_mods and \ not cmd.startswith("wxGUI."): yield cmd def write_html_header(f, title, ismain = False, body_width = "99%"): f.write(header1_tmpl.substitute(title = title)) if ismain and macosx: f.write(macosx_tmpl.substitute(grass_version = grass_version, grass_mmver = grass_mmver)) f.write(header2_tmpl.substitute(grass_version = grass_version, body_width = body_width)) def write_html_cmd_overview(f): f.write(overview_tmpl.substitute(grass_version_major = grass_version_major, grass_version_minor = grass_version_minor)) def write_html_footer(f, index_url, year = None): if year is None: cur_year = default_year else: cur_year = year f.write(footer_tmpl.substitute(grass_version = grass_version, index_url = index_url, year = cur_year)) def get_desc(cmd): f = open(cmd, 'r') while True: line = f.readline() if not line: return "" if "NAME" in line: break while True: line = f.readline() if not line: return "" if "SYNOPSIS" in line: break if "" in line: sp = line.split('-',1) if len(sp) > 1: return sp[1].strip() else: return None return "" def to_title(name): """Convert name of command class/family to form suitable for title""" return name.capitalize() ############################################################################ arch_dist_dir = os.environ['ARCH_DISTDIR'] html_dir = os.path.join(arch_dist_dir, "docs", "html") gisbase = os.environ['GISBASE'] grass_version = os.getenv("VERSION_NUMBER", "unknown") grass_version_major = grass_version.split('.')[0] grass_version_minor = grass_version.split('.')[1] grass_mmver = '.'.join(grass_version.split('.')[0:2]) macosx = "darwin" in os.environ['ARCH'].lower() default_year = os.getenv("VERSION_DATE") if not default_year: default_year = str(datetime.now().year) ############################################################################