1. Luke Plant
  2. lukeplant_python

Commits

Luke Plant  committed 16aa275

Implemented 'TracWikiWriter' backend and writer mechanism

  • Participants
  • Parent commits 5a9bbb6
  • Branches default

Comments (0)

Files changed (5)

File bibleverses/config.py

View file
 import os
 from readers import TracWikiReader, FileReader
+from writers import TracWikiWriter
 
 OUTPUTHTMLDIR = "/home/luke/httpd/lukeplant.me.uk/src/bible"
 
 datareader = TracWikiReader(DATABASE)
 # - To get data from file system
 #datareader = FileReader(YAMLDIR)
+
+datawriters = {'wiki': TracWikiWriter(DATABASE, AUTHOR)}

File bibleverses/readers.py

View file
         return data
     return get_page
 
-
 def FileReader(dirname):
     """Returns a reader that will retrieve data from files in the
     sepcified directory"""

File bibleverses/update.py

View file
 
 from parse import get_verses, get_topic_entries, populate_topic_tree, get_topictree, get_schemes
 from build import build_schemes
-from writers import write_page
+from config import datawriters
 from StringIO import StringIO
 
 from config import VERSESPAGENAME, TOPICSPAGENAME, SCHEMESPAGENAME, SCHEMESPAGENAMEPREFIX
 
+def write_page(name, data):
+    datawriters['wiki'](name, data)
+
 def write_pages():
     verses = get_verses()
     topictree = get_topictree()

File bibleverses/writers.py

View file
-#!/usr/bin/env python
-
-from config import DATABASE, AUTHOR
 import time
 import sqlite3
 
+# Defines factory functions for returning writers that can write
+# data to different backends
 
-def write_page(name, data, add_new_version=False):
-    c = sqlite3.connect(DATABASE)
-    latest_version = c.execute("SELECT MAX(version) FROM wiki WHERE name = ?;", [name]).fetchone()[0]
-    if latest_version is None:
-        c.execute("INSERT INTO wiki (name, version, time, author, ipnr, text, comment, readonly) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
-                  [name, 1, int(time.time()), AUTHOR, '127.0.0.1', data, '', 0])
-    else:
-        if not add_new_version:
+def TracWikiWriter(dbname, author):
+    """Returns a writer that can write to the given trac database, and uses
+    the supplied 'author' if it has to create new pages."""
+    def write_page(name, data):
+        c = sqlite3.connect(dbname)
+        latest_version = c.execute("SELECT MAX(version) FROM wiki WHERE name = ?;", [name]).fetchone()[0]
+        if latest_version is None:
+            c.execute("INSERT INTO wiki (name, version, time, author, ipnr, text, comment, readonly) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+                      [name, 1, int(time.time()), author, '127.0.0.1', data, '', 0])
+        else:
             c.execute("UPDATE wiki SET text = ? WHERE version = ? AND name = ?", [data, latest_version, name])
-        else:
-            raise NotImplementedError("Haven't implemented 'add_new_version=True' yet.")
-    c.commit()
-    c.close()
-    
+        c.commit()
+        c.close()
+    return write_page

File bibleverses/yaml/BibleMemorisationSchemeYaml

View file
 ---
 name: General 1
 description: 
-  X Foundational scheme, containing verses on a large range 
+  Foundational scheme, containing verses on a large range 
   of subjects, including the basic Christian doctrines
   of God's nature and the gospel, and how to live the
   Christian life.