Source

ec2control / ec2control / main.py

Full commit
import sys
from emailer import ParseMail, Response
from ec2 import Instance, CommandError
from config import Config
import argparse

import logging
log = logging.getLogger(__name__)

from logging.config import fileConfig

def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--config", 
                        type=str, 
                        default="ec2control.ini", 
                        help="Path to config file")
    parser.add_argument("-r", "--read", 
                        type=str, 
                        help="Read email text from file instead of stdin")

    options = parser.parse_args()

    config = Config(options.config)

    fileConfig(options.config)

    if options.read:
        email_data = file(options.read).read()
    else:
        email_data = sys.stdin.read()
    struct = ParseMail(email_data)
    resp = Response(config, struct)
    instance = None
    try:
        if struct.command == "startup":
            if struct.arguments:
                name = struct.arguments[0]
            else:
                name = None
            instance = Instance(config, name)
            instance.start()
            resp.send_started(instance)
        else:
            raise CommandError("Unknown command: '%s'"  % struct.command)
    except CommandError, ce:
        resp.send_command_error(ce, instance)
    except Exception, e:
        log.error("Error occurred", exc_info=True)
        resp.send_error(e, instance)
    print email_data