<commit_before>from configparser import ConfigParser
import os

# Import flask and template operators
from flask import Flask, render_template, request

# Flask Extensions
from flask.ext.compress import Compress
from flask.ext.socketio import SocketIO
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.assets import Environment
from flask.ext.babel import Babel

# Define the WSGI application object
app = Flask(__name__)
app.config["CSRF_ENABLED"] = True
app.config["LANGUAGES"] = {
    "en": "English",
    "de": "Deutsch"
}
app.config["BASE_DIR"] = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(app.config["BASE_DIR"], "data", "app.db")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["THREADS_PER_PAGE"] = 2  # TODO?

# initialize app specific config
CONFIG_PATH = os.path.join(app.config["BASE_DIR"], "data", "config.ini")
config = ConfigParser()
config.read(CONFIG_PATH)

app.config["CSRF_SESSION_KEY"] = config["general"]["csrf_session_key"]
app.config["SECRET_KEY"] = config["general"]["secret_key"]

assets = Environment(app)
# load asset definitions from "static/webassets.yml"
assets.from_yaml(app.root_path + os.sep + "static" + os.sep + "webassets.yml")

# use app/static/compiled as output path for webassets' assets
assets.directory = os.path.abspath(app.root_path + os.sep + "static" + os.sep + "compiled")
assets.url = "/static/compiled"

# use app/static as load path for assets
assets.append_path(app.root_path + os.sep + "static", "static")

db = SQLAlchemy(app)
babel = Babel(app)
Compress(app)

# TODO async_mode, see https://stackoverflow.com/questions/35235797/socketio-emit-doesnt-work-when-interacting-using-popen-on-windows-in-a-thread
socketio = SocketIO(app) # , async_mode="threading"


@babel.localeselector
def get_locale():
    return request.accept_languages.best_match(app.config["LANGUAGES"].keys())


@app.errorhandler(404)
def not_found(error):
    return render_template("errors/404.html"), 404


# Register blueprint(s)
from app.modules.mod_index.controller import mod_index
from app.modules.mod_auth.controller import mod_auth<commit_msg>add loading of fallback config<commit_after>import os
import warnings
from configparser import ConfigParser

# Import flask and template operators
from flask import Flask, render_template, request

# Flask Extensions
from flask.ext.compress import Compress
from flask.ext.socketio import SocketIO
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.assets import Environment
from flask.ext.babel import Babel

# Define the WSGI application object
app = Flask(__name__)
app.config["CSRF_ENABLED"] = True
app.config["LANGUAGES"] = {
    "en": "English",
    "de": "Deutsch"
}
app.config["BASE_DIR"] = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(app.config["BASE_DIR"], "data", "app.db")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["THREADS_PER_PAGE"] = 2  # TODO?

# initialize app specific config
CONFIG_PATH = os.path.join(app.config["BASE_DIR"], "data", "config.ini")
config = ConfigParser()
if os.path.isfile(CONFIG_PATH):
    config.read(CONFIG_PATH)
else:
    warnings.warn("Loading fallback config - %s does not exist!" % CONFIG_PATH, RuntimeWarning)
    config.read_dict({
        "general": {
            "csrf_session_key": "secret",
            "secret_key": "secret",
            "parallel_processes": 1
        },
        "filemanager": {
            "show_resolution": False
        },
        "encoding": {
            "acodec": "aac",
            "strict": "experimental",
            "s": "1280x720",
            "aspect": "1280:720",
            "preset": "slow",
            "crf": 22
        }
    })

app.config["CSRF_SESSION_KEY"] = config["general"]["csrf_session_key"]
app.config["SECRET_KEY"] = config["general"]["secret_key"]

assets = Environment(app)
# load asset definitions from "static/webassets.yml"
assets.from_yaml(app.root_path + os.sep + "static" + os.sep + "webassets.yml")

# use app/static/compiled as output path for webassets' assets
assets.directory = os.path.abspath(app.root_path + os.sep + "static" + os.sep + "compiled")
assets.url = "/static/compiled"

# use app/static as load path for assets
assets.append_path(app.root_path + os.sep + "static", "static")

db = SQLAlchemy(app)
babel = Babel(app)
Compress(app)

# TODO async_mode, see https://stackoverflow.com/questions/35235797/socketio-emit-doesnt-work-when-interacting-using-popen-on-windows-in-a-thread
socketio = SocketIO(app)  # , async_mode="threading"


@babel.localeselector
def get_locale():
    return request.accept_languages.best_match(app.config["LANGUAGES"].keys())


@app.errorhandler(404)
def not_found(error):
    return render_template("errors/404.html"), 404


# Register blueprint(s)
from app.modules.mod_index.controller import mod_index
from app.modules.mod_auth.controller import mod_auth
{'fraction_non_alphanumeric': 0.13963694394574108, 'fraction_numerical': 0.010572511470177539, 'mean_word_length': 4.697727272727272, 'pattern_counts': {'":': 17, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '3548396', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1647, 'n_words': 345}