author | Laurent Peuch <cortex@worlddomination.be> |
Tue, 08 Oct 2019 23:11:19 +0200 | |
changeset 12764 | fb97669efcaa |
parent 12761 | 10b8352b0208 |
child 12766 | 682d0790997f |
permissions | -rw-r--r-- |
12755
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
1 |
# copyright 2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
3 |
# |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
5 |
# |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
9 |
# any later version. |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
10 |
# |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
14 |
# details. |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
15 |
# |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
18 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
19 |
from logging import getLogger |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
20 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
21 |
logger = getLogger('cubicweb') |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
22 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
23 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
24 |
SUBSCRIBERS = { |
12764
fb97669efcaa
[debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents:
12761
diff
changeset
|
25 |
"controller": [], |
12755
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
26 |
"rql": [], |
12761
10b8352b0208
[debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents:
12755
diff
changeset
|
27 |
"sql": [], |
12755
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
28 |
} |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
29 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
30 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
31 |
def subscribe_to_debug_channel(channel, subscriber): |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
32 |
if channel not in SUBSCRIBERS.keys(): |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
33 |
raise Exception("debug channel '%s' doesn't exist" % channel) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
34 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
35 |
SUBSCRIBERS[channel].append(subscriber) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
36 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
37 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
38 |
def unsubscribe_to_debug_channel(channel, subscriber): |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
39 |
if channel not in SUBSCRIBERS.keys(): |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
40 |
raise Exception("debug channel '%s' doesn't exist" % channel) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
41 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
42 |
if subscriber not in SUBSCRIBERS[channel]: |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
43 |
raise Exception("subscriber '%s' is not in debug channel '%s'" % (subscriber, channel)) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
44 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
45 |
SUBSCRIBERS[channel].remove(subscriber) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
46 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
47 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
48 |
def emit_to_debug_channel(channel, message): |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
49 |
if channel not in SUBSCRIBERS.keys(): |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
50 |
raise Exception("debug channel '%s' doesn't exist" % channel) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
51 |
|
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
52 |
for subscriber in SUBSCRIBERS[channel]: |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
53 |
try: |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
54 |
subscriber(message) |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
55 |
except Exception: |
7df6c6048bc8
[debug] add a new channel events mechanism for debugging
Laurent Peuch <cortex@worlddomination.be>
parents:
diff
changeset
|
56 |
logger.error("Failed to send debug message '%s' to subscriber '%s'", message, subscriber, exc_info=True) |