import getpass
import ftplib
import sys

SCMTHOST = "scmt-int.twc.weather.com"
DEFAULTUSERNAME = "scmt_prov"

def getScmtInfo():
    while 1:
        username = DEFAULTUSERNAME
        password = ""
        print "Please enter the SCMT user name"
        print "(hit enter to use %s)" % username
        print "(hit CTRL-D or CTRL-C to not send the provision report)"
        #get username
        try:
            tmp_username = raw_input("> ")
        except EOFError:
            print "Terminating report"
            sys.exit(1)
        except KeyboardInterrupt:
            print "Terminating report"
            sys.exit(1)
        if tmp_username:
            username = tmp_username
        #get password
        while not password:
            print "Please enter the SCMT password"
            try:
                password = getpass.getpass("> ")
            except EOFError:
                print "Terminating report"
                sys.exit(1)
            except KeyboardInterrupt:
                print "Terminating report"
                sys.exit(1)
        #test FTP connection
        try:
            ftplib.FTP(SCMTHOST).login(username, password)
            print "FTP username/password were correct"
            return (username, password, SCMTHOST)
        except ftplib.error_perm:
            print "*" * 40
            print "FTP username/password were incorrect; try again."
            print "*" * 40


if __name__ == "__main__":
    #command line test for the getScmtInfo() function
    print getScmtInfo()
