def main():
    """
        %prog [-c] filename username
        %prog -b[c] filename username password
        %prog -D filename username
    """
    # For now, we only care about the use cases that affect tests/functional.py
    parser = optparse.OptionParser(usage=main.__doc__)
    parser.add_option('-b', action='store_true', dest='batch', default=False,
        help='Batch mode; password is passed on the command line IN THE CLEAR.'
        )
    parser.add_option('-c', action='store_true', dest='create', default=False,
        help='Create a new htpasswd file, overwriting any existing file.')
    parser.add_option('-D', action='store_true', dest='delete_user',
        default=False, help='Remove the given user from the password file.')

    if len(sys.argv) <= 1:
        parser.print_help()
        sys.exit(1)

    options, args = parser.parse_args()

    def syntax_error(msg):
        """Utility function for displaying fatal error messages with usage
        help.
        """
        printerr("Syntax error: " + msg, newline=True)
        printerr(parser.format_help(), newline=True)
        sys.exit(1)

    # Non-option arguments
    if len(args) < 2:
        syntax_error("Insufficient number of arguments.\n")
    filename, username = args[:2]
    password = None
    if options.delete_user:
        if len(args) != 2:
            syntax_error("Incorrect number of arguments.\n")
    else:
        if len(args) == 3 and options.batch:
            password = args[2]
        elif len(args) == 2 and not options.batch:
            first = getpass.getpass("New password:")
            second = getpass.getpass("Re-type new password:")
            if first == second:
                password = first
            else:
                printout("htpasswd: password verification error")
                return
        else:
            syntax_error("Incorrect number of arguments.\n")

    try:
        passwdfile = HtpasswdFile(filename, create=options.create)
    except __HOLE__:
        syntax_error("File not found.\n")
    else:
        if options.delete_user:
            passwdfile.delete(username)
        else:
            passwdfile.update(username, password)
        passwdfile.save()
dataset/ETHPy150Open edgewall/trac/contrib/htpasswd.py/main