|
@@ -5,7 +5,7 @@
|
|
#
|
|
#
|
|
# MODULE: build_graphical_index
|
|
# MODULE: build_graphical_index
|
|
# AUTHOR(S): Vaclav Petras <wenzeslaus gmail com>
|
|
# AUTHOR(S): Vaclav Petras <wenzeslaus gmail com>
|
|
-# PURPOSE: Build index (gallery) from images from all HTML files
|
|
|
|
|
|
+# PURPOSE: Build graphical index
|
|
# COPYRIGHT: (C) 2015 by Vaclav Petras and the GRASS Development Team
|
|
# COPYRIGHT: (C) 2015 by Vaclav Petras and the GRASS Development Team
|
|
#
|
|
#
|
|
# This program is free software under the GNU General Public
|
|
# This program is free software under the GNU General Public
|
|
@@ -24,16 +24,6 @@ from build_html import write_html_footer, grass_version, header1_tmpl
|
|
|
|
|
|
output_name = 'graphical_index.html'
|
|
output_name = 'graphical_index.html'
|
|
|
|
|
|
-img_extensions = ['png', 'jpg', 'gif']
|
|
|
|
-img_patterns = ['*.' + extension for extension in img_extensions]
|
|
|
|
-
|
|
|
|
-# we don't want some images to show up
|
|
|
|
-# logos
|
|
|
|
-img_blacklist = ['grass_logo.png', 'grass_icon.png']
|
|
|
|
-# circles with numbers from helptext.html (unfortunate we have to list it here)
|
|
|
|
-# perhaps some general name ending would be good, like *_noindex.png
|
|
|
|
-img_blacklist.extend(['circle_{}.png'.format(num) for num in range(1, 6)])
|
|
|
|
-
|
|
|
|
year = os.getenv("VERSION_DATE")
|
|
year = os.getenv("VERSION_DATE")
|
|
|
|
|
|
# other similar strings are in a different file
|
|
# other similar strings are in a different file
|
|
@@ -51,9 +41,10 @@ header_graphical_index_tmpl = """\
|
|
.img-list li {
|
|
.img-list li {
|
|
display: inline-block;
|
|
display: inline-block;
|
|
position: relative;
|
|
position: relative;
|
|
- width: 7em;
|
|
|
|
|
|
+ width: 8em;
|
|
margin: 0;
|
|
margin: 0;
|
|
padding: 0.5em;
|
|
padding: 0.5em;
|
|
|
|
+ margin-bottom: 1em;
|
|
}
|
|
}
|
|
|
|
|
|
.img-list li:hover {
|
|
.img-list li:hover {
|
|
@@ -79,9 +70,9 @@ header_graphical_index_tmpl = """\
|
|
margin: 0.1em;
|
|
margin: 0.1em;
|
|
display: block;
|
|
display: block;
|
|
color: #409940;
|
|
color: #409940;
|
|
- font-weight: normal;
|
|
|
|
- font-style: italic;
|
|
|
|
- font-size: 80%;
|
|
|
|
|
|
+ font-weight: bold;
|
|
|
|
+ font-style: normal;
|
|
|
|
+ font-size: 120%;
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|
|
</head>
|
|
</head>
|
|
@@ -94,91 +85,46 @@ header_graphical_index_tmpl = """\
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
|
|
-def img_in_html(filename, imagename):
|
|
|
|
- # for some reason, calling search just once is much faster
|
|
|
|
- # than calling it on every line (time is spent in _compile)
|
|
|
|
- pattern = re.compile('<img .*src=.{}.*>'.format(imagename))
|
|
|
|
- with open(filename) as file:
|
|
|
|
- if re.search(pattern, file.read()):
|
|
|
|
- return True
|
|
|
|
- return False
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def file_matches(filename, patterns):
|
|
|
|
- for pattern in patterns:
|
|
|
|
- if fnmatch.fnmatch(filename, pattern):
|
|
|
|
- return True
|
|
|
|
- return False
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def get_files(directory, patterns, exclude_patterns):
|
|
|
|
- files = []
|
|
|
|
- for filename in os.listdir(directory):
|
|
|
|
- if file_matches(filename, patterns):
|
|
|
|
- if not file_matches(filename, exclude_patterns):
|
|
|
|
- files.append(filename)
|
|
|
|
- return files
|
|
|
|
|
|
+def std_img_name(name):
|
|
|
|
+ return "gi_{}.jpg".format(name)
|
|
|
|
|
|
|
|
|
|
-def remove_module_name(string, module):
|
|
|
|
- string = string.replace(module.replace('wxGUI.', 'g.gui.'), '')
|
|
|
|
- string = string.replace(module.replace('.', '_'), '') # using _
|
|
|
|
- string = string.replace(module.replace('.', ''), '') # using nothing
|
|
|
|
- string = string.replace(module, '') # using original dots
|
|
|
|
- return string
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def title_from_names(module_name, img_name):
|
|
|
|
- # we ignore the possibility of having extension at the end of image
|
|
|
|
- # so possibly r.out.png fails but image name should use _ anyway
|
|
|
|
- # strictly speaking, it could be also, e.g., index name
|
|
|
|
- for extension in img_extensions:
|
|
|
|
- img_name = img_name.replace('.' + extension, '')
|
|
|
|
- img_name = remove_module_name(img_name, module_name)
|
|
|
|
- img_name = img_name.replace('_', ' ')
|
|
|
|
- img_name = img_name.strip()
|
|
|
|
- if img_name:
|
|
|
|
- return "{name} ({desc})".format(name=module_name, desc=img_name)
|
|
|
|
- else:
|
|
|
|
- return "{name}".format(name=module_name)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def get_module_name(filename):
|
|
|
|
- return filename.replace('.html', '')
|
|
|
|
|
|
+index_items = [
|
|
|
|
+ ('raster_graphical.html', std_img_name('raster'), 'Raster'),
|
|
|
|
+ ('vector_graphical.html', std_img_name('vector'), 'Vector'),
|
|
|
|
+ ('database_graphical.html', std_img_name('database'), 'Database'),
|
|
|
|
+ ('general_graphical.html', std_img_name('general'), 'General'),
|
|
|
|
+ ('display_graphical.html', std_img_name('display'), 'Display'),
|
|
|
|
+ ('imagery_graphical.html', std_img_name('imagery'), 'Imagery'),
|
|
|
|
+ ('raster3d_graphical.html', std_img_name('raster3d'), '3D raster'),
|
|
|
|
+ ('temporal_graphical.html', std_img_name('temporal'), 'Temporal'),
|
|
|
|
+ ('misc_graphical.html', std_img_name('misc'), 'Miscellaneous'),
|
|
|
|
+ ('postscript_graphical.html', std_img_name('cartography'), 'Cartography'),
|
|
|
|
+ ('wxGUI_graphical.html', std_img_name('gui'), 'GUI'),
|
|
|
|
+ ('wxGUI.nviz.html', std_img_name('3dview'), '3D view'),
|
|
|
|
+ ('https://grass.osgeo.org/grass71/manuals/libpython/index.html', std_img_name('python'), 'Python'),
|
|
|
|
+ ('https://grass.osgeo.org/programming7/', std_img_name('c'), 'C library'),
|
|
|
|
+ ('manual_gallery.html', std_img_name('gallery'), 'Gallery'),
|
|
|
|
+]
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
html_dir = sys.argv[1]
|
|
html_dir = sys.argv[1]
|
|
|
|
|
|
- html_files = get_files(html_dir, ['*.html'],
|
|
|
|
- exclude_patterns=[output_name, '*_graphical.html'])
|
|
|
|
- img_html_files = {}
|
|
|
|
-
|
|
|
|
- for filename in os.listdir(html_dir):
|
|
|
|
- if filename in img_blacklist:
|
|
|
|
- continue
|
|
|
|
- if file_matches(filename, img_patterns):
|
|
|
|
- for html_file in html_files:
|
|
|
|
- if img_in_html(os.path.join(html_dir, html_file), filename):
|
|
|
|
- img_html_files[filename] = html_file
|
|
|
|
- # for now suppose one image per html
|
|
|
|
-
|
|
|
|
with open(os.path.join(html_dir, output_name), 'w') as output:
|
|
with open(os.path.join(html_dir, output_name), 'w') as output:
|
|
output.write(header1_tmpl.substitute(title="GRASS GIS %s Reference "
|
|
output.write(header1_tmpl.substitute(title="GRASS GIS %s Reference "
|
|
"Manual: Graphical index" % grass_version))
|
|
"Manual: Graphical index" % grass_version))
|
|
output.write(header_graphical_index_tmpl)
|
|
output.write(header_graphical_index_tmpl)
|
|
output.write('<ul class="img-list">\n')
|
|
output.write('<ul class="img-list">\n')
|
|
- for image, html_file in img_html_files.iteritems():
|
|
|
|
- name = get_module_name(html_file)
|
|
|
|
- title = title_from_names(name, image)
|
|
|
|
|
|
+ for html_file, image, label in index_items:
|
|
output.write(
|
|
output.write(
|
|
'<li>'
|
|
'<li>'
|
|
- '<a href="{html}" title="{title}">'
|
|
|
|
|
|
+ '<a href="{html}">'
|
|
'<img src="{img}">'
|
|
'<img src="{img}">'
|
|
'<span class="name">{name}</span>'
|
|
'<span class="name">{name}</span>'
|
|
'</a>'
|
|
'</a>'
|
|
'</li>\n'
|
|
'</li>\n'
|
|
- .format(html=html_file, img=image, title=title, name=name))
|
|
|
|
|
|
+ .format(html=html_file, img=image, name=label))
|
|
output.write('</ul>')
|
|
output.write('</ul>')
|
|
write_html_footer(output, "index.html", year)
|
|
write_html_footer(output, "index.html", year)
|
|
|
|
|