comparison bitsyblog/cli.py @ 102:bc08a00a7d93

make user creation work again, wip
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 16:50:06 -0800
parents dd4abe56edf7
children
comparison
equal deleted inserted replaced
101:83ec14fca36c 102:bc08a00a7d93
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 """ 3 """
4 command line interface to bitsyblog 4 bitsyblog command line interface for user creation
5 """ 5 """
6 6
7 import optparse 7 import argparse
8 import sys 8 import sys
9 from getpass import getpass
9 from user import FilespaceUsers 10 from user import FilespaceUsers
10 11
11 def main(args=sys.argv[1:]): 12 def main(args=sys.argv[1:]):
12 """command line entry point for user creation"""
13 13
14 # command line parser 14 # command line parser
15 usage = '%prog [options] directory user' 15 parser = argparse.ArgumentParser(description=__doc__)
16 parser = optparse.OptionParser(usage=usage) 16 parser.add_argument('directory', help="base bitsyblog user directory")
17 options, args = parser.parse_args(args) 17 parser.add_argument('user', help="user name")
18 parser.add_argument('-p', '--password', dest='password',
19 help="password for user")
20 options = parser.parse_args(args)
18 21
19 # get user name 22 # read password if not given
20 if len(args) != 2: 23 if not options.password:
21 parser.error("directory, user not specified") 24 password = getpass("Enter password for {} : ".format(options.user))
22 directory, name = args 25 if password:
26 options.password = password
27 else:
28 parser.error("No password given")
23 29
24 # create user 30 # create userspace
25 users = FilespaceUsers(directory) 31 users = FilespaceUsers(options.directory)
32
33 # create a user
34 # TODO: password hashing
26 35
27 if __name__ == '__main__': 36 if __name__ == '__main__':
28 main() 37 main()