<commit_before>#!/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 concurrent.futures
import os
import pymongo
import tornado
import tornado.httpserver
import tornado.netutil
import tornado.options as topt
import tornado.web
import uuid

import handlers.app as happ
import handlers.dbindexes as hdbindexes
import urls


DEFAULT_CONFIG_FILE = "/etc/linaro/kernelci-backend.cfg"

topt.define(
    "master_key", default=str(uuid.uuid4()), type=str, help="The master key")
topt.define(
    "max_workers", default=5, type=int,
    help="The number of workers for the thread pool executor"
)
topt.define("gzip", default=True)
topt.define("debug", default=True)
topt.define("autoreload", default=True)
topt.define(
    "port", default=8888, type=int,
    help="The port number where the server should listen"
)

# mongodb connection parameters.
topt.define(
    "dbhost", default="localhost", type=str, help="The DB host to connect to"
)
topt.define("dbport", default=27017, type=int, help="The DB port to connect to")
topt.define(
    "dbuser", default="", type=str,
    help="The user name to use for the DB connection"
)
topt.define(
    "dbpassword", default="", type=str,
    help="The password to use for the DB connection"
)
topt.define(
    "dbpool", default=250, type=int, help="The DB connections pool size")
topt.define(
    "unixsocket", default=False, type=bool,
    help="If unix socket should be used"
)
topt.define(
    "smtp_host", default="", type=str, help="The SMTP host to connect to")
topt.define("smtp_user", default="", type=str, help="SMTP connection user")
topt.define(
    "smtp_password", default="", type=str, help="SMTP connection password")
topt.define(
    "smtp_port", default=587, type=int,
    help="The SMTP connection port, default to 587")
topt.define(
    "smtp_sender", default="", type=str, help="The sender email address")
topt.define(
    "send_delay", default=60*60+5, type=int,
    help="The delay in sending the report emails, "
         "default to 1 hour and 5 seconds"
)
topt.define(
    "storage_url", default=None, type=str, help="The URL of the storage system")


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

    Where everything starts.
    """
    mongodb_client = None

    def __init__(self):

        db_options = {
            "dbhost": topt.options.dbhost,
            "dbport": topt.options.dbport,
            "dbuser": topt.options.dbuser,
            "dbpassword": topt.options.dbpassword,
            "dbpool": topt.options.dbpool
        }

        mail_options = {
            "host": topt.options.smtp_host,
            "user": topt.options.smtp_user,
            "password": <PASSWORD>.smtp_password,
            "port": topt.options.smtp_port,
            "sender": topt.options.smtp_sender
        }

        if self.mongodb_client is None:
            self.mongodb_client = pymongo.MongoClient(
                host=topt.options.dbhost,
                port=topt.options.dbport,<commit_msg>Add new options: info_email.<commit_after>#!/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 concurrent.futures
import os
import pymongo
import tornado
import tornado.httpserver
import tornado.netutil
import tornado.options as topt
import tornado.web
import uuid

import handlers.app as happ
import handlers.dbindexes as hdbindexes
import urls


DEFAULT_CONFIG_FILE = "/etc/linaro/kernelci-backend.cfg"

topt.define(
    "master_key", default=str(uuid.uuid4()), type=str, help="The master key")
topt.define(
    "max_workers", default=5, type=int,
    help="The number of workers for the thread pool executor"
)
topt.define("gzip", default=True)
topt.define("debug", default=True)
topt.define("autoreload", default=True)
topt.define(
    "port", default=8888, type=int,
    help="The port number where the server should listen"
)

# mongodb connection parameters.
topt.define(
    "dbhost", default="localhost", type=str, help="The DB host to connect to"
)
topt.define("dbport", default=27017, type=int, help="The DB port to connect to")
topt.define(
    "dbuser", default="", type=str,
    help="The user name to use for the DB connection"
)
topt.define(
    "dbpassword", default="", type=str,
    help="The password to use for the DB connection"
)
topt.define(
    "dbpool", default=250, type=int, help="The DB connections pool size")
topt.define(
    "unixsocket", default=False, type=bool,
    help="If unix socket should be used"
)
topt.define(
    "smtp_host", default="", type=str, help="The SMTP host to connect to")
topt.define("smtp_user", default="", type=str, help="SMTP connection user")
topt.define(
    "smtp_password", default="", type=str, help="SMTP connection password")
topt.define(
    "smtp_port", default=587, type=int,
    help="The SMTP connection port, default to 587")
topt.define(
    "smtp_sender", default="", type=str, help="The sender email address")
topt.define(
    "send_delay", default=60*60+5, type=int,
    help="The delay in sending the report emails, "
         "default to 1 hour and 5 seconds"
)
topt.define(
    "info_email", default=None, type=str,
    help="The email address to use for footnote in the email reports")
topt.define(
    "storage_url", default=None, type=str,
    help="The URL of the storage system")


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

    Where everything starts.
    """
    mongodb_client = None

    def __init__(self):

        db_options = {
            "dbhost": topt.options.dbhost,
            "dbport": topt.options.dbport,
            "dbuser": topt.options.dbuser,
            "dbpassword": topt.options.dbpassword,
            "dbpool": topt.options.dbpool
        }

        mail_options = {
            "host": topt.options.smtp_host,
            "user": topt.options.smtp_user,
            "password": <PASSWORD>,
            "port": topt.options.smtp_port,
            "sender": topt.options.smtp_sender,
            "info_email": topt.options.info_email
        }

        if self.mongodb_client is None:
            self.mongodb_client = pymongo.MongoClient(
                host=topt.options.dbhost,
                port=topt.options.dbport,
{'fraction_non_alphanumeric': 0.11359453063371022, 'fraction_numerical': 0.008414409676571128, 'mean_word_length': 3.5660264105642256, 'pattern_counts': {'":': 21, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '598391', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2310, 'n_words': 747}