# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8

__all__ = ('Server',)

import sys, os
from os import path

BASEDIR = os.environ.get("BASEDIR", None)
if BASEDIR is None:
    SCRIPTDIR = path.abspath(path.split(__file__)[0])
    BASEDIR = path.dirname(path.dirname(SCRIPTDIR))
sys.path.insert(0, path.join(BASEDIR, 'config'))
sys.path.insert(1, path.join(BASEDIR, 'python'))

from nulib.paths import mkdirp
from nulib.web import web, Application
from app import config
from pages import *

class Server(Application):
    # décommenter les lignes suivantes pour activer les sessions
    #def _new_session(self):
    #    sdir = path.join(self.basedir, 'var/sessions')
    #    mkdirp(sdir)
    #    return web.session.DiskStore(sdir), {}

    def before_start(self):
        super(Server, self).before_start()
        config.set_appname(self.NAME)
        config.set_basedir(self.basedir)
        config.set_profile(self.PROFILE)
        #if config.migrate:
        #    from model import data
        #    data.migration.migrate()

if __name__ == '__main__':
    Server(BASEDIR).run(sys.argv[1:])
