Просмотр исходного кода

add first version of script to create keywords page

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55313 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 12 лет назад
Родитель
Сommit
54b3b9601b
2 измененных файлов с 77 добавлено и 1 удалено
  1. 11 1
      man/Makefile
  2. 66 0
      man/build_keywords.py

+ 11 - 1
man/Makefile

@@ -23,7 +23,7 @@ categories = \
 
 IDXCATS := $(foreach cat,$(categories),$(lastword $(subst :, ,$(cat))))
 
-IDXSRC = full_index index topics $(IDXCATS)
+IDXSRC = full_index index topics keywords $(IDXCATS)
 
 INDICES := $(patsubst %,$(HTMLDIR)/%.html,$(IDXSRC))
 
@@ -54,6 +54,12 @@ GISBASE="$(RUN_GISBASE)" ARCH="$(ARCH)" ARCH_DISTDIR="$(ARCH_DISTDIR)" \
 	$(PYTHON) ./build_topics.py $(HTMLDIR)
 endef
 
+define build_keywords
+GISBASE="$(RUN_GISBASE)" ARCH="$(ARCH)" ARCH_DISTDIR="$(ARCH_DISTDIR)" \
+	VERSION_NUMBER=$(GRASS_VERSION_NUMBER) VERSION_DATE=$(GRASS_VERSION_DATE) \
+	$(PYTHON) ./build_keywords.py $(HTMLDIR)
+endef
+
 $(HTMLDIR)/topics.html: $(ALL_HTML)
 	$(call build_topics)
 	touch $@
@@ -66,6 +72,10 @@ $(HTMLDIR)/index.html: build_index.py build_html.py
 	$(call build,index)
 	touch $@
 
+$(HTMLDIR)/keywords.html: $(ALL_HTML)
+	$(call build_keywords)
+	touch $@
+
 define category_rule
 $$(HTMLDIR)/$(2).html: $$(wildcard $$(HTMLDIR)/$(1).*.html) build_class.py build_html.py
 	$$(call build,class,$(1) $(2))

+ 66 - 0
man/build_keywords.py

@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# generates topics.html and topic_*.html
+# (c) 2013 by the GRASS Development Team, Luca Delucchi
+
+import os
+import sys
+import glob
+import string
+from build_html import *
+
+blacklist = ['Display', 'Database', 'General', 'Imagery', 'Misc', 'Postscript',
+             'Raster', 'Raster3D', 'Temporal', 'Vector']
+
+path = sys.argv[1]
+year = os.getenv("VERSION_DATE")
+
+keywords = {}
+
+htmlfiles = glob.glob1(path, '*.html')
+
+for fname in htmlfiles:
+    fil = open(os.path.join(path, fname))
+    # TODO maybe move to Python re (regex)
+    lines=fil.readlines()
+    try:
+        index_keys = lines.index('<h2>KEYWORDS</h2>\n') + 1
+        index_desc = lines.index('<h2>NAME</h2>\n') + 1
+    except:
+        continue
+    try:
+        keys = lines[index_keys].split(',')
+    except:
+        continue
+    for key in keys:
+        key = key.strip().title()
+        if key not in keywords.keys():
+            keywords[key] = []
+            keywords[key].append(fname)
+        elif fname not in keywords[key]:
+            keywords[key].append(fname)
+
+for black in blacklist:
+    try:
+        del keywords[black]
+    except:
+        continue
+
+topicsfile = open(os.path.join(path, 'keywords.html'), 'w')
+topicsfile.write(header1_tmpl.substitute(title = "GRASS GIS " \
+                        "%s Reference Manual: Topics index" % grass_version))
+topicsfile.write(headertopics_tmpl)
+for key, values in sorted(keywords.iteritems()):
+    keyword_line = "<li><b>%s</b>:" % key
+    for value in values:
+        keyword_line += ' <a href="%s">%s</a>,' % (value, value.replace('.html',
+                                                                        ''))
+    keyword_line = keyword_line.rstrip(',')
+    keyword_line += '</li>\n'
+    topicsfile.write(keyword_line)
+
+topicsfile.write("</ul>\n")
+write_html_footer(topicsfile, "index.html", year)  
+topicsfile.close()
+