Browse files

For, sets default usage as wrapping the payload and moves …

…the raw message format to the options. Also changes usage to promote typing into stdin as the default way of using the script.
  • Loading branch information...
1 parent 78569bc commit 0b06f59def1d13cfb84028af02d64b85df5a76d5 @barberdt barberdt committed Dec 6, 2011
Showing with 8 additions and 8 deletions.
  1. +8 −8
@@ -19,7 +19,7 @@ def signal_handler(signal, frame):
-def produce(hostname, api_key, swarm_id, resource_id, wrap):
+def produce(hostname, api_key, swarm_id, resource_id, raw):
global conn
conn = httplib.HTTPConnection(hostname)
sel = "/stream?swarm_id=%s&resource_id=%s"%(swarm_id, resource_id)
@@ -36,7 +36,7 @@ def produce(hostname, api_key, swarm_id, resource_id, wrap):
#Execute further messages
- if wrap == False:
+ if raw == True:
while True:
msg = sys.stdin.readline()
@@ -72,19 +72,19 @@ def main():
elif sys.argv[1] == "produce":
signal.signal(signal.SIGINT, signal_handler)
- opt_usage = "usage: \n DATA | ./ %s SWARM_ID RESOURCE_ID [options]"%(sys.argv[1])
- opt_usage += "\n\n *DATA: The data to produce in the feed. Valid forms; \"echo 'DATA'\", \"cat FILENAME\".\n DATA may also be passed in through stdin after running the script rather than piping in each time." \
- +"\n *SWARM_ID: The ID of the swarm to produce to." \
- +"\n *RESOURCE_ID: The ID of the resource to produce with."
+ opt_usage = "usage: \n ./ %s SWARM_ID RESOURCE_ID [options]"%(sys.argv[1])
+ opt_usage += "\n\n *SWARM_ID: The ID of the swarm to produce to." \
+ +"\n *RESOURCE_ID: The ID of the resource to produce with." \
+ +"\n\n NOTE: Data may also be produced by piping into the function (DATA | ./ produce SWARM_ID RESOURCE_ID [options])."
parser = OptionParser(usage = opt_usage)
- parser.add_option("-w", action="store_true", dest="wrap", help="Wrap the payload in the proper message stanza.", default=False)
+ parser.add_option("-r", action="store_true", dest="raw", help="Require that messages be sent in the raw formatting as specified in the 'Sending Messages' section at", default=False)
(options, args) = parser.parse_args()
if len(args) != 3:
print "Invalid number of args. See --help for correct usage."
swarm_id = args[1]
resource_id = args[2]
- produce(server_info["hostname"], keys['participation'], swarm_id, resource_id, options.wrap)
+ produce(server_info["hostname"], keys['participation'], swarm_id, resource_id, options.raw)

0 comments on commit 0b06f59

Please sign in to comment.