changeset 106:c7495fb71045 tip

more output
author Jeff Hammel <>
date Thu, 21 Apr 2016 15:17:39 -0700
parents 67e01fc5e360
files bitsyblog/
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/
+++ b/bitsyblog/
@@ -1,20 +1,25 @@
-"""blog interfaces to data for bitsy"""
+blog models
+# imports
 import datetime
 import os
+import sys
 import utils
 from cStringIO import StringIO
 from glob import glob
 from pkg_resources import iter_entry_points
 class BlogEntry(object):
     """interface class for a blog entry"""
     def __init__(self, date, body, privacy, user, modified=None): = date
         self.body = body
         self.privacy = privacy
         self._modified = modified
         if user is not None:
             self.user = user
@@ -65,17 +70,17 @@ class Blog(object):
     def latest(self, users, number):
         """return the lastest entries"""
         blog = []
         for user in users:
             blog.extend(, ('public',), number))
         blog.sort(key=lambda entry:, reverse=True)
         return blog[:number]
-    # interfaces for subclasses
+    ### interfaces for subclasses
     def blog(self, user, permissions, number=None):
         return the user's blog sorted in reverse date order
         if number is None, the entire blog is returned
     def entry(self, user, datestamp, permissions):
@@ -90,34 +95,41 @@ class Blog(object):
     def post(self, user, date, text, privacy):
         """post a new blog entry"""
         return BlogEntry(date, text, privacy, user)
     def delete(self, user, datestamp):
         """remove a blog entry"""
 class FileBlog(Blog):
     """a blog that lives on the filesystem"""
     def __init__(self, directory): = directory
     def location(self, user, permission, *path):
         """returns which directory files are in based on permission"""
         return os.path.join(, user, 'entries', permission, *path)
     def body(self, user, datestamp, permission):
         return file(self.location(user, permission, datestamp)).read()
     def get_entry(self, user, datestamp, permission):
         modified = datetime.datetime.fromtimestamp(os.path.getmtime(self.location(user, permission, datestamp)))
-        return BlogEntry(,
-                         self.body(user, datestamp, permission),
-                         permission, user, modified=modified)
+        try:
+            return BlogEntry(,
+                             self.body(user, datestamp, permission),
+                             permission,
+                             user,
+                             modified=modified)
+        except Exception:
+            sys.stderr.write("Error getting blog entry for datestamp: '{0}'\n".format(datestamp))
+            raise
     ### interfaces from Blog
     def blog(self, user, permissions, number=None):
         entries = []
         for permission in permissions:
             entries.extend([(entry, permission)
                              for entry in os.listdir(self.location(user, permission)) ])