<commit_before>#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@authors: <NAME> <EMAIL>
          <NAME>. <EMAIL>

@license:  GNU AFFERO GENERAL PUBLIC LICENSE

Caliope Server is the web server of Caliope's Framework
Copyright (C) 2013 Fundación Correlibre

    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/>.
'''
#system, and standard library
import os
import getopt
import sys
import json

#gevent
from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from gevent import monkey

#flask
from flask import Flask, render_template, send_from_directory
from jinja2 import FileSystemLoader

#Blueprints
from api.views import api
from server_notifications.views import server_notifications
from file_uploader.views import file_uploader

#Apps import
from utils.fileUtils import loadJSONFromFile

#: Gevent to patch all TCP/IP connections
monkey.patch_all()

app = Flask(__name__)
app.secret_key = os.urandom(24)
app.debug = True

app.register_blueprint(api, url_prefix='/api')
app.register_blueprint(server_notifications, url_prefix='/event_from_server')
app.register_blueprint(file_uploader, url_prefix='/upload')


@app.route('/')
def index():
    return send_from_directory(app.config['STATIC_PATH'], 'index.html')
    #return render_template('index.html')


@app.route('/<path:filename>')
def custom_static(filename):
    return send_from_directory(app.config['STATIC_PATH'], filename)


def main(argv):
    configfile = "conf/caliope_server.json"
    try:
        opts, args = getopt.getopt(argv, "hc:", ["help", "config="])
    except getopt.GetoptError:
        print 'caliope_server.py -c <configfile>'
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print 'caliope_server.py -c <configfile>'
            sys.exit()
        elif opt in ("-c", "--config"):
            configfile = arg
    config = loadJSONFromFile(configfile)
    if 'port' in config:
        port = int(config['port'])
    else:
        port = 8000

    if 'static' in config:
        app.config['STATIC_PATH'] = config['static']
    else:
        app.config['STATIC_PATH'] = "."
    if 'formTemplates' in config:
        app.config['FORM_TEMPLATES'] = config['formTemplates']
    else:
        app.config['FORM_TEMPLATES'] = app.config['STATIC_PATH']
    print "=" * 80
    print "listening at port : " + str(port)
    print "static base directory : " + app.config['STATIC_PATH']
    print "forms template directory : " + app.config['FORM_TEMPLATES']
    print "=" * 80

    app.jinja_loader = FileSystemLoader(os.path.join(".",
                                        app.config['STATIC_PATH']))
    http_server = WSGIServer(('', port), app, handler_class=WebSocketHandler)  # @IgnorePep8
    http_server.serve_forever()


if __name__ == '__main__':
    main(sys.argv[1:])<commit_msg>Added run_server method, added debug settings<commit_after>#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@authors: <NAME> <EMAIL>
          <NAME>. ne<EMAIL>

@license:  GNU AFFERO GENERAL PUBLIC LICENSE

Caliope Server is the web server of Caliope's Framework
Copyright (C) 2013 <NAME>

    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/>.
'''
#system, and standard library
import os
import getopt
import sys
import json

#gevent
from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from gevent import monkey


#flask
from flask import Flask, render_template, send_from_directory
from jinja2 import FileSystemLoader

#Blueprints
from api.views import api
from server_notifications.views import server_notifications
from file_uploader.views import file_uploader

#Apps import
from utils.fileUtils import loadJSONFromFile

#: Gevent to patch all TCP/IP connections
monkey.patch_all()

app = Flask(__name__)
app.secret_key = os.urandom(24)
app.debug = True
#To enable use of pydebuger
app.use_debbuger = False
app.use_reloader = False

app.register_blueprint(api, url_prefix='/api')
app.register_blueprint(server_notifications, url_prefix='/event_from_server')
app.register_blueprint(file_uploader, url_prefix='/upload')


@app.route('/')
def index():
    return send_from_directory(app.config['STATIC_PATH'], 'index.html')
    #return render_template('index.html')


@app.route('/<path:filename>')
def custom_static(filename):
    return send_from_directory(app.config['STATIC_PATH'], filename)


def main(argv):
    configfile = "conf/caliope_server.json"
    try:
        opts, args = getopt.getopt(argv, "hc:", ["help", "config="])
    except getopt.GetoptError:
        print 'caliope_server.py -c <configfile>'
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print 'caliope_server.py -c <configfile>'
            sys.exit()
        elif opt in ("-c", "--config"):
            configfile = arg
    config = loadJSONFromFile(configfile)
    if 'port' in config:
        port = int(config['port'])
    else:
        port = 8000

    if 'static' in config:
        app.config['STATIC_PATH'] = config['static']
    else:
        app.config['STATIC_PATH'] = "."
    if 'formTemplates' in config:
        app.config['FORM_TEMPLATES'] = config['formTemplates']
    else:
        app.config['FORM_TEMPLATES'] = app.config['STATIC_PATH']
    print "=" * 80
    print "listening at port : " + str(port)
    print "static base directory : " + app.config['STATIC_PATH']
    print "forms template directory : " + app.config['FORM_TEMPLATES']
    print "=" * 80

    app.jinja_loader = FileSystemLoader(os.path.join(".",
                                        app.config['STATIC_PATH']))
    run_server(port)


def run_server(port):
    http_server = WSGIServer(('', port), app, handler_class=WebSocketHandler)  # @IgnorePep8
    http_server.serve_forever()


if __name__ == '__main__':
    main(sys.argv[1:])
{'fraction_non_alphanumeric': 0.10680851063829787, 'fraction_numerical': 0.005673758865248227, 'mean_word_length': 3.5373230373230373, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4119262', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2094, 'n_words': 651}