jflow_server.py 2.05 KB
Newer Older
1
#
Penom Nom's avatar
Penom Nom committed
2
# Copyright (C) 2015 INRA
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import cherrypy
Penom Nom's avatar
Penom Nom committed
19 20
import cgi
import tempfile
21 22
import json
import sys
Penom Nom's avatar
Penom Nom committed
23
import datetime
24 25
from functools import wraps
import time
26
import os
27
import argparse
28 29 30 31 32 33

try:
    import _preamble
except ImportError:
    sys.exc_clear()

Penom Nom's avatar
Penom Nom committed
34
from jflow.server import JFlowServer
35

36

Penom Nom's avatar
Penom Nom committed
37
WEB_DIR = os.path.abspath(os.path.join(__file__, "../../docs"))
38

Penom Nom's avatar
Penom Nom committed
39
class AppServer( JFlowServer ):
40
    
41
    @cherrypy.expose
Penom Nom's avatar
Penom Nom committed
42 43
    def index(self):
        raise cherrypy.HTTPRedirect("/app/index.html")
Penom Nom's avatar
Penom Nom committed
44

45

46
if __name__ == '__main__':
Penom Nom's avatar
Penom Nom committed
47

48 49 50
    parser = argparse.ArgumentParser()
    parser.add_argument("--daemon", action="store_true", dest="daemon", default=False, help="Run the server as daemon")
    args = vars(parser.parse_args())
Penom Nom's avatar
Penom Nom committed
51

Penom Nom's avatar
Penom Nom committed
52 53
    app_conf = {
        '/': 
54
            {'tools.staticdir.root': WEB_DIR, 'tools.CORS.on': True},
Penom Nom's avatar
Penom Nom committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68
        os.path.join('/', 'css'): 
            {'tools.staticdir.on'  : True, 'tools.staticdir.dir' : './css/'},
        os.path.join('/', 'js'): 
            {'tools.staticdir.on'  : True, 'tools.staticdir.dir' : './js/'},
        os.path.join('/', 'img'): 
            {'tools.staticdir.on'  : True, 'tools.staticdir.dir' : './img/'},
        os.path.join('/', 'fonts'): 
            {'tools.staticdir.on'  : True, 'tools.staticdir.dir' : './fonts/'},
        os.path.join('/', 'app'): 
            {'tools.staticdir.on'  : True, 'tools.staticdir.dir' : './'}
    }
    
    JFlowServer.quickstart(AppServer, app_conf, daemon=args["daemon"])