Commits

Doug Hellmann committed 97ae257 Draft

initialize the database from within the documentation config file

Comments (0)

Files changed (2)

 clean:
 	-rm -rf $(BUILDDIR)/*
 
-html: sampledatabase
+html:
 	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
 	@echo
 	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
 
-.PHONY: sampledatabase
-sampledatabase:
-	rm -f sampledata.db
-	sqlite3 sampledata.db < sampledata.sql
+# .PHONY: sampledatabase
+# sampledatabase:
+# 	rm -f sampledata.db
+# 	sqlite3 sampledata.db < sampledata.sql
 
 dirhtml:
 	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
 # All configuration values have a default; values that are commented out
 # serve to show the default.
 
-import sys, os
+import os
+import sqlite3
+import sys
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 
 # How to display URL addresses: 'footnote', 'no', or 'inline'.
 #texinfo_show_urls = 'footnote'
+
+
+def setup(app):
+    print 'Initializing sample database'
+    if os.path.exists('sampledata.db'):
+        os.unlink('sampledata.db')
+    with sqlite3.connect('sampledata.db') as conn:
+        with open('sampledata.sql', 'rt') as f:
+            schema = f.read()
+        conn.executescript(schema)