Skip to content

Commit

Permalink
launch-workers bugfix: don't create empty output file
Browse files Browse the repository at this point in the history
  • Loading branch information
lirazsiri committed Aug 9, 2011
1 parent eaf5b56 commit 075af23
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cmd_launch_workers.py
Expand Up @@ -58,6 +58,7 @@
import getopt

from cloudtask import Hub
from StringIO import StringIO

def usage(e=None):
if e:
Expand Down Expand Up @@ -118,16 +119,19 @@ def main():
except ValueError:
usage("illegal howmany value '%s'" % howmany)

if output == '-':
output = sys.stdout
else:
if exists(output):
fatal("'%s' already exists, refusing to overwrite" % output)
if output != '-' and exists(output):
fatal("'%s' already exists, refusing to overwrite" % output)

output = file(output, "w")
sio = StringIO()

for address in Hub(hub_apikey).launch(howmany, **kwargs):
print >> output, address
try:
for address in Hub(hub_apikey).launch(howmany, **kwargs):
print >> sio, address
finally:
addresses = sio.getvalue()
if addresses:
output = sys.stdout if (output == '-') else file(output, "w")
output.write(addresses)

if __name__ == "__main__":
main()

0 comments on commit 075af23

Please sign in to comment.