Commits

John Mulligan  committed 8aabed9

add skeleton files

  • Participants

Comments (0)

Files changed (5)

+\.py[co]$
+\.swp$

File muyhomepage2/__init__.py

Empty file added.

File muyhomepage2/metadata.py

+#!/usr/bin/env python
+#
+# Copyright 2009 John Mulligan <phlogistonjohn@asynchrono.us>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2, incorporated herein by reference.
+#
+"""metadata functions
+"""
+
+
+def writepagecache(data, fp):
+    pass
+
+
+def readpagecache(fp):
+    pass
+
+
+def writetagcache(data, fp):
+    pass
+
+def readtagcache(fp):
+    pass

File muyhomepage2/page.py

+#!/usr/bin/env python
+#
+# Copyright 2009 John Mulligan <phlogistonjohn@asynchrono.us>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2, incorporated herein by reference.
+#
+"""page data
+"""
+
+import os
+import email.parser
+
+
+def parse(name):
+    """Parses a page file and returns a Page object.
+    """
+    fp = open(name)
+    try:
+        message = email.parser.Parser().parse(fp)
+    finally:
+        fp.close()
+    headers = dict([(k.lower(), v) for k, v in message.items()])
+    return Page(name, headers, message.get_payload())
+
+
+def walkpages(root, suffix='.page'):
+    """Generates a series of page filenames from the given root directory.
+    """
+    for dname, dirs, files in os.walk(root):
+        for fn in files:
+            if fn.endswith(suffix):
+                yield os.path.join(dname, fn)
+
+
+class Page(object):
+    """A page object.
+    """
+    def __init__(self, filename, headers=None, body=None):
+        self.filename = filename
+        self.headers = headers
+        self.body = body
+
+    @property
+    def title(self):
+        return self.headers.get('title')

File muyhomepage2/util.py

+#!/usr/bin/env python
+#
+# Copyright 2009 John Mulligan <phlogistonjohn@asynchrono.us>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2, incorporated herein by reference.
+#
+"""utility functions
+"""
+
+import string
+
+
+def encodetitle(title):
+    """Create a simplified title string.
+    """
+    permitted = string.letters + string.digits + ':'
+    temp = []
+    for ch in title.lower():
+        if ch in permitted:
+            temp.append(ch)
+        elif temp[-1] == '-':
+            pass
+        else:
+            temp.append('-')
+    # elminate leading and trailing dashes
+    while temp[0] == '-':
+        temp = temp[1:]
+    while temp[-1] == '-':
+        temp = temp[:-1]
+    return ''.join(temp)