# HG changeset patch # User Jeff Hammel # Date 1393203006 28800 # Node ID bc08a00a7d93aa8b73430b5047c9b1b970c91542 # Parent 83ec14fca36cb406d886ff431816c2d6d658f10c make user creation work again, wip diff -r 83ec14fca36c -r bc08a00a7d93 bitsyblog/bitsyblog.py --- 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 - diff -r 83ec14fca36c -r bc08a00a7d93 bitsyblog/cli.py --- 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() diff -r 83ec14fca36c -r bc08a00a7d93 bitsyblog/user.py --- 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') diff -r 83ec14fca36c -r bc08a00a7d93 setup.py --- 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