view bitsyblog/cli.py @ 133:ce478807848e default tip

py3
author Jeff Hammel <k0scist@gmail.com>
date Mon, 28 Dec 2020 21:18:19 +0000
parents bc08a00a7d93
children
line wrap: on
line source

#!/usr/bin/env python

"""
bitsyblog command line interface for user creation
"""

import argparse
import sys
from getpass import getpass
from user import FilespaceUsers

def main(args=sys.argv[1:]):

    # command line parser
    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)

    # 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 userspace
    users = FilespaceUsers(options.directory)

    # create a user
    # TODO: password hashing

if __name__ == '__main__':
    main()