comparison piecrust/data/debug.py @ 219:d7a548ebcd58

serve: Add server sent events for showing pipeline errors in the debug window. The server can now run an endpoint that streams pipeline status, including errors or "fixed" statuses. As a result, I had to investigate using event-loop based server alternatives, before I figured out the correct flag to set in Werkzeug. Support for Gunicorn is therefore now possible, although disabled by default. I will come in handy though when proper support for CMS-mode is enabled.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 02 Feb 2015 08:34:44 -0800
parents 0445a2232de7
children bd56d9acd6ef
comparison
equal deleted inserted replaced
218:10f24c62b05b 219:d7a548ebcd58
12 12
13 css_id_re = re.compile(r'[^\w\d\-]+') 13 css_id_re = re.compile(r'[^\w\d\-]+')
14 14
15 15
16 # CSS for the debug window. 16 # CSS for the debug window.
17 CSS_DEBUGINFO = """ 17 CSS_DEBUGWINDOW = """
18 text-align: left; 18 text-align: left;
19 font-family: serif;
19 font-style: normal; 20 font-style: normal;
20 padding: 1em; 21 font-weight: normal;
21 background: #a42;
22 color: #fff;
23 position: fixed; 22 position: fixed;
24 width: 50%; 23 width: 50%;
25 bottom: 0; 24 bottom: 0;
26 right: 0; 25 right: 0;
27 overflow: auto; 26 overflow: auto;
28 max-height: 50%; 27 max-height: 50%;
29 box-shadow: 0 0 10px #633; 28 box-shadow: 0 0 10px #633;
29 """
30
31 CSS_PIPELINESTATUS = """
32 background: #fff;
33 color: #a22;
34 """
35
36 CSS_DEBUGINFO = """
37 padding: 1em;
38 background: #a42;
39 color: #fff;
30 """ 40 """
31 41
32 # HTML elements. 42 # HTML elements.
33 CSS_P = 'margin: 0; padding: 0;' 43 CSS_P = 'margin: 0; padding: 0;'
34 CSS_A = 'color: #fff; text-decoration: none;' 44 CSS_A = 'color: #fff; text-decoration: none;'
60 70
61 71
62 def _do_build_debug_info(page, data, output): 72 def _do_build_debug_info(page, data, output):
63 app = page.app 73 app = page.app
64 74
65 print('<div id="piecrust-debug-info" style="%s">' % CSS_DEBUGINFO, file=output) 75 print('<div id="piecrust-debug-info" style="%s">' % CSS_DEBUGWINDOW,
66 76 file=output)
67 print('<div>', file=output) 77
68 print('<p style="%s"><strong>PieCrust %s</strong> &mdash; ' % (CSS_P, APP_VERSION), file=output) 78 print('<div id="piecrust-debug-info-pipeline-status" style="%s">' %
79 CSS_PIPELINESTATUS, file=output)
80 print('</div>', file=output)
81
82 print('<div style="%s">' % CSS_DEBUGINFO, file=output)
83 print('<p style="%s"><strong>PieCrust %s</strong> &mdash; ' %
84 (CSS_P, APP_VERSION), file=output)
69 85
70 # If we have some execution info in the environment, 86 # If we have some execution info in the environment,
71 # add more information. 87 # add more information.
72 if page.flags & FLAG_RAW_CACHE_VALID: 88 if page.flags & FLAG_RAW_CACHE_VALID:
73 output.write('baked this morning') 89 output.write('baked this morning')
90 106
91 print('</p>', file=output) 107 print('</p>', file=output)
92 print('</div>', file=output) 108 print('</div>', file=output)
93 109
94 if data: 110 if data:
95 print('<div>', file=output) 111 print('<div style="%s padding-top: 0;">' % CSS_DEBUGINFO, file=output)
96 print(('<p style="%s cursor: pointer;" onclick="var l = ' 112 print(('<p style="%s cursor: pointer;" onclick="var l = '
97 'document.getElementById(\'piecrust-debug-details\'); ' 113 'document.getElementById(\'piecrust-debug-details\'); '
98 'if (l.style.display == \'none\') l.style.display = ' 114 'if (l.style.display == \'none\') l.style.display = '
99 '\'block\'; else l.style.display = \'none\';">' % CSS_P), file=output) 115 '\'block\'; else l.style.display = \'none\';">' % CSS_P), file=output)
100 print(('<span style="%s">Template engine data</span> ' 116 print(('<span style="%s">Template engine data</span> '
119 135
120 print('</div>', file=output) 136 print('</div>', file=output)
121 print('</div>', file=output) 137 print('</div>', file=output)
122 138
123 print('</div>', file=output) 139 print('</div>', file=output)
140
141 print('<script src="/__piecrust_static/piecrust-debug-info.js"></script>',
142 file=output)
124 143
125 144
126 class DebugDataRenderer(object): 145 class DebugDataRenderer(object):
127 MAX_VALUE_LENGTH = 150 146 MAX_VALUE_LENGTH = 150
128 147