Skip to content
This repository
tree: 7b01b7e6a5
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 75 lines (62 sloc) 2.371 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
import gevent.monkey ; gevent.monkey.patch_all()
import os
import sys
import logging
try:
    import argparse
except ImportError:
    #TODO add argparse to setup.py for pre 2.7
    print "Couldn't import argparse. Use Python 2.7"


from harness import EPUHarness
from exceptions import HarnessException

log = logging.getLogger(__name__)

ERROR_RETURN = 1

def main(argv=None):


    if not argv:
        argv = list(sys.argv)
    command = argv.pop(0)

    parser = argparse.ArgumentParser("Start EPU Services Locally")
    parser.add_argument('-f', '--force', action='store_true')
    parser.add_argument('-c', '--config', metavar='CONFIG_FILE', default=None)
    parser.add_argument('-x', '--exchange', metavar='EXCHANGE_NAME',
            default=None)
    parser.add_argument('action', metavar='ACTION', help='start or stop')
    parser.add_argument('extras', help='deployment config file for start, or services to stop',
            default=[], nargs='*')
    args = parser.parse_args(argv)

    epuharness = EPUHarness(exchange=args.exchange, config=args.config)

    action = args.action.lower()
    if action == 'start':
        configs = args.extras
        if len(configs) > 0:
            config = configs[0]
            if (config.endswith('.yaml') or config.endswith('.yml')
                or config.endswith('.json')):
                deployment_file = config
            else:
                print >>sys.stderr, "Your configuration file isn't recognized. I expect a json or yaml config file"
                sys.exit(ERROR_RETURN)
        else:
            deployment_file = None

        try:
            epuharness.start(deployment_file)
        except HarnessException, e:
            log.error("Problem starting services: %s" % e.message)
            sys.exit(ERROR_RETURN)
    elif action == 'stop':
        services = getattr(args, 'extras')
        force = args.force
        try:
            epuharness.stop(force=force, services=services)
        except HarnessException, e:
            log.error("Problem stopping services: %s" % e.message)
            sys.exit(ERROR_RETURN)
    elif action == 'status':
        try:
            epuharness.status()
        except HarnessException, e:
            log.error("Problem getting status: %s" % e.message)
            sys.exit(ERROR_RETURN)
    else:
        usage()
        sys.exit(ERROR_RETURN)

Something went wrong with that request. Please try again.