#!/usr/bin/env python
'''
This is the main launcher for various IOC related web utilities. 
We use a single gunicorn instance to host multiple scripts.
Each script has its Bottle app and we import these in this launcher and the merge their routes into this launcher's app.
Static files are served from the static folder by this launcher.
 '''

import os
import ujson
import logging
from bottle import route, run, request, abort, Bottle, static_file
from gevent import monkey; monkey.patch_all()
import collections

from iocDetails import app as iocDetailsApp


app = Bottle()
# Merge all routes from client apps into this app.
app.merge(iocDetailsApp)

logger = logging.getLogger("miscIOCWebUtils")
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)



@app.route('/<filename:path>')
def send_html(filename):
    return static_file(filename, root='./static')

if __name__ == "__main__":
    # To start this, use gunicorn -w 4 -b <machine>:<port> launcher:app
    run(app=app, server='miscIOCWebUtils', host='0.0.0.0', port=8080)
