#!/usr/bin/ensim-python
#
# Copyright (c) Ensim Corporation 2000, 2001   All Rights Reserved.
#
# This software is furnished under a license and may be used and copied
# only  in  accordance  with  the  terms  of such  license and with the
# inclusion of the above copyright notice. This software or any other
# copies thereof may not be provided or otherwise made available to any
# other person. No title to and ownership of the software is hereby
# transferred.
#
# The information in this software is subject to change without notice
# and  should  not be  construed  as  a commitment by Ensim Corporation.
# Ensim assumes no responsibility for the use or  reliability  of its
# software on equipment which is not supplied by Ensim.
#
#
# This function edits a user of a domain 
#
# Usage:
#
# ChangeInfoVirtUser <domainname> <username> <usersfullname> <usersdiskquota>
#
# Example:
#
# ChangeInfoVirtUser myco.com joe 'Joe User' 20

import getopt
import sys
import traceback
from vh3 import virthost
from vh3.modules import users
import string
import be_vherrordisp

if (len(sys.argv) < 5) or (sys.argv[1] == "--help"): 
    print "usage: ChangeInfoVirtUser <domainname> <username> <usersfullname> <usersdiskquota>"
    sys.exit(0)
else: 
    # checks to see if we are in maintenance mode
    virthost.checkMaintenance()

    status = be_vherrordisp.CLIError.SUCCESS
    status_obj = be_vherrordisp.CLIError()
    options, args = getopt.getopt(sys.argv[1:],"")
    siteindex = virthost.get_site_from_anything(string.lower(args[0]))
    username = string.lower(args[1])
    usersfullname = args[2]
    usersdiskquota = args[3]
    if not siteindex:
        print "Domain %s does not exist on this server."% string.lower(args[0])
        sys.exit(1)
    ret = []
    try:
        virthost.edit_user(ret, siteindex, username, usersfullname, None, usersdiskquota, None)
        status = virthost.cli_display_status_list(ret)
    except:
        status = be_vherrordisp.CLIError.ERROR
        print traceback.print_exc()
    sys.exit(status)
