]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
add some log output
[xonotic/xonstat.git] / xonstat / __init__.py
1 import sqlahelper
2 from pyramid_beaker import set_cache_regions_from_settings
3 from pyramid.config import Configurator
4 from pyramid.httpexceptions import HTTPNotFound
5 from pyramid.renderers import JSONP
6 from sqlalchemy import engine_from_config
7 from xonstat.models import initialize_db
8 from xonstat.views import *
9
10 def main(global_config, **settings):
11     """ This function returns a Pyramid WSGI application.
12     """
13     # setup the database engine
14     engine = engine_from_config(settings, 'sqlalchemy.', pool_size=5)
15     sqlahelper.add_engine(engine)
16
17     # initialize database structures
18     initialize_db(engine)
19
20     # set up beaker cache
21     set_cache_regions_from_settings(settings)
22
23     config = Configurator(settings=settings)
24
25     config.add_renderer('jsonp', JSONP(param_name='callback'))
26
27     # for static assets
28     config.add_static_view('static', 'xonstat:static')
29
30     # for 404s
31     config.add_view(notfound, context=HTTPNotFound, renderer="404.mako")
32
33     # ROOT ROUTE
34     config.add_route("main_index", "/")
35     config.add_view(main_index, route_name="main_index", renderer="main_index.mako")
36
37     # MAIN SUBMISSION ROUTE
38     config.add_route("submit_stats", "stats/submit")
39     config.add_view(submit_stats, route_name="submit_stats")
40
41     # PLAYER ROUTES
42     config.add_route("player_game_index",      "/player/{player_id:\d+}/games")
43     config.add_view(player_game_index,      route_name="player_game_index",      renderer="player_game_index.mako")
44
45     config.add_route("player_game_index_json", "/player/{player_id:\d+}/games.json")
46     config.add_view(player_game_index_json, route_name="player_game_index_json", renderer="jsonp")
47
48     config.add_route("player_hashkey_info_text", "/player/me")
49     config.add_view(player_hashkey_info_text, route_name="player_hashkey_info_text", renderer="player_hashkey_info_text.mako")
50
51     config.add_route("player_info",      "/player/{id:\d+}")
52     config.add_view(player_info,      route_name="player_info",      renderer="player_info.mako")
53
54     config.add_route("player_info_json", "/player/{id:\d+}.json")
55     config.add_view(player_info_json, route_name="player_info_json", renderer="jsonp")
56
57     config.add_route("player_elo_info_text", "/elo/{hashkey}")
58     config.add_view(player_elo_info_text, route_name="player_elo_info_text", renderer="player_elo_info_text.mako")
59
60     config.add_route("player_elo_info_json", "/elo/{hashkey}.json") ## FIXME - doesn't seem to work?
61     config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp")
62
63     config.add_route("player_accuracy",      "/player/{id:\d+}/accuracy")
64     config.add_view(player_accuracy_json, route_name="player_accuracy",      renderer="jsonp")
65
66     config.add_route("player_index",      "/players")
67     config.add_view(player_index,      route_name="player_index",      renderer="player_index.mako")
68
69     config.add_route("player_index_json", "/players.json")
70     config.add_view(player_index_json, route_name="player_index_json", renderer="jsonp")
71
72     config.add_route("player_damage", "/player/{id:\d+}/damage")
73     config.add_view(player_damage_json, route_name="player_damage", renderer="jsonp")
74
75     config.add_route("player_captimes",      "/player/{id:\d+}/captimes")
76     config.add_view(player_captimes,      route_name="player_captimes",      renderer="player_captimes.mako")
77
78     config.add_route("player_captimes_json", "/player/{id:\d+}/captimes.json")
79     config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp")
80
81     # GAME ROUTES
82     config.add_route("game_info",      "/game/{id:\d+}")
83     config.add_view(game_info,      route_name="game_info",      renderer="game_info.mako")
84
85     config.add_route("game_info_json", "/game/{id:\d+}.json")
86     config.add_view(game_info_json, route_name="game_info_json", renderer="jsonp")
87
88     config.add_route("rank_index",      "/ranks/{game_type_cd:ctf|dm|tdm|duel|ca|ft}")
89     config.add_view(rank_index,      route_name="rank_index",      renderer="rank_index.mako")
90
91     config.add_route("rank_index_json", "/ranks/{game_type_cd:ctf|dm|tdm|duel|ca|ft}.json")
92     config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp")
93
94     config.add_route("game_index", "/games")
95     config.add_view(game_finder, route_name="game_index", renderer="game_finder.mako")
96
97     # SERVER ROUTES
98     config.add_route("server_index",      "/servers")
99     config.add_view(server_index,      route_name="server_index",      renderer="server_index.mako")
100
101     config.add_route("server_index_json", "/servers.json")
102     config.add_view(server_index_json, route_name="server_index_json", renderer="jsonp")
103
104     config.add_route("server_game_index",      "/server/{server_id:\d+}/games/page/{page:\d+}")
105     config.add_view(server_game_index,      route_name="server_game_index",      renderer="server_game_index.mako")
106
107     config.add_route("server_game_index_json", "/server/{server_id:\d+}/games.json")
108     config.add_view(server_game_index_json, route_name="server_game_index_json", renderer="jsonp")
109
110     config.add_route("server_info",      "/server/{id:\d+}")
111     config.add_view(server_info,      route_name="server_info",      renderer="server_info.mako")
112
113     config.add_route("server_info_json", "/server/{id:\d+}.json")
114     config.add_view(server_info_json, route_name="server_info_json", renderer="jsonp")
115
116     # MAP ROUTES
117     config.add_route("map_index",      "/maps")
118     config.add_view(map_index,      route_name="map_index",      renderer="map_index.mako")
119
120     config.add_route("map_index_json", "/maps.json")
121     config.add_view(map_index_json, route_name="map_index_json", renderer="jsonp")
122
123     config.add_route("map_info",      "/map/{id:\d+}")
124     config.add_view(map_info,      route_name="map_info",      renderer="map_info.mako")
125
126     config.add_route("map_info_json", "/map/{id:\d+}.json")
127     config.add_view(map_info_json, route_name="map_info_json", renderer="jsonp")
128
129     config.add_route("map_captimes",      "/map/{id:\d+}/captimes")
130     config.add_view(map_captimes,      route_name="map_captimes",      renderer="map_captimes.mako")
131
132     config.add_route("map_captimes_json", "/map/{id:\d+}/captimes.json")
133     config.add_view(map_captimes_json, route_name="map_captimes_json", renderer="jsonp")
134
135     # SEARCH ROUTES
136     config.add_route("search",      "search")
137     config.add_view(search,      route_name="search",      renderer="search.mako")
138
139     config.add_route("search_json", "search.json")
140     config.add_view(search_json, route_name="search_json", renderer="jsonp")
141
142     return config.make_wsgi_app()