Browse files

launch-workers bugfix: don't create empty output file

  • Loading branch information...
1 parent eaf5b56 commit 075af23972b3a491f2b8fbf0cc8f11ccd8512594 @lirazsiri lirazsiri committed Aug 9, 2011
Showing with 12 additions and 8 deletions.
  1. +12 −8 cmd_launch_workers.py
View
20 cmd_launch_workers.py
@@ -58,6 +58,7 @@
import getopt
from cloudtask import Hub
+from StringIO import StringIO
def usage(e=None):
if e:
@@ -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.