Skip to content

Commit 9106345

Browse files
committed
msgflo-python: Initial executable for starting a participant component
1 parent 4e2afd3 commit 9106345

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

bin/msgflo-python

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
import sys, os, importlib
4+
sys.path.append(os.path.abspath(".."))
5+
import msgflo, gevent
6+
import logging
7+
8+
def find_participant_classes(mod):
9+
cls = []
10+
for name in dir(mod):
11+
symbol = getattr(mod, name)
12+
if hasattr(symbol, 'send') and hasattr(symbol, 'process'): # XXX: HACK
13+
cls.append(symbol)
14+
return cls
15+
16+
def load_module_file(filepath):
17+
modulename = os.path.basename(filepath)
18+
modulename = modulename.replace('.py', '')
19+
dirpath = os.path.dirname(filepath)
20+
print dirpath, modulename
21+
sys.path.append(dirpath) # XXX: HACK
22+
module = importlib.import_module(modulename)
23+
return module
24+
25+
def main():
26+
prog, args = sys.argv[0], sys.argv[1:]
27+
try:
28+
modulepath, role = args
29+
except ValueError, e:
30+
sys.stderr.write("Usage: msgflo-python MODULE.py ROLE\n")
31+
return 1
32+
33+
module = load_module_file(modulepath)
34+
classes = find_participant_classes(module)
35+
Participant = classes[0]
36+
37+
participant = Participant(role)
38+
d = participant.definition
39+
waiter = gevent.event.AsyncResult()
40+
engine = msgflo.run(participant, done_cb=waiter.set)
41+
print "%s(%s) running on %s" % (d['role'], d['component'], engine.broker_url)
42+
sys.stdout.flush()
43+
waiter.wait()
44+
45+
if __name__ == '__main__':
46+
logging.basicConfig()
47+
main()

0 commit comments

Comments
 (0)