Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 53 lines (47 sloc) 1.685 kb
182320f package complete, for now
Davis Barber authored
1 #!/usr/bin/python
2 from optparse import OptionParser
8f5b230 @jedahan move swarmtoolscore to its own directory
jedahan authored
3 from lib import swarmtoolscore
b48de82 adds produce.py and consume.py
Andrew Turley authored
4 import sys
5 import httplib
6 import os
d43b87e @barberdt better signal handling for consume.py
barberdt authored
7 import signal
8
9 conn = None
b48de82 adds produce.py and consume.py
Andrew Turley authored
10
182320f package complete, for now
Davis Barber authored
11 def usage(script_name):
12 print "%s [consume] \n"%(script_name)
13 print "Use '%s [method] --help' for a method's usage and options."%(script_name)
b48de82 adds produce.py and consume.py
Andrew Turley authored
14 sys.exit()
15
d43b87e @barberdt better signal handling for consume.py
barberdt authored
16 def signal_handler(signal, frame):
17 global conn
18 conn.close()
19 sys.exit(0)
20
e2b6314 @aturley updates consume.py and produce.py to use the new streaming API.
aturley authored
21 def consume(hostname, api_key, swarm_id, resource_id):
d43b87e @barberdt better signal handling for consume.py
barberdt authored
22 global conn
f874b14 @kgilmer bugswarm-tools: add support for hostname configuration property to
kgilmer authored
23 conn = httplib.HTTPConnection(hostname)
4f1db93 @aturley fixes typo, changing "resouce" to "resource".
aturley authored
24 conn.request("GET", "/stream?swarm_id=%s&resource_id=%s"%(swarm_id, resource_id), None, {"x-bugswarmapikey":api_key})
b48de82 adds produce.py and consume.py
Andrew Turley authored
25 resp = conn.getresponse()
26 while(1):
27 txt = resp.read(1)
28 sys.stdout.write(txt)
aee6ad5 added flush to consume.py
Davis Barber authored
29 sys.stdout.flush()
b48de82 adds produce.py and consume.py
Andrew Turley authored
30 conn.close();
31
32 def main():
9e239d1 cleaned up kgilmer's commit functionality to match the rest of the code ...
Davis Barber authored
33 server_info = swarmtoolscore.get_server_info()
b48de82 adds produce.py and consume.py
Andrew Turley authored
34 keys = swarmtoolscore.get_keys()
182320f package complete, for now
Davis Barber authored
35 if len(sys.argv) == 1:
b48de82 adds produce.py and consume.py
Andrew Turley authored
36 usage(sys.argv[0])
345c581 adds printing of usage info if an unknown method is given.
Andrew Turley authored
37 elif sys.argv[1] == "consume":
d43b87e @barberdt better signal handling for consume.py
barberdt authored
38 signal.signal(signal.SIGINT, signal_handler)
e2b6314 @aturley updates consume.py and produce.py to use the new streaming API.
aturley authored
39 opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID"%(sys.argv[1])
4796279 made doc changes to produce and consume
Davis Barber authored
40 opt_usage += "\n\n *SWARM_ID: The ID of the swarm to consume." \
41 +"\n *RESOURCE_ID: The ID of the resource to use for consumption."
182320f package complete, for now
Davis Barber authored
42 parser = OptionParser(usage = opt_usage)
43 (options, args) = parser.parse_args()
e2b6314 @aturley updates consume.py and produce.py to use the new streaming API.
aturley authored
44 if len(args) != 3:
62ae4cb parsing args before method calls now. makes methods more standalone. usa...
Davis Barber authored
45 print "Invalid number of args. See --help for correct usage."
46 sys.exit()
47 swarm_id = args[1]
e2b6314 @aturley updates consume.py and produce.py to use the new streaming API.
aturley authored
48 resource_id = args[2]
5ecd181 fixes key issues in consume and produce
Davis Barber authored
49 consume(server_info["hostname"], keys["participation"], swarm_id, resource_id)
345c581 adds printing of usage info if an unknown method is given.
Andrew Turley authored
50 else:
51 usage(sys.argv[0])
b48de82 adds produce.py and consume.py
Andrew Turley authored
52 main()
Something went wrong with that request. Please try again.