Browse files

Merge branch 'feature/pygments+json' into develop

  • Loading branch information...
2 parents 69b9d08 + 6b989b1 commit 0272f8c6a164cf5bfa0a4c447c7ddb23346a557f @ralphbean committed Mar 23, 2012
View
31 busmon/consumers.py
@@ -1,12 +1,33 @@
-
+import pygments.lexers
+import pygments.formatters
from moksha.api.hub import Consumer
-class BusmonConsumer(Consumer):
+import fedmsg
+import fedmsg.json
+
+
+class MessageColorizer(Consumer):
app = "busmon" # hopefully this won't be necessary anymore
topic = "*"
+ destination_topic = "colorized-messages"
jsonify = False
- def consumer(self, message):
- # We may not actually need this.
- pass
+ def consume(self, message):
+ if self.destination_topic in message.topic:
+ return
+
+ html_args = {'full': False}
+ code = pygments.highlight(
+ fedmsg.json.pretty_dumps(fedmsg.json.loads(message.body)),
+ pygments.lexers.JavascriptLexer(),
+ pygments.formatters.HtmlFormatter(**html_args)
+ )
+
+ code = code.strip()
+
+ fedmsg.send_message(
+ topic=self.destination_topic,
+ msg=code,
+ validate=False,
+ )
View
2 busmon/controllers/root.py
@@ -11,6 +11,7 @@
from busmon.widgets import (
TopicsBarChart,
MessagesTimeSeries,
+ ColorizedMessagesWidget,
)
__all__ = ['RootController']
@@ -39,6 +40,7 @@ def index(self):
return dict(
barchart=TopicsBarChart,
timeseries=MessagesTimeSeries,
+ colorized_messages=ColorizedMessagesWidget,
)
@expose('busmon.templates.about')
View
59 busmon/public/css/monokai.css
@@ -0,0 +1,59 @@
+.hll { background-color: #49483e }
+.c { color: #75715e } /* Comment */
+.err { color: #960050; background-color: #1e0010 } /* Error */
+.k { color: #66d9ef } /* Keyword */
+.l { color: #ae81ff } /* Literal */
+.n { color: #f8f8f2 } /* Name */
+.o { color: #f92672 } /* Operator */
+.p { color: #f8f8f2 } /* Punctuation */
+.cm { color: #75715e } /* Comment.Multiline */
+.cp { color: #75715e } /* Comment.Preproc */
+.c1 { color: #75715e } /* Comment.Single */
+.cs { color: #75715e } /* Comment.Special */
+.ge { font-style: italic } /* Generic.Emph */
+.gs { font-weight: bold } /* Generic.Strong */
+.kc { color: #66d9ef } /* Keyword.Constant */
+.kd { color: #66d9ef } /* Keyword.Declaration */
+.kn { color: #f92672 } /* Keyword.Namespace */
+.kp { color: #66d9ef } /* Keyword.Pseudo */
+.kr { color: #66d9ef } /* Keyword.Reserved */
+.kt { color: #66d9ef } /* Keyword.Type */
+.ld { color: #e6db74 } /* Literal.Date */
+.m { color: #ae81ff } /* Literal.Number */
+.s { color: #e6db74 } /* Literal.String */
+.na { color: #a6e22e } /* Name.Attribute */
+.nb { color: #f8f8f2 } /* Name.Builtin */
+.nc { color: #a6e22e } /* Name.Class */
+.no { color: #66d9ef } /* Name.Constant */
+.nd { color: #a6e22e } /* Name.Decorator */
+.ni { color: #f8f8f2 } /* Name.Entity */
+.ne { color: #a6e22e } /* Name.Exception */
+.nf { color: #a6e22e } /* Name.Function */
+.nl { color: #f8f8f2 } /* Name.Label */
+.nn { color: #f8f8f2 } /* Name.Namespace */
+.nx { color: #a6e22e } /* Name.Other */
+.py { color: #f8f8f2 } /* Name.Property */
+.nt { color: #f92672 } /* Name.Tag */
+.nv { color: #f8f8f2 } /* Name.Variable */
+.ow { color: #f92672 } /* Operator.Word */
+.w { color: #f8f8f2 } /* Text.Whitespace */
+.mf { color: #ae81ff } /* Literal.Number.Float */
+.mh { color: #ae81ff } /* Literal.Number.Hex */
+.mi { color: #ae81ff } /* Literal.Number.Integer */
+.mo { color: #ae81ff } /* Literal.Number.Oct */
+.sb { color: #e6db74 } /* Literal.String.Backtick */
+.sc { color: #e6db74 } /* Literal.String.Char */
+.sd { color: #e6db74 } /* Literal.String.Doc */
+.s2 { color: #e6db74 } /* Literal.String.Double */
+.se { color: #ae81ff } /* Literal.String.Escape */
+.sh { color: #e6db74 } /* Literal.String.Heredoc */
+.si { color: #e6db74 } /* Literal.String.Interpol */
+.sx { color: #e6db74 } /* Literal.String.Other */
+.sr { color: #e6db74 } /* Literal.String.Regex */
+.s1 { color: #e6db74 } /* Literal.String.Single */
+.ss { color: #e6db74 } /* Literal.String.Symbol */
+.bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
+.vc { color: #f8f8f2 } /* Name.Variable.Class */
+.vg { color: #f8f8f2 } /* Name.Variable.Global */
+.vi { color: #f8f8f2 } /* Name.Variable.Instance */
+.il { color: #ae81ff } /* Literal.Number.Integer.Long */
View
38 busmon/public/css/site.css
@@ -9,6 +9,22 @@ body, p, a, li, div, input, button {
font-size: 12pt;
}
+pre {
+ margin: 0;
+ font-size: 70%;
+}
+div.hll {
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+ border: 1px solid black;
+ -webkit-box-shadow: 2px 2px 2px #333;
+ -moz-box-shadow: 2px 2px 2px #333;
+ box-shadow: 2px 2px 2px #333;
+ padding: 1.0em;
+}
+
+
+
#header h1 span#logo {
background:transparent url("../images/fedora-logo.png") no-repeat scroll 0px 0px;
height: 50px;
@@ -23,7 +39,7 @@ body, p, a, li, div, input, button {
float: left;
overflow: visible;
margin-top: -10px;
- margin-bottom: 20px;
+ margin-bottom: 5px;
}
#header div {
@@ -46,22 +62,36 @@ body, p, a, li, div, input, button {
background-color: #60605b;
}
+.page {
+ width: 979px;
+ margin: 0 auto;
+}
+.pane {
+}
+.left {
+ width: 525px;
+ float: left;
+}
+.right {
+ width: 450px;
+ float: right;
+}
+
.content {
margin-left: auto;
margin-right: auto;
overflow: hidden;
position: relative;
- width: 960px;
background-color:white;
-moz-border-radius: 10px;
border-radius: 10px;
border: 2px solid black;
-webkit-box-shadow: 5px 5px 5px #333;
-moz-box-shadow: 5px 5px 5px #333;
box-shadow: 5px 5px 5px #333;
- padding: 1.6em;
+ padding: 0.8em;
}
.spacer {
- margin: 10px;
+ margin: 4px;
}
View
2 busmon/public/css/text.css
@@ -95,7 +95,7 @@ li {
margin-left:30px
}
-p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset {
+p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,table,address,fieldset {
margin-bottom:20px
}
View
2 busmon/templates/colorized_messages.mak
@@ -0,0 +1,2 @@
+<%namespace name="tw" module="tw2.core.mako_util"/>\
+<div ${tw.attrs(attrs=w.attrs)}></div>
View
26 busmon/templates/index.mak
@@ -1,8 +1,20 @@
<%inherit file="local:templates.master"/>
- <div class="content">
- ${barchart.display() | n}
- </div>
- <div class="clear spacer"></div>
- <div class="content">
- ${timeseries.display() | n}
- </div>
+<div class="page">
+ <div class="left pane">
+ <div class="content">
+ <strong>Messages per Topic</strong>
+ ${barchart.display() | n}
+ </div>
+ <div class="clear spacer"></div>
+ <div class="content">
+ <strong>Total Messages over Time</strong>
+ ${timeseries.display() | n}
+ </div>
+ </div>
+ <div class="right pane">
+ <div class="content">
+ <strong>Last 5 Messages</strong>
+ ${colorized_messages.display() | n}
+ </div>
+ </div>
+</div>
View
28 busmon/widgets.py
@@ -6,7 +6,8 @@
import tw2.core as twc
import tw2.d3
-global_width = 940
+global_width = 485
+
class TopicsBarChart(tw2.d3.BarChart, moksha.api.widgets.live.LiveWidget):
id = 'topics-bar-chart'
@@ -15,9 +16,9 @@ class TopicsBarChart(tw2.d3.BarChart, moksha.api.widgets.live.LiveWidget):
data = collections.OrderedDict() # empty
- padding = [30, 10, 10, 120]
+ padding = [30, 10, 10, global_width/2]
width = global_width
- height = 200
+ height = 225
interval = 2000
def prepare(self):
@@ -29,16 +30,33 @@ def prepare(self):
0.001,
))
+
class MessagesTimeSeries(tw2.d3.TimeSeriesChart,
moksha.api.widgets.live.LiveWidget):
id = 'messages-time-series'
topic = "*"
onmessage = "tw2.store['${id}'].value++"
width = global_width
- height = 200
+ height = 150
# Keep this many data points
- n = 400
+ n = 200
# Initialize to n zeros
data = [0] * n
+
+
+class ColorizedMessagesWidget(moksha.api.widgets.live.LiveWidget):
+ id = 'colorized-messages'
+ template = "mako:busmon.templates.colorized_messages"
+ resources = [twc.CSSLink(link="css/monokai.css")]
+ css_class = "hll"
+
+ topic = 'org.fedoraproject.busmon.colorized-messages'
+ onmessage = """
+ var container = $('#${id}');
+ if ( container.children().size() > 4 ) {
+ container.children().first().remove();
+ }
+ container.append(json.msg);
+ """
View
4 development.ini
@@ -45,8 +45,8 @@ moksha.livesocket.backend = websocket
moksha.livesocket.websocket.port = 9919
zmq_enabled = True
-zmq_publish_endpoints = tcp://*:5432
-zmq_subscribe_endpoints = tcp://127.0.0.1:5432,tcp://127.0.0.1:6543
+zmq_publish_endpoints=tcp://*:4321
+zmq_subscribe_endpoints=tcp://127.0.0.1:6543,tcp://127.0.0.1:5432,tcp://127.0.01:4321
zmq_strict = False
# If you'd like to fine-tune the individual locations of the cache data dirs
View
3 fedmsg.ini
@@ -0,0 +1,3 @@
+[fedmsg]
+# Have fedmsg send to an address where the moksha-hub is listening
+publish_endpoint = tcp://*:6543
View
3 setup.py
@@ -70,11 +70,12 @@
'main = pylons.util:PylonsInstaller',
),
'moksha.consumer': (
- #'wat = busmon.consumers:BusmonConsumer',
+ 'colorizer = busmon.consumers:MessageColorizer',
),
'moksha.widget': (
'topics_bar = busmon.widgets:TopicsBarChart',
'messages_series = busmon.widgets:MessagesTimeSeries',
+ 'colorized_msgs = busmon.widgets:ColorizedMessagesWidget',
),
},
dependency_links=[
View
2 tools/fake-bus.py
@@ -17,7 +17,7 @@
def main():
# Prepare our context and publisher
- fedmsg.init(publish_endpoint="tcp://*:6543")
+ fedmsg.init(publish_endpoint="tcp://*:5432")
# Probabilities of us emitting an event on each topic.
probs = {

0 comments on commit 0272f8c

Please sign in to comment.