6 commits - demo/demo development.ini moksha/api moksha/lib moksha/templates moksha/tests production/sample-production.ini setup.py
by Luke Macken
demo/demo/widget.py | 2
development.ini | 4 +
moksha/api/widgets/global_resources/widget.py | 6 ++
moksha/lib/helpers.py | 2
moksha/templates/index.mak | 2
moksha/tests/quickstarts/test_tg2.py | 23 ++++++++--
moksha/tests/quickstarts/tg2app/setup.py | 5 +-
moksha/tests/quickstarts/tg2app/tg2app.egg-info/entry_points.txt | 5 +-
production/sample-production.ini | 2
setup.py | 3 +
10 files changed, 42 insertions(+), 12 deletions(-)
New commits:
commit 1d140b2f4727bbc2b90758c00e32bb17a47fda71
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Oct 7 18:46:44 2010 -0400
Disable a unit test that plugs a TG2 app into the moksha.wsgiapp entry-point.
This turns out to cause the plugin to stomp all over Moksha's pylons.config.
It is still possible to plug in any WSGI app into this, but TG2/Pylons apps should
be avoided.
diff --git a/moksha/tests/quickstarts/test_tg2.py b/moksha/tests/quickstarts/test_tg2.py
index 7288b6b..e8939d9 100644
--- a/moksha/tests/quickstarts/test_tg2.py
+++ b/moksha/tests/quickstarts/test_tg2.py
@@ -1,4 +1,5 @@
import os
+import pylons
import pkg_resources
from webtest import TestApp
@@ -34,10 +35,24 @@ class TestTG2AppInMoksha(object):
DBSession.flush()
assert DBSession.query(User).count() == 1
- def test_tg2app_wsgi(self):
- """ Ensure we can get to TG2 when it is mounted as a WSGI app """
- resp = self.app.get('/apps/tg2wsgi/')
- assert 'Now Viewing: index' in resp
+ #def test_tg2app_wsgi(self):
+ # """
+ # Test plugging a TurboGears2/Pylons app into moksha via the
+ # moksha.wsgiapp extension-point.
+
+ # :Note: This is a bad idea, as the the TG2 app will stomp on Moksha's
+ # pylons.config, since Moksha is a TG2 app as well. So, this test
+ # will verify that they don't play well together.
+ # """
+ # # The tg2app will stomp on the pylons.paths and TG will dispatch
+ # # to the plugins RootController, instead of Moksha's
+ # resp = self.app.get('/apps/tg2wsgi/')
+ # assert '[ Moksha ]' in resp
+ # # It's getting to the app
+ # #assert 'Welcome to TurboGears' in resp, resp
+
+ # #import tg2app
+ # #assert pylons.config['package'] == tg2app, pylons.config['package']
class TestTG2App(object):
diff --git a/moksha/tests/quickstarts/tg2app/setup.py b/moksha/tests/quickstarts/tg2app/setup.py
index f1a201e..409fba4 100644
--- a/moksha/tests/quickstarts/tg2app/setup.py
+++ b/moksha/tests/quickstarts/tg2app/setup.py
@@ -49,8 +49,9 @@ setup(
[moksha.application]
tg2app = tg2app.controllers.root:RootController
- [moksha.wsgiapp]
- tg2wsgi = tg2app.wsgi:application
+ # Bad Idea.
+ #[moksha.wsgiapp]
+ #tg2wsgi = tg2app.wsgi:application
""",
)
diff --git a/moksha/tests/quickstarts/tg2app/tg2app.egg-info/entry_points.txt b/moksha/tests/quickstarts/tg2app/tg2app.egg-info/entry_points.txt
index bd4d865..2655973 100644
--- a/moksha/tests/quickstarts/tg2app/tg2app.egg-info/entry_points.txt
+++ b/moksha/tests/quickstarts/tg2app/tg2app.egg-info/entry_points.txt
@@ -8,7 +8,8 @@
[moksha.application]
tg2app = tg2app.controllers.root:RootController
- [moksha.wsgiapp]
- tg2wsgi = tg2app.wsgi:application
+ # Bad Idea.
+ #[moksha.wsgiapp]
+ #tg2wsgi = tg2app.wsgi:application
\ No newline at end of file
commit 0ddd035ee07a9fa243bac2668902610652bdd0c2
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Oct 7 18:45:14 2010 -0400
Have get_moksha_dev_config look in /etc/moksha
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py
index 0257bd2..bd41ed7 100644
--- a/moksha/lib/helpers.py
+++ b/moksha/lib/helpers.py
@@ -793,7 +793,7 @@ def get_moksha_config_path():
# raise MokshaConfigNotFound('Cannot find moksha configuration file!')
def get_moksha_dev_config():
- cfgs = [os.path.join(os.path.abspath(__file__ + '/../../../'), 'development.ini'), os.path.join(os.path.abspath(__file__ + '/../../../../'), 'development.ini'), os.path.join(os.getcwd(), 'development.ini'), '/etc/development.ini']
+ cfgs = [os.path.join(os.path.abspath(__file__ + '/../../../'), 'development.ini'), os.path.join(os.path.abspath(__file__ + '/../../../../'), 'development.ini'), os.path.join(os.getcwd(), 'development.ini'), '/etc/moksha/development.ini']
for cfg in cfgs:
if os.path.isfile(cfg):
return cfg
commit 04de60e98f518af7d30124c09356cb624aa8c216
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Oct 7 18:39:11 2010 -0400
Remove a stray tw.jquery import
diff --git a/moksha/api/widgets/global_resources/widget.py b/moksha/api/widgets/global_resources/widget.py
index 3377f3b..c518849 100644
--- a/moksha/api/widgets/global_resources/widget.py
+++ b/moksha/api/widgets/global_resources/widget.py
@@ -19,7 +19,6 @@ import pkg_resources
from tg import config, url
from tw.api import Widget, CSSLink, JSLink
-from tw.jquery import jquery_js
from paste.deploy.converters import asbool
from pylons import request
from inspect import isclass
commit 34ef9e14d1376f710a858665574c820c0b0f5b41
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Oct 7 18:36:47 2010 -0400
Put the Live Socket on the global entry-point by default, and make it
configurable with the `mokska.livesocket` option.
diff --git a/development.ini b/development.ini
index 5e4b959..21e350d 100644
--- a/development.ini
+++ b/development.ini
@@ -79,6 +79,10 @@ app_db = sqlite:///%s.db
## Moksha Live Socket configuration
##
+# Automatically inject the Moksha live socket with
+# the Global Resource Injection Widget
+moksha.livesocket = True
+
# The backing protocol for live widgets.
# Available backends: stomp, amqp
moksha.livesocket.backend = stomp
diff --git a/moksha/api/widgets/global_resources/widget.py b/moksha/api/widgets/global_resources/widget.py
index 0fb9417..3377f3b 100644
--- a/moksha/api/widgets/global_resources/widget.py
+++ b/moksha/api/widgets/global_resources/widget.py
@@ -25,6 +25,7 @@ from pylons import request
from inspect import isclass
from moksha.widgets.moksha_js import moksha_js, moksha_extension_points_js
+from moksha.api.widgets.live import moksha_socket
log = logging.getLogger(__name__)
@@ -80,6 +81,10 @@ class GlobalResourceInjectionWidget(Widget):
log.debug("Skipping duplicate global widget: %s" %
widget_entry.name)
else:
+ if loaded is moksha_socket:
+ if not asbool(config.get('moksha.livesocket', True)):
+ log.debug('Moksha Live Socket disabled in the config')
+ continue
self.children.append(loaded)
else:
raise Exception("Unknown global resource: %s. Should be "
diff --git a/production/sample-production.ini b/production/sample-production.ini
index b9b4b36..7ec92f4 100644
--- a/production/sample-production.ini
+++ b/production/sample-production.ini
@@ -75,6 +75,8 @@ feed_cache = sqlite:////var/lib/moksha/feeds.db
orbited_host = localhost
orbited_port = 9000
+moksha.livesocket = True
+
# The backing protocol for live widgets.
# Available backends: stomp, amqp
moksha.livesocket.backend = stomp
diff --git a/setup.py b/setup.py
index 1ce16a3..673d0a4 100644
--- a/setup.py
+++ b/setup.py
@@ -86,6 +86,9 @@ setup(
code_widget = moksha.widgets.source:code_widget
moksha_socket = moksha.api.widgets.live:moksha_socket
+ [moksha.global]
+ moksha_socket = moksha.api.widgets.live:moksha_socket
+
[paste.global_paster_command]
moksha = moksha.commands.quickstart:MokshaQuickstartCommand
commit 76b3467fec05c769e3299b8759a0efe1097d054a
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Oct 7 18:34:11 2010 -0400
Cosmetic tweak to our demo widget
diff --git a/demo/demo/widget.py b/demo/demo/widget.py
index a954c92..32b9aff 100644
--- a/demo/demo/widget.py
+++ b/demo/demo/widget.py
@@ -2,8 +2,8 @@ from moksha.api.widgets.live import LiveWidget
class HelloWorldWidget(LiveWidget):
topic = "helloworld"
- onmessage = "$('#data').append(json.msg).append('<br/>');"
template = """
<b>Hello World Widget</b>
<div id="data"/>
"""
+ onmessage = "$('#data').append(json.msg).append('<br/>');"
commit 387e8af9690d08298b52f0cb6d625ffd9e004b2c
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon Oct 4 19:08:24 2010 -0400
Don't run any mako filters on the global resource widget in our default index
diff --git a/moksha/templates/index.mak b/moksha/templates/index.mak
index 101f88b..a748c37 100644
--- a/moksha/templates/index.mak
+++ b/moksha/templates/index.mak
@@ -32,7 +32,7 @@
<div id="moksha_dock" style="display:block; padding-top: 10px; height: 30px; bottom:5px; position: absolute;" />
## Inject our global resources
- ${tmpl_context.moksha_global_resources()}
+ ${tmpl_context.moksha_global_resources() | n}
## Setup our right-click contextual menu
## ${tmpl_context.contextual_menu_widget()}
13 years, 8 months
5 commits - docs/main moksha/commands
by Luke Macken
docs/main/MessagingScenarios.rst | 5 +++++
moksha/commands/cli.py | 31 ++++++++++++++++++++++++++++---
2 files changed, 33 insertions(+), 3 deletions(-)
New commits:
commit 69a65b68af9e2064d1b718e9823abb1a7debedda
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat Oct 2 00:15:42 2010 -0400
Add our --send parser option
diff --git a/moksha/commands/cli.py b/moksha/commands/cli.py
index aa152dd..a1ffa56 100644
--- a/moksha/commands/cli.py
+++ b/moksha/commands/cli.py
@@ -132,8 +132,13 @@ def main():
except Exception, e:
print "Caught exception: %s" % str(e)
moksha.stop()
- elif opts.list:
+ elif opts.list or 'list' in args:
moksha.list()
+ elif opts.send or 'send' in args:
+ if len(sys.argv) != 4:
+ log.error('Usage: moksha send <topic> <message>')
+ sys.exit(-1)
+ moksha.send(sys.argv[2], sys.argv[3])
else:
parser.print_help()
commit a4fb173d370f4a05c3e1d527f62f4110f35e11a4
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat Oct 2 00:15:30 2010 -0400
Setup a basic logging config in our cli
diff --git a/moksha/commands/cli.py b/moksha/commands/cli.py
index 30d4091..aa152dd 100644
--- a/moksha/commands/cli.py
+++ b/moksha/commands/cli.py
@@ -117,7 +117,9 @@ def main():
opts, args = parser.parse_args()
moksha = MokshaCLI()
- log.setLevel(logging.INFO)
+ logging.basicConfig(level=logging.INFO, format=
+ '%(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s')
+
stdout = logging.StreamHandler(sys.stdout)
stdout.setFormatter(logging.Formatter('%(message)s'))
log.addHandler(stdout)
commit 130c5ee972366894d6d0699647ba0048d9f17992
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat Oct 2 00:13:41 2010 -0400
Add an initial `moksha send <topic> <message>` command.
This has a few drawbacks. I couldn't figure out how to get the message to
flush properly without calling reactor.run(), so we first schedule a task to
run 0.2 seconds in the future that stops the reactor. This feels dirty and
should eventually be improved. It also spits out fatal connection upon
completion when using the STOMP messaging protocol.
diff --git a/moksha/commands/cli.py b/moksha/commands/cli.py
index 5f859d9..30d4091 100644
--- a/moksha/commands/cli.py
+++ b/moksha/commands/cli.py
@@ -84,6 +84,21 @@ class MokshaCLI(object):
""" Create a new Moksha component """
# If no arguments given, run `paster moksha --help`
+ def send(self, topic, message):
+ """ Send a message to a topic """
+ from moksha.api.hub import MokshaHub, reactor
+ hub = MokshaHub()
+ print "send_message(%s, %s)" % (topic, message)
+ hub.send_message(topic, {'msg': message})
+
+ def stop_reactor():
+ hub.close()
+ reactor.stop()
+
+ reactor.callLater(0.2, stop_reactor)
+ reactor.run()
+
+
def get_parser():
usage = 'usage: %prog [command]'
@@ -92,6 +107,8 @@ def get_parser():
help='Start Moksha')
parser.add_option('', '--list', action='store_true', dest='list',
help='List all installed Moksha components')
+ parser.add_option('', '--send', action='store_true', dest='send',
+ help='Send a message to a given topic. Usage: send <topic> <message>')
return parser
commit 2d9b8e093dd72f34ab171c67eb176a64c821f126
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat Oct 2 00:12:54 2010 -0400
Set the PYTHONPATH to cwd when spawning processes from the cli
diff --git a/moksha/commands/cli.py b/moksha/commands/cli.py
index c18c8bc..5f859d9 100644
--- a/moksha/commands/cli.py
+++ b/moksha/commands/cli.py
@@ -47,7 +47,8 @@ class MokshaCLI(object):
args = args and [process] + list(args) or [process]
print "Running %s %s" % (process, ' '.join(args))
pp = MokshaProcessProtocol(name=process)
- process = reactor.spawnProcess(pp, process, args, **kw)
+ process = reactor.spawnProcess(pp, process, args,
+ env={'PYTHONPATH': os.getcwd()}, **kw)
pids.append(process.pid)
def start(self):
commit c710db7515838adc69a1de6b6c0c07ab0a768e11
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat Oct 2 00:12:48 2010 -0400
Add a See Also block to our Messaging Scenarios doc
diff --git a/docs/main/MessagingScenarios.rst b/docs/main/MessagingScenarios.rst
index 6719906..f33900e 100644
--- a/docs/main/MessagingScenarios.rst
+++ b/docs/main/MessagingScenarios.rst
@@ -27,3 +27,8 @@ Pros:
- Flexibility and power of AMQP queues, exchanges, routing keys, etc.
Cons:
- Relatively new and not 100% complete JavaScript bindings
+
+.. seealso::
+
+ See :doc:`MessageBrokers` for more information on configuring various
+ protocols and brokers with Moksha.
13 years, 8 months
demo/demo demo/MANIFEST.in demo/setup.py
by Luke Macken
demo/MANIFEST.in | 2 ++
demo/demo/consumer.py | 7 +++++++
demo/demo/producer.py | 8 ++++++++
demo/demo/root.py | 12 ++++++++++++
demo/demo/template.mak | 8 ++++++++
demo/demo/widget.py | 9 +++++++++
demo/setup.py | 31 +++++++++++++++++++++++++++++++
7 files changed, 77 insertions(+)
New commits:
commit 90e57260092911d6897160db40d0ca74a017b8c0
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat Oct 2 00:12:05 2010 -0400
Add the beginnings of our simple Hello World demo
diff --git a/demo/MANIFEST.in b/demo/MANIFEST.in
new file mode 100644
index 0000000..2d52b69
--- /dev/null
+++ b/demo/MANIFEST.in
@@ -0,0 +1,2 @@
+include *.py
+graft demo
diff --git a/demo/demo/__init__.py b/demo/demo/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/demo/demo/consumer.py b/demo/demo/consumer.py
new file mode 100644
index 0000000..c32fea6
--- /dev/null
+++ b/demo/demo/consumer.py
@@ -0,0 +1,7 @@
+from moksha.api.hub.consumer import Consumer
+
+class HelloWorldConsumer(Consumer):
+ topic = 'helloworld'
+
+ def consume(self, message):
+ self.log.info('Received message: ' + message['body']['msg'])
diff --git a/demo/demo/producer.py b/demo/demo/producer.py
new file mode 100644
index 0000000..bfd44f4
--- /dev/null
+++ b/demo/demo/producer.py
@@ -0,0 +1,8 @@
+from moksha.api.hub.producer import PollingProducer
+from datetime import timedelta
+
+class HelloWorldProducer(PollingProducer):
+ frequency = timedelta(seconds=3)
+
+ def poll(self):
+ self.send_message('helloworld', {'msg': 'Hello World!'})
diff --git a/demo/demo/root.py b/demo/demo/root.py
new file mode 100644
index 0000000..3574b84
--- /dev/null
+++ b/demo/demo/root.py
@@ -0,0 +1,12 @@
+from tg import expose
+
+class Root(object):
+
+ @expose()
+ def index(self, *args, **kwargs):
+ return 'Hello World!'
+
+ @expose('mako:demo.template')
+ def mako(self, *args, **kwargs):
+ """ An example controller method exposed with a Mako template """
+ return {'msg': 'Hello World!'}
diff --git a/demo/demo/template.mak b/demo/demo/template.mak
new file mode 100644
index 0000000..2010e44
--- /dev/null
+++ b/demo/demo/template.mak
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>${msg}</title>
+ </head>
+ <body>
+ ${msg}
+ </body>
+</html>
diff --git a/demo/demo/widget.py b/demo/demo/widget.py
new file mode 100644
index 0000000..a954c92
--- /dev/null
+++ b/demo/demo/widget.py
@@ -0,0 +1,9 @@
+from moksha.api.widgets.live import LiveWidget
+
+class HelloWorldWidget(LiveWidget):
+ topic = "helloworld"
+ onmessage = "$('#data').append(json.msg).append('<br/>');"
+ template = """
+ <b>Hello World Widget</b>
+ <div id="data"/>
+ """
diff --git a/demo/setup.py b/demo/setup.py
new file mode 100644
index 0000000..8cc041e
--- /dev/null
+++ b/demo/setup.py
@@ -0,0 +1,31 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='moksha.demo',
+ version='0.1',
+ description='A Hello World Moksha app',
+ author='Luke Macken',
+ author_email='lmacken(a)redhat.com',
+ url='http://moksha.fedorahosted.org',
+ license='GPLv3+',
+ install_requires=['Moksha'],
+ packages=find_packages(),
+ include_package_data=True,
+ test_suite='nose.collector',
+
+ entry_points="""
+
+ [moksha.root]
+ root = demo.root:Root
+
+ [moksha.producer]
+ helloworld = demo.producer:HelloWorldProducer
+
+ [moksha.consumer]
+ helloworld = demo.consumer:HelloWorldConsumer
+
+ [moksha.widget]
+ helloworld = demo.widget:HelloWorldWidget
+
+ """
+)
13 years, 8 months