diff options
author | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-23 18:30:11 +0000 |
---|---|---|
committer | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-23 18:30:11 +0000 |
commit | db039bf8987e6148bca5fc3bd417ad0d04dfa3ab (patch) | |
tree | d153fdffa85a254d85cd0035800c7fc7432f62cc /libbe/utility.py | |
parent | 6fc191d83c62ec44184b113193e6046bb4999ece (diff) | |
download | bugseverywhere-db039bf8987e6148bca5fc3bd417ad0d04dfa3ab.tar.gz |
Added editor_string utility function
Diffstat (limited to 'libbe/utility.py')
-rw-r--r-- | libbe/utility.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libbe/utility.py b/libbe/utility.py index a2774d3..3ed4bda 100644 --- a/libbe/utility.py +++ b/libbe/utility.py @@ -1,5 +1,7 @@ import calendar import time +import os +import tempfile class FileString(object): """Bare-bones pseudo-file class @@ -76,4 +78,25 @@ def str_to_time(str_time): def handy_time(time_val): return time.strftime("%a, %d %b %Y %H:%M", time.localtime(time_val)) - + +def editor_string(): + """Invokes the editor, and returns the user_produced text as a string""" + try: + editor = os.environ["EDITOR"] + except KeyError: + raise cmdutil.UserError( + "No comment supplied, and EDITOR not specified.") + + fhandle, fname = tempfile.mkstemp() + try: + os.close(fhandle) + oldmtime = os.path.getmtime(fname) + os.system("%s %s" % (editor, fname)) + if oldmtime == os.path.getmtime(fname): + output = None + else: + output = file(fname, "rb").read() + finally: + os.unlink(fname) + return output + |