# Path: util/db.py
# def init_db():
#     db_client = None;
#     try:
#         uri = 'mongodb://'+settings.MONGO_USER+':'+settings.MONGO_PWD+'@'+settings.MONGO_HOST+':'+str(settings.MONGO_PORT)+'/'+settings.MONGO_DB
#         db_client = MongoClient(uri)
#         options.db_client = db_client
#         logging.info("Init db successed")
#     except Exception as e:
#         logging.error("Init db failed",e);
# 
#     return db_client
# 
# Path: util/discover.py
# def init_etcd():
#     etcd_client = None
#     try:
#         etcd_client = etcd.Client(settings.ETCD_HOST,settings.ETCD_PORT)
#         options.etcd_client = etcd_client
#         logging.info("Init etcd successed")
#     except Exception,e:
#         logging.error("Init etcd failed",e)
# 
#     return etcd_client
# 
# Path: util/dockerclient.py
# def init_docker():
#     docker_client = None
#     try:
#         docker_client = docker.Client(base_url=settings.DOCKER_HOST)
#         options.docker_client = docker_client
#         logging.info("Init docker client successed")
#     except Exception,e:
#         logging.error("Init docker client failed",e)
# 
#     return docker_client
# 
# Path: util/rabbitmq.py
# def init_amqp():
#     def handle_error(conn_error):
#             print conn_error.method
#             print conn_error.reply_code
#     conn.on_error = handle_error
#     
#     def handle_disconnect():
#             logging.error("Init amqp failed")
#             options.ioloop.stop()
#     conn.on_disconnect = handle_disconnect
#     conn.connect(on_connect)


import tornado.ioloop
import tornado.web
import tornado.httpserver
import os.path
import settings
from tornado.options import define, options
from tornado import gen
from util.db import init_db
from util.discover import init_etcd
from util.dockerclient import init_docker
from util.rabbitmq import init_amqp
        from views.home import HomeHandler
        from views.service import ServicesHandler,ServiceInfoHandler,ServiceBuildHandler
        from views.login import LoginHandler,SigninHandler,SignupHandler,ForgetHandler
        from views.oauth import GitLabOAuthHandler,GitLabTokenHandler,GitLabRefreshHanlder
        from views.application import ApplicationsHandler,ApplicationInfoHandler,ApplicationRunHandler,ApplicationAccessHandler
        from views.registry import RegistryHandler
#!/usr/bin/env python
# -*- coding: utf-8 -*-

define("port", default=settings.TORNADO_PORT, help="run on the given port", type=int)
define("ioloop",default=None,help="global ioloop instance",type=object)

class Application(tornado.web.Application):
    def __init__(self):
        self.init_service()
        handlers = [
             (r"/", HomeHandler),
             (r"/login",LoginHandler),
             (r"/api/user/signup",SignupHandler),
             (r"/api/user/signin",SigninHandler),
             (r"/api/user/forget",ForgetHandler),
             (r"/api/services",ServicesHandler),
             (r"/api/service/info",ServiceInfoHandler),
             (r"/api/service/build",ServiceBuildHandler),
             (r"/api/applications",ApplicationsHandler),
             (r"/api/application/info",ApplicationInfoHandler),
             (r"/api/application/run",ApplicationRunHandler),
             (r"/api/application/access",ApplicationAccessHandler),

# Path: util/db.py
# def init_db():
#     db_client = None;
#     try:
#         uri = 'mongodb://'+settings.MONGO_USER+':'+settings.MONGO_PWD+'@'+settings.MONGO_HOST+':'+str(settings.MONGO_PORT)+'/'+settings.MONGO_DB
#         db_client = MongoClient(uri)
#         options.db_client = db_client
#         logging.info("Init db successed")
#     except Exception as e:
#         logging.error("Init db failed",e);
# 
#     return db_client
# 
# Path: util/discover.py
# def init_etcd():
#     etcd_client = None
#     try:
#         etcd_client = etcd.Client(settings.ETCD_HOST,settings.ETCD_PORT)
#         options.etcd_client = etcd_client
#         logging.info("Init etcd successed")
#     except Exception,e:
#         logging.error("Init etcd failed",e)
# 
#     return etcd_client
# 
# Path: util/dockerclient.py
# def init_docker():
#     docker_client = None
#     try:
#         docker_client = docker.Client(base_url=settings.DOCKER_HOST)
#         options.docker_client = docker_client
#         logging.info("Init docker client successed")
#     except Exception,e:
#         logging.error("Init docker client failed",e)
# 
#     return docker_client
# 
# Path: util/rabbitmq.py
# def init_amqp():
#     def handle_error(conn_error):
#             print conn_error.method
#             print conn_error.reply_code
#     conn.on_error = handle_error
#     
#     def handle_disconnect():
#             logging.error("Init amqp failed")
#             options.ioloop.stop()
#     conn.on_disconnect = handle_disconnect
#     conn.connect(on_connect)


# Path: manage.py
import tornado.ioloop
import tornado.web
import tornado.httpserver
import os.path
import settings
from tornado.options import define, options
from tornado import gen
from util.db import init_db
from util.discover import init_etcd
from util.dockerclient import init_docker
from util.rabbitmq import init_amqp
        from views.home import HomeHandler
        from views.service import ServicesHandler,ServiceInfoHandler,ServiceBuildHandler
        from views.login import LoginHandler,SigninHandler,SignupHandler,ForgetHandler
        from views.oauth import GitLabOAuthHandler,GitLabTokenHandler,GitLabRefreshHanlder
        from views.application import ApplicationsHandler,ApplicationInfoHandler,ApplicationRunHandler,ApplicationAccessHandler
        from views.registry import RegistryHandler

#!/usr/bin/env python
# -*- coding: utf-8 -*-

define("port", default=settings.TORNADO_PORT, help="run on the given port", type=int)
define("ioloop",default=None,help="global ioloop instance",type=object)

class Application(tornado.web.Application):
    def __init__(self):
        self.init_service()
        handlers = [
             (r"/", HomeHandler),
             (r"/login",LoginHandler),
             (r"/api/user/signup",SignupHandler),
             (r"/api/user/signin",SigninHandler),
             (r"/api/user/forget",ForgetHandler),
             (r"/api/services",ServicesHandler),
             (r"/api/service/info",ServiceInfoHandler),
             (r"/api/service/build",ServiceBuildHandler),
             (r"/api/applications",ApplicationsHandler),
             (r"/api/application/info",ApplicationInfoHandler),
             (r"/api/application/run",ApplicationRunHandler),
             (r"/api/application/access",ApplicationAccessHandler),

             (r"/api/gitlab/oauth",GitLabOAuthHandler),