Skip to content

Commit

Permalink
Save the temporary file in case something went wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
bortzmeyer committed Apr 25, 2012
1 parent f3e883a commit 692aabc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion seenthis-post.py
Expand Up @@ -18,6 +18,8 @@
sys.argv[0])
sys.exit(1)

save_message = False # In case of crash

# If the user redirected standard input from a file or a process
if not sys.stdin.isatty():
message = sys.stdin.read()
Expand All @@ -27,6 +29,7 @@
editor = os.environ['EDITOR']
else:
editor = 'vi'
save_message = True
tmpfile = tempfile.NamedTemporaryFile(delete=True)
try:
run_editor = subprocess.Popen([editor, tmpfile.name],
Expand All @@ -41,7 +44,14 @@
print >>sys.stderr, ("Cannot run: \"%s %s\"" % (editor, tmpfile.name))
raise
tmpfile.close()
result = st.post(message)
try:
result = st.post(message)
except:
if save_message:
tmpfile = tempfile.NamedTemporaryFile(delete=False)
tmpfile.write(message)
print "CRASH: *** Message saved in %s ***\n\n" % tmpfile.name
raise
print result


Expand Down

0 comments on commit 692aabc

Please sign in to comment.