#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys, locale
from beaker.middleware import SessionMiddleware
from bottle import Bottle, run

#te amo

from routes.index import index
from routes.static import static
from routes.login import login
#from routes.csv import csv
from routes.plot import plot
from routes.pdf import pdf
from routes.survey import survey
from routes.surveys import surveys
from routes.upload import upload
from routes.properties import properties
from routes.help import help
#from routes.table import table
from routes.readings import readings
from routes.users import users
from routes.register import register
from routes.credentials import credentials
from routes.logout import logout
from routes.errors import errors
from routes.compare import compare
from routes.cloud import cloud
from routes.notice import notice

# ??????
os.environ["LANG"] = "en_US.UTF-8"
os.environ["LANGUAGE"] = "en_US:en"
os.environ["LC_ALL"] = "en_US.UTF-8"
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")

app = Bottle()

for route in (index, static, login, pdf, plot, survey, surveys, upload,
              properties, help, readings, users, register,
              credentials, logout, compare, cloud, notice):
    app.merge(route)

# Errors
# FIXME: This appears to have been deprecated
# app.error_handler = errors

session_opts = {
    "session.type": "file",
    "session.cookie_expires": True,
    "session.data_dir": "./data",
    "session.auto": True,
}
app = SessionMiddleware(app, session_opts)

# CGI only
#run(app=app, server="cgi")

if __name__ == "__main__":
    run(app=app, host="localhost", port=8080, debug=True)
