webmcp
annotate framework/env/trace/_render_sub_tree.lua @ 28:ea2e8f3a2776
allow webmcp path to be set in cgi script
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sun Sep 19 01:36:08 2010 +0200 (2010-09-19) |
parents | 9fdfb27f8e67 |
children | 0b7e87f2dc91 |
rev | line source |
---|---|
jbe/bsw@0 | 1 local function open(class) |
jbe/bsw@0 | 2 slot.put('<li class="trace_' .. class .. '">') |
jbe/bsw@0 | 3 end |
jbe/bsw@0 | 4 local function open_head() |
jbe/bsw@0 | 5 slot.put('<div class="trace_head">') |
jbe/bsw@0 | 6 end |
jbe/bsw@0 | 7 local function close_head() |
jbe/bsw@0 | 8 slot.put('</div>') |
jbe/bsw@0 | 9 end |
jbe/bsw@0 | 10 local function close() |
jbe/bsw@0 | 11 slot.put('</li>') |
jbe/bsw@0 | 12 end |
jbe/bsw@0 | 13 function trace._render_sub_tree(node) |
jbe/bsw@0 | 14 local function render_children(tail) |
jbe/bsw@0 | 15 if #node > 0 then |
jbe/bsw@0 | 16 slot.put('<ul class="trace_list">') |
jbe/bsw@0 | 17 for idx, child in ipairs(node) do |
jbe/bsw@0 | 18 trace._render_sub_tree(child) |
jbe/bsw@0 | 19 end |
jbe/bsw@0 | 20 if tail then |
jbe/bsw@0 | 21 slot.put(tail) |
jbe/bsw@0 | 22 end |
jbe/bsw@0 | 23 slot.put("</ul>") |
jbe/bsw@0 | 24 end |
jbe/bsw@0 | 25 end |
jbe/bsw@0 | 26 local function close_with_children() |
jbe/bsw@0 | 27 close_head() |
jbe/bsw@0 | 28 render_children() |
jbe/bsw@0 | 29 close() |
jbe/bsw@0 | 30 end |
jbe/bsw@0 | 31 local node_type = node.type |
jbe/bsw@0 | 32 if node_type == "root" then |
jbe/bsw@0 | 33 render_children() |
jbe/bsw@0 | 34 elseif node_type == "debug" then |
jbe/bsw@0 | 35 open("debug") |
jbe/bsw@0 | 36 slot.put(encode.html(node.message)) |
jbe/bsw@0 | 37 close() |
jbe/bsw@0 | 38 elseif node_type == "request" then |
jbe/bsw@0 | 39 open("request") |
jbe/bsw@0 | 40 open_head() |
jbe/bsw@0 | 41 slot.put("REQUESTED") |
jbe/bsw@0 | 42 if node.view then |
jbe/bsw@0 | 43 slot.put(" VIEW") |
jbe/bsw@0 | 44 elseif node.action then |
jbe/bsw@0 | 45 slot.put(" ACTION") |
jbe/bsw@0 | 46 end |
jbe/bsw@0 | 47 slot.put( |
jbe/bsw@0 | 48 ": ", |
jbe/bsw@0 | 49 encode.html(node.module), |
jbe/bsw@0 | 50 "/", |
jbe/bsw@0 | 51 encode.html(node.view or node.action) |
jbe/bsw@0 | 52 ) |
jbe/bsw@0 | 53 close_with_children() |
jbe/bsw@0 | 54 elseif node_type == "config" then |
jbe/bsw@0 | 55 open("config") |
jbe/bsw@0 | 56 open_head() |
jbe/bsw@0 | 57 slot.put('Configuration "', encode.html(node.name), '"') |
jbe/bsw@0 | 58 close_with_children() |
jbe/bsw@0 | 59 elseif node_type == "filter" then |
jbe/bsw@0 | 60 open("filter") |
jbe/bsw@0 | 61 open_head() |
jbe/bsw@0 | 62 slot.put(encode.html(node.path)) |
jbe/bsw@0 | 63 close_with_children() |
jbe/bsw@0 | 64 elseif node_type == "view" then |
jbe/bsw@0 | 65 open("view") |
jbe/bsw@0 | 66 open_head() |
jbe/bsw@0 | 67 slot.put( |
jbe/bsw@0 | 68 "EXECUTE VIEW: ", |
jbe/bsw@0 | 69 encode.html(node.module), |
jbe/bsw@0 | 70 "/", |
jbe/bsw@0 | 71 encode.html(node.view) |
jbe/bsw@0 | 72 ) |
jbe/bsw@0 | 73 close_with_children() |
jbe/bsw@0 | 74 elseif node_type == "action" then |
jbe/bsw@0 | 75 if |
jbe/bsw@0 | 76 node.status and ( |
jbe/bsw@0 | 77 node.status == "ok" or |
jbe/bsw@0 | 78 string.find(node.status, "^ok_") |
jbe/bsw@0 | 79 ) |
jbe/bsw@0 | 80 then |
jbe/bsw@0 | 81 open("action_success") |
jbe/bsw@0 | 82 elseif |
jbe/bsw@0 | 83 node.status and ( |
jbe/bsw@0 | 84 node.status == "error" or |
jbe/bsw@0 | 85 string.find(node.status, "^error_") |
jbe/bsw@0 | 86 ) |
jbe/bsw@0 | 87 then |
jbe/bsw@0 | 88 open("action_softfail") |
jbe/bsw@0 | 89 else |
jbe/bsw@0 | 90 open("action_neutral") |
jbe/bsw@0 | 91 end |
jbe/bsw@0 | 92 open_head() |
jbe/bsw@0 | 93 slot.put( |
jbe/bsw@0 | 94 "EXECUTE ACTION: ", |
jbe/bsw@0 | 95 encode.html(node.module), |
jbe/bsw@0 | 96 "/", |
jbe/bsw@0 | 97 encode.html(node.action) |
jbe/bsw@0 | 98 ) |
jbe/bsw@0 | 99 close_head() |
jbe/bsw@0 | 100 if node.status == "softfail" then |
jbe/bsw@0 | 101 render_children( |
jbe/bsw@0 | 102 '<li class="trace_action_status">Status code: "' .. |
jbe/bsw@0 | 103 encode.html(node.failure_code) .. |
jbe/bsw@0 | 104 '"</li>' |
jbe/bsw@0 | 105 ) |
jbe/bsw@0 | 106 else |
jbe/bsw@0 | 107 render_children() |
jbe/bsw@0 | 108 end |
jbe/bsw@0 | 109 close() |
jbe/bsw@0 | 110 elseif node_type == "redirect" then |
jbe/bsw@0 | 111 open("redirect") |
jbe/bsw@0 | 112 open_head() |
jbe/bsw@0 | 113 slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) |
jbe/bsw@0 | 114 close_with_children() |
jbe/bsw@0 | 115 elseif node_type == "forward" then |
jbe/bsw@0 | 116 open("forward") |
jbe/bsw@0 | 117 open_head() |
jbe/bsw@0 | 118 slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) |
jbe/bsw@0 | 119 close_with_children() |
jbe/bsw@0 | 120 elseif node_type == "exectime" then |
jbe/bsw@0 | 121 open("exectime") |
jbe/bsw@0 | 122 open_head() |
jbe/bsw@0 | 123 slot.put( |
jbe/bsw@0 | 124 "Finished after " .. |
jbe/bsw@0 | 125 string.format("%.1f", os.monotonic_hires_time() * 1000) .. |
jbe/bsw@0 | 126 ' ms (' .. |
jbe/bsw@0 | 127 string.format("%.1f", os.clock() * 1000) .. |
jbe/bsw@0 | 128 ' ms CPU)' |
jbe/bsw@0 | 129 ) |
jbe/bsw@0 | 130 close_with_children() |
jbe/bsw@0 | 131 elseif node_type == "sql" then |
jbe/bsw@0 | 132 open("sql") |
jbe/bsw@0 | 133 if node.error_position then |
jbe/bsw@0 | 134 -- error position starts counting with 1 |
jbe/bsw@0 | 135 local part1 = string.sub(node.command, 1, node.error_position - 1) |
jbe/bsw@0 | 136 --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1) |
jbe/bsw@0 | 137 local part2 = string.sub(node.command, node.error_position) |
jbe/bsw@0 | 138 slot.put(encode.html(part1)) |
jbe/bsw@0 | 139 slot.put('<span class="trace_error_position">⇒</span>') |
jbe/bsw@0 | 140 slot.put(encode.html(part2)) |
jbe/bsw@0 | 141 --slot.put('</span>') |
jbe/bsw@0 | 142 --slot.put(encode.html(part3)) |
jbe/bsw@0 | 143 else |
jbe/bsw@0 | 144 slot.put(encode.html(node.command)) |
jbe/bsw@0 | 145 end |
jbe/bsw@0 | 146 close(); |
jbe/bsw@0 | 147 elseif node_type == "error" then |
jbe/bsw@0 | 148 open("error") |
jbe/bsw@0 | 149 open_head() |
jbe/bsw@0 | 150 slot.put("UNEXPECTED ERROR") |
jbe/bsw@0 | 151 close_head() |
jbe/bsw@0 | 152 close() |
jbe/bsw@0 | 153 end |
jbe/bsw@0 | 154 end |