<commit_before># denyhosts sync server
# Copyright (C) 2015 <NAME> <<EMAIL>>

# 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/>.

import argparse
import logging
import signal
import sys
import ConfigParser

from twisted.web import server, resource, static
from twisted.enterprise import adbapi
from twisted.internet import task, reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python import log

from twistar.registry import Registry

import views
import debug_views
import models
import controllers
import config
import database
import stats

import __init__

def stop_reactor(value):
    print(value)
    reactor.stop()

def sighup_handler(signum, frame):
    global configfile
    global main_xmlrpc_handler

    logging.warning("Received SIGHUP, reloading configuration file...")
    debug_was_on = config.enable_debug_methods
    old_xmlrpc_listen_port = config.xmlrpc_listen_port
    old_stats_listen_port = config.stats_listen_port
    config.read_config(configfile)

    configure_logging()
    schedule_jobs()

    if debug_was_on and not config.enable_debug_methods:
        # Remove debug methods
        # Missing API in class XMLRPC
        del main_xmlrpc_handler.subHandlers["debug"]

    if config.enable_debug_methods and not debug_was_on:
        d = debug_views.DebugServer(main_xmlrpc_handler)
        main_xmlrpc_handler.putSubHandler('debug', d)

    stop_listening().addCallback(lambda _: start_listening())

_xmlrpc_listener = None
_stats_listener = None
# Returns a callback. Wait on it before the port(s) are actually closed
def stop_listening():
    logging.debug("main.stop_listening()")
    global _xmlrpc_listener
    global _stats_listener

    # It's not easy to actually close a listening port.
    # You need to close both the port and the protocol,
    # and wait for them
    if _xmlrpc_listener is not None:
        deferred = _xmlrpc_listener.stopListening()
        deferred.addCallback(_xmlrpc_listener.loseConnection)
    else:
        deferred = Deferred()

    if _stats_listener is not None:
        deferred.addCallback(_stats_listener.stopListening)
        deferred.addCallback(_stats_listener.loseConnection)

    _xmlrpc_listener = None
    _stats_listener = None

    return deferred

def start_listening():
    logging.debug("main.start_listening()")
    global _xmlrpc_listener
    global _stats_listener

    # Configure web resources
    main_xmlrpc_handler = views.Server()
    stats_resource = views.WebResource()
    web_static = static.File(config.static_dir)
    web_graphs = static.File(config.graph_dir)
<commit_msg>Add explicit content type for svg files, not all systems have this<commit_after># denyhosts sync server
# Copyright (C) 2015 <NAME> <<EMAIL>>

# 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/>.

import argparse
import logging
import signal
import sys
import ConfigParser

from twisted.web import server, resource, static
from twisted.enterprise import adbapi
from twisted.internet import task, reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python import log

from twistar.registry import Registry

import views
import debug_views
import models
import controllers
import config
import database
import stats

import __init__

def stop_reactor(value):
    print(value)
    reactor.stop()

def sighup_handler(signum, frame):
    global configfile
    global main_xmlrpc_handler

    logging.warning("Received SIGHUP, reloading configuration file...")
    debug_was_on = config.enable_debug_methods
    old_xmlrpc_listen_port = config.xmlrpc_listen_port
    old_stats_listen_port = config.stats_listen_port
    config.read_config(configfile)

    configure_logging()
    schedule_jobs()

    if debug_was_on and not config.enable_debug_methods:
        # Remove debug methods
        # Missing API in class XMLRPC
        del main_xmlrpc_handler.subHandlers["debug"]

    if config.enable_debug_methods and not debug_was_on:
        d = debug_views.DebugServer(main_xmlrpc_handler)
        main_xmlrpc_handler.putSubHandler('debug', d)

    stop_listening().addCallback(lambda _: start_listening())

_xmlrpc_listener = None
_stats_listener = None
# Returns a callback. Wait on it before the port(s) are actually closed
def stop_listening():
    logging.debug("main.stop_listening()")
    global _xmlrpc_listener
    global _stats_listener

    # It's not easy to actually close a listening port.
    # You need to close both the port and the protocol,
    # and wait for them
    if _xmlrpc_listener is not None:
        deferred = _xmlrpc_listener.stopListening()
        deferred.addCallback(_xmlrpc_listener.loseConnection)
    else:
        deferred = Deferred()

    if _stats_listener is not None:
        deferred.addCallback(_stats_listener.stopListening)
        deferred.addCallback(_stats_listener.loseConnection)

    _xmlrpc_listener = None
    _stats_listener = None

    return deferred

def start_listening():
    logging.debug("main.start_listening()")
    global _xmlrpc_listener
    global _stats_listener

    # Configure web resources
    main_xmlrpc_handler = views.Server()
    stats_resource = views.WebResource()
    web_static = static.File(config.static_dir)
    static.File.contentTypes['.svg'] = 'image/svg+xml'
    web_graphs = static.File(config.graph_dir)

{'fraction_non_alphanumeric': 0.062232415902140674, 'fraction_numerical': 0.0015290519877675841, 'mean_word_length': 4.098207326578332, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 29}, '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': '6304752', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1791, 'n_words': 621}