[Kimchi-devel] [PATCH 2/2] Build help index page only once

Crístian Viana vianac at linux.vnet.ibm.com
Fri Mar 7 20:46:20 UTC 2014


The help index page (ui/pages/help/index.html) is being built once for
every .dita file available. I.e. if there are 10 .dita files, 10 .html
files are generated and index.html is generated 10 times.

Improve the Makefile target so it generates the help index page only once
whenever one of the .dita file changes. The build Python script has also been
updated so its input and output are more flexible, making it easier to handle
from the Makefile.

Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
---
 ui/pages/help/Makefile.am  |  4 +++-
 ui/pages/help/gen-index.py | 20 ++++++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/ui/pages/help/Makefile.am b/ui/pages/help/Makefile.am
index 97011f4..719f603 100644
--- a/ui/pages/help/Makefile.am
+++ b/ui/pages/help/Makefile.am
@@ -24,8 +24,10 @@ dist_help_DATA = $(HTML_FILES) $(NULL)
 
 EXTRA_DIST = $(wildcard *.dita)
 
+index.html: $(wildcard *.dita)
+	$(shell pwd)/gen-index.py $^ > $@
+
 %.html: %.dita $(DITA_XSL_FILE)
 	xsltproc -o $@ $(DITA_XSL_FILE) $<
-	$(shell pwd)/gen-index.py
 
 CLEANFILES = $(HTML_FILES)
diff --git a/ui/pages/help/gen-index.py b/ui/pages/help/gen-index.py
index e62b608..56cbf47 100755
--- a/ui/pages/help/gen-index.py
+++ b/ui/pages/help/gen-index.py
@@ -20,6 +20,7 @@
 
 import glob
 import libxml2
+import sys
 
 
 HTML_HEAD = """
@@ -38,9 +39,13 @@ HTML_TAIL = """
 
 
 def main():
+    if len(sys.argv) < 2:
+        sys.exit("Missing input files")
+
+    input_files = sys.argv[1:]
+
     pages = {}
-    files = sorted(glob.glob('*.dita'))
-    for f in files:
+    for f in sorted(input_files):
         with open(f) as fd:
             xml = fd.read()
             doc = libxml2.parseDoc(xml)
@@ -49,12 +54,11 @@ def main():
             pages[f.replace('.dita', '.html')] = name
             doc.freeDoc()
 
-    with open('index.html', 'w') as fd:
-        fd.write(HTML_HEAD)
-        for page, name in pages.iteritems():
-            html = '  <a href="/help/%s">%s</a><br />\n'
-            fd.write(html % (page, name))
-        fd.write(HTML_TAIL)
+    print HTML_HEAD
+    for page, name in pages.iteritems():
+        html = '  <a href="/help/%s">%s</a><br />\n'
+        print html % (page, name)
+    print HTML_TAIL
 
 
 if __name__ == '__main__':
-- 
1.8.5.3




More information about the Kimchi-devel mailing list