#!/usr/bin/env python
# Copyright (C) 2014 Linaro Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""The Tornado application base module."""

import pymongo
import tornado

from concurrent.futures import ThreadPoolExecutor
from tornado.web import Application

from handlers.app import AppHandler
from urls import APP_URLS


class KernelCiBackend(Application):
    """The Kernel CI backend application.

    Where everything starts.
    """

    mongodb_client = pymongo.MongoClient()

    def __init__(self):

        settings = {
            'client': self.mongodb_client,
            'default_handler_class': AppHandler,
            'executor': ThreadPoolExecutor(max_workers=15),
            'gzip': True,
            'debug': True,
        }

        super(KernelCiBackend, self).__init__(APP_URLS, **settings)


if __name__ == '__main__':
    KernelCiBackend().listen(8888)
    tornado.ioloop.IOLoop.instance().start()

@@ -750,16 +750,26 @@
 le.%22%22%22%0A%0A
+import os%0A
 import p
@@ -841,16 +841,73 @@
 xecutor%0A
+from tornado.options import (%0A    define,%0A    options,%0A)%0A
 from tor
@@ -933,16 +933,39 @@
 lication
+%0Afrom uuid import uuid4
 %0A%0Afrom h
@@ -1022,16 +1022,359 @@
 _URLS%0A%0A%0A
+DEFAULT_CONFIG_FILE = '/etc/linaro/kernelci-backend.cfg'%0A%0Adefine('master_key', default=str(uuid4()), type=str, help=%22The master key%22)%0Adefine(%0A    'max_workers', default=20, type=int,%0A    help=%22The number of workers for the thread pool executor%22%0A)%0Adefine('gzip', default=True)%0Adefine('debug', default=True)%0Adefine('autoreload', default=True)%0A%0A%0A
 class Ke
@@ -1723,10 +1723,27 @@
 ers=
-15
+options.max_workers
 ),%0A 
@@ -1761,20 +1761,28 @@
 'gzip': 
-True
+options.gzip
 ,%0A      
@@ -1796,20 +1796,121 @@
 debug': 
-True
+options.debug,%0A            'master_key': options.master_key,%0A            'autoreload': options.autoreload
 ,%0A      
@@ -2011,16 +2011,163 @@
 ain__':%0A
+    if os.path.isfile(DEFAULT_CONFIG_FILE):%0A        options.parse_config_file(DEFAULT_CONFIG_FILE, final=False)%0A%0A    options.parse_command_line()%0A%0A
     Kern

Add config file and command line options.