#!/usr/bin/env python

from __future__ import with_statement
import ConfigParser
import sys
import base64
from rctl.rctl import write_password

def usage():
    """
    Prints the script's usage guide.
    """
    print "Adds the encoded password to the appropriate host section of the"
    print "environments.ini file."
    print "Usage: (inifile) hostname password"

def main(argv=None):
    if argv is None:
        argv = sys.argv
    if len(argv) == 3:
        write_password('environments.ini', argv[1], argv[2])
    elif len(argv) == 4:
        write_password(argv[1], argv[2], argv[3])
    else:
        usage()


if __name__ == "__main__":
    sys.exit(main())