Completed
Push — master ( 6d6a7d...e4617d )
by Jasper
8s
created

main()   B

Complexity

Conditions 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 26
rs 8.8571
1
from pyramid.config import Configurator
2
import waitress, os
3
from niprov.dependencies import Dependencies
4
5
6
def serve():
7
    wsgiapp = main(None)
8
    waitress.serve(wsgiapp, host='0.0.0.0', port=6543)
9
10
def main(global_config, **settings):
11
    """ This function returns a Pyramid WSGI application.
12
    """
13
#    settings = {}
14
#    settings['reload_all'] = True
15
#    settings['debug_all'] = True
16
#    settings['mako.directories'] = os.path.join(here, 'templates')
17
    config = Configurator(settings=settings)
18
    config.include('pyramid_mako')
19
    config.add_static_view('static', 'static', cache_max_age=10)
20
    config.add_static_view('snapshots', 
21
        os.path.expanduser('~/.niprov-snapshots'), cache_max_age=10)
22
    config.add_route('home', '/')
23
    config.add_route('latest', '/latest')
24
    config.add_route('stats', '/stats')
25
    config.add_route('short', '/id/{id}')
26
    config.add_route('pipeline', '/id/{id}/pipeline')
27
    config.add_route('location', '/location/{host}*path')
28
    config.add_route('modality', '/modality/{modality}')
29
    config.add_route('subject', '/subject/{subject}')
30
    config.add_route('project', '/project/{project}')
31
    config.add_route('user', '/user/{user}')
32
    config.add_request_method(lambda r: Dependencies(), 
33
        'dependencies', reify=True)
34
    config.scan()
35
    return config.make_wsgi_app()
36
37
"""
38
Documentation:
39
PasteDeploy: http://pythonpaste.org/deploy/
40
(Handles reading config from file and picking server and app settings)
41
Waitress: http://waitress.readthedocs.org/en/latest/
42
(How to start and configure waitress)
43
"""
44