changeset 94:fa221a2d24d9

wow; old + crufty
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 24 Apr 2013 09:07:15 -0700
parents 5c04cf601aba
children dd4abe56edf7
files bitsyblog/bitsyblog.py bitsyblog/cli.py bitsyblog/user.py
diffstat 3 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py
+++ b/bitsyblog/bitsyblog.py
@@ -794,17 +794,17 @@ class BitsyBlog(object):
         data['users'] = [ i for i in list(self.users.users()) 
                           if i != user ]
         data['message'] = message
         data['errors'] = errors or {}
 
         # render the template
         template = self.loader.load('preferences.html')
         return template.generate(**data).render()
-            
+
 
 class BitsierBlog(BitsyBlog):
     """single user version of bitsyblog"""
 
     defaults = BitsyBlog.defaults.copy()
     defaults['user'] = None
 
     def __init__(self, kw, handler_args):
new file mode 100644
--- /dev/null
+++ b/bitsyblog/cli.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+"""
+command line interface to bitsyblog
+"""
--- a/bitsyblog/user.py
+++ b/bitsyblog/user.py
@@ -2,17 +2,17 @@ import os
 import random
 import settings
 import shutil
 from roles import roles
 from webob import exc
 
 class BitsyUser(object):
     """interface class for a bitsyblog user"""
-    settings = {} 
+    settings = {}
     def __init__(self, name, password=''):
         self.name = name
         self.password = password
 
     # user behaves like a dictionary of settings
 
     def __getitem__(self, key):
         return self.settings[key]
@@ -34,17 +34,17 @@ class BitsyUsers(object):
             raise KeyError
         user = BitsyUser(user, self.password(user))
         user.settings = self.settings(user.name)
         return user
 
     def passwords(self):
         """returns a dictionary of { user: password }"""
         passwords = {}
-        for user in self.users():            
+        for user in self.users():
             passwords[user] = self.password(user)
         return passwords
 
     ### interface methods to be specified by the child class
     def new(self, name, password):
         """create a new user"""
 
     def users(self):
@@ -119,23 +119,23 @@ class FilespaceUsers(BitsyUsers):
             raise exc.HTTPForbidden("The name '%s' is already used for a url"  % user).exception
 
         home = self.home(name)
         os.mkdir(home)
         pw_file = file(self.pw_file(name), 'w')
         print >> pw_file, password
 
         # setup entries structure for blog
-        entries = os.path.join(home, 'entries') 
+        entries = os.path.join(home, 'entries')
         os.mkdir(entries)
         for setting in roles['author']:
             os.mkdir(os.path.join(entries, setting))
 
         # setup user CSS
-        css_dir = os.path.join(home, 'css') 
+        css_dir = os.path.join(home, 'css')
         os.mkdir(css_dir)
         shutil.copyfile(os.path.join(self.directory, 'site.css'),
                         os.path.join(css_dir, 'default.css'))
 
 
     def users(self):
         ignores = set(['.svn'])
         for user in os.listdir(self.directory):
@@ -154,37 +154,36 @@ class FilespaceUsers(BitsyUsers):
 
     def settings(self, name):
         """returns a dictionary of user preferences from a file"""
         filename = self.home(name, 'preferences.txt')
         prefs = {}
         if os.path.exists(filename):
             prefs = file(filename).read().split('\n')
             prefs = [ i for i in prefs if i.strip() ]
-            prefs = [ [ j.strip() for j in i.split(':', 1) ] 
+            prefs = [ [ j.strip() for j in i.split(':', 1) ]
                       for i in prefs if ':' in i]
             prefs = dict(prefs)
 
         # assemble friends from a list
         friends = prefs.get('Friends') # can see secret blog posts
         if friends:
             prefs['Friends'] = friends.split(', ')
         else:
             prefs['Friends'] = []
 
         # CSS files
         prefs['CSS'] = self.css(name, prefs.get('Stylesheet'))
-        
+
         return prefs
 
     def write_settings(self, name, **kw):
         """write user settings to disk"""
-        
+
         # generic stuff; could factor out
-        
         newsettings = {}
         errors = {}
 
         for setting in settings.form:
             if kw.has_key(setting.name):
                 try:
                     setting.set(kw[setting.name])
                     newsettings[setting.name] = setting.value
@@ -197,16 +196,16 @@ class FilespaceUsers(BitsyUsers):
         # this makes the function depend on implemention
         # i don't like this
         new_css = newsettings.pop('CSS file')
         if new_css:
             filename = new_css['filename']
             css_file = file(self.home(name, 'css', filename), 'w')
             print >> css_file, new_css['css']
             newsettings['CSS'] = filename.rsplit('.css', 1)[0]
-                
+
         prefs = self.settings(name)
         prefs.update(newsettings)
 
         # write the preferences to a file
         preferences = file(self.preferences_file(name), 'w')
         for key, value in prefs.items():
             print >> preferences, '%s: %s' % ( key, value )