Mercurial > piecrust2
annotate piecrust/wsgiutil/__init__.py @ 929:cebeedfa034f
serve: Don't start the admin panel SSE until the window is ready.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Oct 2017 09:08:31 -0700 |
parents | b4156f5d4368 |
children | 7ecb946bfafd |
rev | line source |
---|---|
897
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
1 import logging |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
379
diff
changeset
|
2 from piecrust.serving.server import WsgiServer |
379
d40b744a9d99
serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents:
376
diff
changeset
|
3 |
d40b744a9d99
serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents:
376
diff
changeset
|
4 |
897
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
5 def _setup_logging(log_file, log_level, max_log_bytes, log_backup_count): |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
6 if log_file: |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
7 from logging.handlers import RotatingFileHandler |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
8 handler = RotatingFileHandler(log_file, maxBytes=max_log_bytes, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
9 backupCount=log_backup_count) |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
10 handler.setLevel(log_level) |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
11 logging.getLogger().addHandler(handler) |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
12 |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
13 |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
14 def get_app(root_dir, *, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
15 cache_key='prod', |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
16 enable_debug_info=False, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
17 log_file=None, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
18 log_level=logging.INFO, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
19 log_backup_count=0, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
20 max_log_bytes=4096): |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
21 _setup_logging(log_file, log_level, max_log_bytes, log_backup_count) |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
379
diff
changeset
|
22 app = WsgiServer(root_dir, |
666
81d9c3a3a0b5
internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
23 cache_key=cache_key, |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
379
diff
changeset
|
24 enable_debug_info=enable_debug_info) |
379
d40b744a9d99
serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents:
376
diff
changeset
|
25 return app |
d40b744a9d99
serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents:
376
diff
changeset
|
26 |
897
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
27 |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
28 def get_admin_app(root_dir, *, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
29 url_prefix='pc-admin', |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
30 log_file=None, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
31 log_level=logging.INFO, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
32 log_backup_count=0, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
33 max_log_bytes=4096): |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
34 _setup_logging(log_file, log_level, max_log_bytes, log_backup_count) |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
35 es = { |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
36 'FOODTRUCK_ROOT': root_dir, |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
37 'FOODTRUCK_URL_PREFIX': url_prefix} |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
38 from piecrust.admin.web import create_foodtruck_app |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
39 app = create_foodtruck_app(es) |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
40 return app |
b4156f5d4368
wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
41 |