#!/usr/bin/env python

"""
QonoS API Server
"""

import gettext
import os
import sys

# If ../glance/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
    os.pardir,
    os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'qonos', '__init__.py')):
    sys.path.insert(0, possible_topdir)

gettext.install('qonos', unicode=1)

from qonos.api import api
from qonos.common import config
from qonos.openstack.common import log


def fail(returncode, e):
    sys.stderr.write("ERROR: %s\n" % e)
    sys.exit(returncode)

if __name__ == '__main__':
    try:
        config.parse_args()
        log.setup('qonos')
        app = api.API(config.load_paste_app())
        app.run()
    except RuntimeError, e:
        fail(1, e)
