changeset 102:bc08a00a7d93

make user creation work again, wip
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 16:50:06 -0800
parents 83ec14fca36c
children 62d4deec4314
files bitsyblog/bitsyblog.py bitsyblog/cli.py bitsyblog/user.py setup.py
diffstat 4 files changed, 30 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Sat Feb 01 13:19:26 2014 -0800
+++ b/bitsyblog/bitsyblog.py	Sun Feb 23 16:50:06 2014 -0800
@@ -29,14 +29,10 @@
 from webob import Request, Response, exc
 
 
-### exceptions
-
 class BlogPathException(Exception):
     """exception when trying to retrieve the blog"""
 
 
-### the main course
-
 class BitsyBlog(object):
     """a very tiny blog"""
 
@@ -846,4 +842,3 @@
 
 
         request.environ['data']['links'] = links
-
--- a/bitsyblog/cli.py	Sat Feb 01 13:19:26 2014 -0800
+++ b/bitsyblog/cli.py	Sun Feb 23 16:50:06 2014 -0800
@@ -1,28 +1,37 @@
 #!/usr/bin/env python
 
 """
-command line interface to bitsyblog
+bitsyblog command line interface for user creation
 """
 
-import optparse
+import argparse
 import sys
+from getpass import getpass
 from user import FilespaceUsers
 
 def main(args=sys.argv[1:]):
-    """command line entry point for user creation"""
 
     # command line parser
-    usage = '%prog [options] directory user'
-    parser = optparse.OptionParser(usage=usage)
-    options, args = parser.parse_args(args)
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('directory', help="base bitsyblog user directory")
+    parser.add_argument('user', help="user name")
+    parser.add_argument('-p', '--password', dest='password',
+                        help="password for user")
+    options = parser.parse_args(args)
 
-    # get user name
-    if len(args) != 2:
-        parser.error("directory, user not specified")
-    directory, name = args
+    # read password if not given
+    if not options.password:
+        password = getpass("Enter password for {} : ".format(options.user))
+        if password:
+            options.password = password
+        else:
+            parser.error("No password given")
 
-    # create user
-    users = FilespaceUsers(directory)
+    # create userspace
+    users = FilespaceUsers(options.directory)
+
+    # create a user
+    # TODO: password hashing
 
 if __name__ == '__main__':
     main()
--- a/bitsyblog/user.py	Sat Feb 01 13:19:26 2014 -0800
+++ b/bitsyblog/user.py	Sun Feb 23 16:50:06 2014 -0800
@@ -1,5 +1,5 @@
 """
-module for bitsyblog users
+bitsyblog users
 """
 
 import os
@@ -24,6 +24,7 @@
     def get(self, key, default=None):
         return self.settings.get(key, default)
 
+
 class BitsyUsers(object):
     """abstract class for bitsyblog user management"""
 
@@ -48,6 +49,7 @@
         return passwords
 
     ### interface methods to be specified by the child class
+
     def new(self, name, password):
         """create a new user"""
 
@@ -105,11 +107,15 @@
                    for i in css_files ]
         return retval
 
+
     ### interfaces for BitsyUsers
 
     def new(self, name, password):
         """create a new user account"""
+
         # XXX this shouldn't use HTTP exceptions
+        # instead, the web handler should listen for exceptions
+        # and it should raise HTTP exceptions
 
         if name in self.users():
             raise exc.HTTPForbidden("The name %s is already taken" % name).exception
@@ -122,6 +128,7 @@
         if name in urls:
             raise exc.HTTPForbidden("The name '%s' is already used for a url"  % user).exception
 
+        # create user directory
         home = self.home(name)
         os.mkdir(home)
         pw_file = file(self.pw_file(name), 'w')
--- a/setup.py	Sat Feb 01 13:19:26 2014 -0800
+++ b/setup.py	Sun Feb 23 16:50:06 2014 -0800
@@ -45,6 +45,7 @@
       # -*- Entry points: -*-
       [console_scripts]
       blog = bitsyblog.blogme:main
+      create-bitsyblog = bitsyblog.cli:main
 
       [paste.app_factory]
       main = bitsyblog.factory:factory