[cig-commits] r15751 - doc/geodynamics.org/benchmarks/trunk
luis at geodynamics.org
luis at geodynamics.org
Mon Oct 5 15:39:44 PDT 2009
Author: luis
Date: 2009-10-05 15:39:43 -0700 (Mon, 05 Oct 2009)
New Revision: 15751
Added:
doc/geodynamics.org/benchmarks/trunk/generate.py
Removed:
doc/geodynamics.org/benchmarks/trunk/generate.sh
Modified:
doc/geodynamics.org/benchmarks/trunk/Makefile
Log:
Smarter regeneration of HTML files
Now we check the file modification times of each source .rst file
before attempting to regenerate the corresponding .html file.
Modified: doc/geodynamics.org/benchmarks/trunk/Makefile
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/Makefile 2009-10-05 22:39:37 UTC (rev 15750)
+++ doc/geodynamics.org/benchmarks/trunk/Makefile 2009-10-05 22:39:43 UTC (rev 15751)
@@ -2,7 +2,7 @@
default: gen
gen:
- ./generate.sh
+ ./generate.py
up:
./upload.py
Added: doc/geodynamics.org/benchmarks/trunk/generate.py
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/generate.py (rev 0)
+++ doc/geodynamics.org/benchmarks/trunk/generate.py 2009-10-05 22:39:43 UTC (rev 15751)
@@ -0,0 +1,106 @@
+#!/usr/bin/env python2.6
+#
+# References:
+# /Library/Frameworks/Python.framework/Versions/Current/bin/rst2html.py
+# http://docutils.sf.net/docs/api/publisher.html
+# http://docs.python.org/library/os.path.html#os.path.getmtime
+#
+
+import os
+import docutils.core
+
+
+# -----------------------------------------------------------------------------
+
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+
+# -----------------------------------------------------------------------------
+
+def getrst(filename):
+ """
+ Given an .html filename, return its .rst source filename.
+ """
+ from common import split_path
+ coll, base, ext = split_path(filename)
+ assert ext == '.html'
+
+ rst = '%s.rst' % base
+ if coll:
+ rst = '%s/%s' % (coll, rst)
+
+ return rst
+
+
+def needs_update(filename):
+ """
+ This function decides whether the .html file in question
+ needs to be re-generated from its .rst source.
+ """
+
+ # if file doesn't exist, generate it. duh.
+ if not os.path.exists(filename):
+ return True
+
+ # next, we check the file modification times
+ html_mtime = os.path.getmtime(filename)
+ rst_mtime = os.path.getmtime(getrst(filename))
+
+ # if .rst file is more recent, we need to regenerate the .html file
+ return (rst_mtime > html_mtime)
+
+
+# -----------------------------------------------------------------------------
+
+def regenerate(filename):
+ """
+ Given an .html filename, regenerate it from its .rst source.
+ """
+
+ rst = getrst(filename)
+ assert os.path.exists(rst)
+
+ docutils.core.publish_file(
+ source_path=rst,
+ destination_path=filename,
+ writer_name='html',
+ )
+
+
+def regenerate_all_html_files():
+ """
+ Regenerate .html files from their .rst source.
+ """
+
+ from common import groups, locate
+
+ print "Scanning for files to regenerate..."
+ for group in groups:
+ for filename in locate('.html', root=group):
+ if needs_update(filename):
+ regenerate(filename)
+
+
+def regenerate_from_list():
+ """
+ Regenerate the .html files that are listed in 'upload.txt'.
+ """
+
+ from common import readlines
+
+ print "Scanning for files to regenerate..."
+ for filename in readlines('upload.txt'):
+ if needs_update(filename):
+ regenerate(filename)
+
+
+# -----------------------------------------------------------------------------
+
+def main():
+ regenerate_from_list()
+
+
+if __name__ == '__main__':
+ main()
+
Property changes on: doc/geodynamics.org/benchmarks/trunk/generate.py
___________________________________________________________________
Name: svn:executable
+ *
Deleted: doc/geodynamics.org/benchmarks/trunk/generate.sh
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/generate.sh 2009-10-05 22:39:37 UTC (rev 15750)
+++ doc/geodynamics.org/benchmarks/trunk/generate.sh 2009-10-05 22:39:43 UTC (rev 15751)
@@ -1,9 +0,0 @@
-#!/bin/bash
-rst2html=rst2html.py
-for rst in $(find . | grep '.rst$'); do
- path=$(dirname $rst)
- base=$(basename $rst .rst)
- html="${path}/${base}.html"
- echo "Generating ${html}"
- ${rst2html} ${rst} ${html}
-done
More information about the CIG-COMMITS
mailing list