~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to man/build_html.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# utilities for generating HTML indices
 
5
# (c) 2003-2015 by the GRASS Development Team, Markus Neteler, Glynn Clements, Luca Delucchi
 
6
 
 
7
import sys
 
8
import os
 
9
import string
 
10
from datetime import datetime
 
11
 
 
12
## TODO: better fix this in include/Make/Html.make, see bug RT #5361
 
13
 
 
14
# exclude following list of modules from help index:
 
15
 
 
16
exclude_mods = [
 
17
    "i.find",
 
18
    "r.watershed.ram",
 
19
    "r.watershed.seg",
 
20
    "v.topo.check",
 
21
    "helptext.html"]
 
22
 
 
23
# these modules don't use G_parser()
 
24
 
 
25
desc_override = {
 
26
    "g.parser": "Provides automated parser, GUI, and help support for GRASS scipts.",
 
27
    "r.li.daemon": "Support module for r.li landscape index calculations."
 
28
    }
 
29
 
 
30
############################################################################
 
31
 
 
32
header1_tmpl = string.Template(\
 
33
r"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
34
<html>
 
35
<head>
 
36
 <title>${title}</title>
 
37
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
38
 <meta name="Author" content="GRASS Development Team">
 
39
""")
 
40
 
 
41
macosx_tmpl = string.Template(\
 
42
r"""
 
43
 <meta name="AppleTitle" content="GRASS GIS ${grass_version} Help">
 
44
 <meta name="AppleIcon" content="GRASS-${grass_mmver}/grass_icon.png">
 
45
 <meta name="robots" content="anchors">
 
46
""")
 
47
 
 
48
header2_tmpl = string.Template(\
 
49
r""" <link rel="stylesheet" href="grassdocs.css" type="text/css">
 
50
</head>
 
51
<body style="width: ${body_width}">
 
52
<div id="container">
 
53
<!-- this file is generated by man/build_html.py -->
 
54
 
 
55
<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
 
56
<hr class="header">
 
57
 
 
58
<h2>GRASS GIS ${grass_version} Reference Manual</h2>
 
59
 
 
60
<p><b>Geographic Resources Analysis Support System</b>, commonly
 
61
referred to as <a href="http://grass.osgeo.org">GRASS</a>, is a <a
 
62
href="http://en.wikipedia.org/wiki/Geographic_information_system">Geographic
 
63
Information System</a> (GIS) used for geospatial data management and
 
64
analysis, image processing, graphics/maps production, spatial
 
65
modeling, and visualization. GRASS is currently used in academic and
 
66
commercial settings around the world, as well as by many governmental
 
67
agencies and environmental consulting companies.</p>
 
68
 
 
69
<p>This reference manual details the use of modules distributed with
 
70
Geographic Resources Analysis Support System (GRASS), an open source
 
71
(<a href="http://www.gnu.org/licenses/gpl.html">GNU GPLed</a>), image
 
72
processing and geographic information system (GIS).</p>
 
73
 
 
74
""")
 
75
#"
 
76
 
 
77
overview_tmpl = string.Template(\
 
78
r"""<!-- the files grass${grass_version_major}.html & helptext.html file live in lib/init/ -->
 
79
 
 
80
<table align="center" border="0" cellspacing="8">
 
81
  <tbody>
 
82
    <tr>
 
83
      <td width="33%" valign="top" class="box"><h3>&nbsp;Quick Introduction</h3>
 
84
      <ul>
 
85
       <li class="box"><a href="helptext.html">How to start with GRASS GIS</a></li>
 
86
       <li class="box"><span>Index of <a href="topics.html">topics</a> and <a href="keywords.html">keywords</a></span></li>
 
87
      </ul>
 
88
      <p>
 
89
      <ul>
 
90
       <li class="box"><a href="projectionintro.html">Intro: projections and spatial transformations</a></li>
 
91
      </ul>
 
92
      <p>
 
93
      <ul>
 
94
       <li class="box"><span><a href="http://grasswiki.osgeo.org/wiki/Faq">FAQ - Frequently Asked Questions</a> (Wiki)</span></li>
 
95
      </ul>
 
96
      </td>
 
97
      <td width="33%" valign="top" class="box"><h3>&nbsp;Graphical User Interface</h3>
 
98
       <ul>
 
99
        <li class="box"><span><a href="wxGUI.html">wxGUI</a></span></li>
 
100
        <li class="box"><a href="wxGUI.components.html">wxGUI components</a></li>
 
101
        <li class="box"><a href="wxGUI.toolboxes.html">wxGUI toolboxes</a></li>
 
102
       </ul>
 
103
 
 
104
       <ul>
 
105
        <li class="box"><a href="topic_gui.html">GUI commands</a></li>
 
106
       </ul>
 
107
       <h3>&nbsp;Display</h3>
 
108
       <ul>
 
109
        <li class="box"><a href="display.html">Display commands manual</a></li>
 
110
        <li class="box"><a href="displaydrivers.html">Display drivers</a></li>
 
111
       </ul>
 
112
      </td>
 
113
      <td width="33%" valign="top" class="box"><h3>&nbsp;General</h3>
 
114
       <ul>
 
115
        <li class="box"><a href="grass${grass_version_major}.html">GRASS GIS startup manual</a></li>
 
116
        <li class="box"><a href="general.html">General commands manual</a></li>
 
117
       </ul>
 
118
        <h3>&nbsp;Addons</h3>
 
119
        <ul>
 
120
        <li class="box"><a href="http://grass.osgeo.org/grass70/manuals/addons/">Addons manual pages</a></li>
 
121
       </ul>
 
122
      </td>
 
123
    </tr>
 
124
    <tr>
 
125
      <td width="33%" valign="top" class="box"><h3>&nbsp;Raster processing</h3>
 
126
       <ul>
 
127
        <li class="box"><a href="rasterintro.html">Intro: 2D raster map processing</a></li>
 
128
        <li class="box"><a href="raster.html">Raster commands manual</a></li>
 
129
       </ul>
 
130
      </td>
 
131
      <td width="33%" valign="top" class="box"><h3>&nbsp;3D raster processing</h3>
 
132
       <ul>
 
133
        <li class="box"><a href="raster3dintro.html">Intro: 3D raster map (voxel) processing</a></li>
 
134
        <li class="box"><a href="raster3d.html">3D raster (voxel) commands manual</a></li>
 
135
      </ul></td>
 
136
      <td width="33%" valign="top" class="box"><h3>&nbsp;Image processing</h3>
 
137
       <ul>
 
138
        <li class="box"><a href="imageryintro.html">Intro: image processing</a></li>
 
139
        <li class="box"><a href="imagery.html">Imagery commands manual</a></li>
 
140
      </ul></td>
 
141
    </tr>
 
142
    <tr>
 
143
      <td width="33%" valign="top" class="box"><h3>&nbsp;Vector processing</h3>
 
144
       <ul>
 
145
        <li class="box"><a href="vectorintro.html">Intro: vector map processing and network analysis</a></li>
 
146
        <li class="box"><a href="vector.html">Vector commands manual</a></li>
 
147
        <li class="box"><a href="vectorascii.html">GRASS ASCII vector format specification</a></li>
 
148
      </ul></td>
 
149
      <td width="33%" valign="top" class="box"><h3>&nbsp;Database</h3>
 
150
       <ul>
 
151
        <li class="box"><a href="databaseintro.html">Intro: database management</a></li>
 
152
        <li class="box"><a href="sql.html">SQL support in GRASS GIS</a></li>
 
153
        <li class="box"><a href="database.html">Database commands manual</a></li>
 
154
       </ul>
 
155
      </td>
 
156
      <td width="33%" valign="top" class="box"><h3>&nbsp;Temporal processing</h3>
 
157
       <ul>
 
158
        <li class="box"><a href="temporalintro.html">Intro: temporal data processing</a></li>
 
159
        <li class="box"><a href="temporal.html">Temporal commands manual</a></li>
 
160
       </ul>
 
161
      </td>
 
162
    </tr>
 
163
    <tr>
 
164
      <td width="33%" valign="top" class="box"><h3>&nbsp;Cartography</h3>
 
165
       <ul>
 
166
        <li class="box"><a href="postscript.html">Postscript commands manual</a></li>
 
167
        <li class="box"><a href="g.gui.psmap.html">wxGUI Cartographic Composer</a></li>
 
168
       </ul>
 
169
      </td>
 
170
      <td width="33%" valign="top" class="box"><h3>&nbsp;Miscellaneous&nbsp;&amp;&nbsp;Variables</h3>
 
171
       <ul>
 
172
        <li class="box"><a href="misc.html">Miscellaneous commands manual</a></li>
 
173
        <li class="box"><a href="variables.html">GRASS variables and environment variables</a></li>
 
174
       </ul>
 
175
      </td>
 
176
      <td width="33%" valign="top" class="box"><h3>&nbsp;Python</h3>
 
177
       <ul>
 
178
        <li class="box"><a href="http://grass.osgeo.org/grass${grass_version_major}${grass_version_minor}/manuals/libpython/pygrass_index.html">PyGRASS documentation</a></li>
 
179
       </ul>
 
180
      </td>
 
181
    </tr>
 
182
  </tbody>
 
183
</table>
 
184
""")
 
185
#"
 
186
 
 
187
footer_tmpl = string.Template(\
 
188
r"""<hr class="header">
 
189
<p><a href="${index_url}">Help Index</a> | <a href="topics.html">Topics Index</a> | <a href="keywords.html">Keywords Index</a> | <a href="full_index.html">Full Index</a></p>
 
190
<p>&copy; 2003-${year} <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS ${grass_version} Reference Manual</p>
 
191
 
 
192
</div>
 
193
</body>
 
194
</html>
 
195
""")
 
196
#"
 
197
 
 
198
cmd2_tmpl = string.Template(\
 
199
r"""<a name="${cmd}"></a>
 
200
<h3>${cmd_label} commands (${cmd}.*)</h3>
 
201
<table>
 
202
""")
 
203
#"
 
204
 
 
205
desc1_tmpl = string.Template(\
 
206
r"""<tr><td valign="top"><a href="${cmd}">${basename}</a></td> <td>${desc}</td></tr>
 
207
""")
 
208
#"
 
209
 
 
210
toc = \
 
211
r"""
 
212
<div class="toc">
 
213
<h4 class="toc">Table of contents</h4>
 
214
<ul class="toc">
 
215
<li class="toc"><a class="toc" href="full_index.html#d">Display commands (d.*)</a></li>
 
216
<li class="toc"><a class="toc" href="full_index.html#db">Database commands (db.*)</a></li>
 
217
<li class="toc"><a class="toc" href="full_index.html#g">General commands (g.*)</a></li>
 
218
<li class="toc"><a class="toc" href="full_index.html#i">Imagery commands (i.*)</a></li>
 
219
<li class="toc"><a class="toc" href="full_index.html#m">Miscellaneous commands (m.*)</a></li>
 
220
<li class="toc"><a class="toc" href="full_index.html#ps">PostScript commands (ps.*)</a></li>
 
221
<li class="toc"><a class="toc" href="full_index.html#r">Raster commands (r.*)</a></li>
 
222
<li class="toc"><a class="toc" href="full_index.html#r3">3D raster commands (r3.*)</a></li>
 
223
<li class="toc"><a class="toc" href="full_index.html#t">Temporal commands (t.*)</a></li>
 
224
<li class="toc"><a class="toc" href="full_index.html#v">Vector commands (v.*)</a></li>
 
225
<li class="toc"><a class="toc" href="wxGUI.html">wxGUI Graphical User Interface</a></li>
 
226
<li class="toc"><a class="toc" href="wxGUI.nviz.html">3D visualization suite</a></li>
 
227
</ul>
 
228
</div>
 
229
"""
 
230
#"
 
231
 
 
232
modclass_intro_tmpl = string.Template(\
 
233
r"""Go to <a href="${modclass_lower}intro.html">${modclass} introduction</a> | <a href="topics.html">topics</a> <p>
 
234
""")
 
235
#"
 
236
 
 
237
modclass_tmpl = string.Template(\
 
238
r"""Go <a href="index.html">back to help overview</a>
 
239
<h3>${modclass} commands:</h3>
 
240
<table>
 
241
""")
 
242
#"
 
243
 
 
244
desc2_tmpl = string.Template(\
 
245
r"""<tr><td valign="top"><a href="${cmd}">${basename}</a></td> <td>${desc}</td></tr>
 
246
""")
 
247
#"
 
248
 
 
249
 
 
250
full_index_header = \
 
251
r"""
 
252
Go <a href="index.html">back to help overview</a>
 
253
"""
 
254
#"
 
255
 
 
256
 
 
257
message_tmpl = string.Template(\
 
258
r"""Generated HTML docs in ${html_dir}/index.html
 
259
----------------------------------------------------------------------
 
260
Following modules are missing the 'modulename.html' file in src code:
 
261
""")
 
262
#"
 
263
 
 
264
moduletopics_tmpl = string.Template(\
 
265
r"""
 
266
<li> <a href="topic_${key}.html">${name}</a></li>
 
267
"""
 
268
)
 
269
#"
 
270
 
 
271
headertopics_tmpl = \
 
272
r"""
 
273
<link rel="stylesheet" href="grassdocs.css" type="text/css">
 
274
</head>
 
275
<body style="width: 99%">
 
276
<div id="container">
 
277
 
 
278
<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
 
279
<hr class="header">
 
280
<h2>Topics</h2>
 
281
<ul>
 
282
"""
 
283
#"
 
284
 
 
285
headerkeywords_tmpl = \
 
286
r"""
 
287
<link rel="stylesheet" href="grassdocs.css" type="text/css">
 
288
</head>
 
289
<body style="width: 99%">
 
290
<div id="container">
 
291
 
 
292
<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
 
293
<hr class="header">
 
294
<h2>Keywords - Index of GRASS GIS modules</h2>
 
295
"""
 
296
#"
 
297
 
 
298
headerkey_tmpl = string.Template(\
 
299
r"""
 
300
<link rel="stylesheet" href="grassdocs.css" type="text/css">
 
301
</head>
 
302
<body bgcolor="white">
 
303
<div id="container">
 
304
 
 
305
<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
 
306
<hr class="header">
 
307
 
 
308
<h2>Topic: ${keyword}</h2>
 
309
<i>Note: see also the corresponding keyword <a href="keywords.html#${keyword}">${keyword}</a> for additional references.</i>
 
310
<p>
 
311
<table>
 
312
""")
 
313
#"
 
314
 
 
315
############################################################################
 
316
 
 
317
def check_for_desc_override(basename):
 
318
    return desc_override.get(basename)
 
319
 
 
320
def read_file(name):
 
321
    f = open(name, 'rb')
 
322
    s = f.read()
 
323
    f.close()
 
324
    return s
 
325
 
 
326
def write_file(name, contents):
 
327
    f = open(name, 'wb')
 
328
    f.write(contents)
 
329
    f.close()
 
330
 
 
331
def try_mkdir(path):
 
332
    try:
 
333
        os.mkdir(path)
 
334
    except OSError as e:
 
335
        pass
 
336
 
 
337
def replace_file(name):
 
338
    temp = name + ".tmp"
 
339
    if os.path.exists(name) and os.path.exists(temp) and read_file(name) == read_file(temp):
 
340
        os.remove(temp)
 
341
    else:
 
342
        try:
 
343
            os.remove(name)
 
344
        except OSError as e:
 
345
            pass
 
346
        os.rename(temp, name)
 
347
 
 
348
def copy_file(src, dst):
 
349
    write_file(dst, read_file(src))
 
350
 
 
351
def html_files(cls = None):
 
352
    for cmd in sorted(os.listdir(html_dir)):
 
353
        if cmd.endswith(".html") and \
 
354
           (cls in [None, '*'] or cmd.startswith(cls + ".")) and \
 
355
           (cls != '*' or len(cmd.split('.')) >= 3) and \
 
356
           cmd not in ["full_index.html", "index.html"] and \
 
357
           cmd not in exclude_mods and \
 
358
           not cmd.startswith("wxGUI."):
 
359
            yield cmd
 
360
 
 
361
def write_html_header(f, title, ismain = False, body_width = "99%"):
 
362
    f.write(header1_tmpl.substitute(title = title))
 
363
    if ismain and macosx:
 
364
        f.write(macosx_tmpl.substitute(grass_version = grass_version,
 
365
                                       grass_mmver = grass_mmver))
 
366
    f.write(header2_tmpl.substitute(grass_version = grass_version, body_width = body_width))
 
367
 
 
368
def write_html_cmd_overview(f):
 
369
    f.write(overview_tmpl.substitute(grass_version_major = grass_version_major,
 
370
                                     grass_version_minor = grass_version_minor))
 
371
 
 
372
def write_html_footer(f, index_url, year = None):
 
373
    if year is None:
 
374
        cur_year = default_year
 
375
    else:
 
376
        cur_year = year
 
377
    f.write(footer_tmpl.substitute(grass_version = grass_version,
 
378
                                   index_url = index_url, year = cur_year))
 
379
 
 
380
def get_desc(cmd):
 
381
    f = open(cmd, 'r')
 
382
    while True:
 
383
        line = f.readline()
 
384
        if not line:
 
385
            return ""
 
386
        if "NAME" in line:
 
387
            break
 
388
 
 
389
    while True:
 
390
        line = f.readline()
 
391
        if not line:
 
392
            return ""
 
393
        if "SYNOPSIS" in line:
 
394
            break
 
395
        if "<em>" in line:
 
396
            sp = line.split('-',1)
 
397
            if len(sp) > 1:
 
398
                return sp[1].strip()
 
399
            else:
 
400
                return None
 
401
 
 
402
    return ""
 
403
 
 
404
def to_title(name):
 
405
    """Convert name of command class/family to form suitable for title"""
 
406
    return name.capitalize()
 
407
 
 
408
############################################################################
 
409
 
 
410
arch_dist_dir = os.environ['ARCH_DISTDIR']
 
411
html_dir = os.path.join(arch_dist_dir, "docs", "html")
 
412
gisbase = os.environ['GISBASE']
 
413
grass_version = os.getenv("VERSION_NUMBER", "unknown")
 
414
grass_version_major = grass_version.split('.')[0]
 
415
grass_version_minor = grass_version.split('.')[1]
 
416
grass_mmver = '.'.join(grass_version.split('.')[0:2])
 
417
macosx = "darwin" in os.environ['ARCH'].lower()
 
418
default_year = os.getenv("VERSION_DATE")
 
419
if not default_year:
 
420
    default_year = str(datetime.now().year)
 
421
 
 
422
############################################################################