# Defines factory functions for returning writers that can write
-# data to different backends
+# data to different backends. The writer objects returned are
+# callables that take the page name and the data and write it out.
def TracWikiWriter(dbname, author):
"""Returns a writer that can write to the given trac database, and uses
- """Returns a writer that writes to files in a directory.
+ """A writer that writes to files in a directory.
Filenames are converted to lowercase, and 'BibleMemorisation'
is stripped from the front of names."""
- def write_page(name, data):
- stem = 'BibleMemorisation'
- assert name.startswith(stem)
- name = name[len(stem):].lower() + ".html"
+ # Implemented as a class as 'make_html_filename' is needed
+ def __init__(self, dirname):
+ filenamestem = 'BibleMemorisation'
+ def make_html_filename(pagename):
+ stem = FileWriter.filenamestem
+ assert pagename.startswith(stem)
# we deliberately leave "/" in, allowing for subdirectories.
# This will fail if dirs do not exist already
- with file(os.path.join(dirname, name), "w") as f:
+ return pagename[len(stem):].lower() + ".html"
+ def __call__(self, name, data):
+ filename = self.make_html_filename(name)
+ with file(os.path.join(self.dirname, filename), "w") as f: