aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorAaron Bentley <abentley@panoramicfeedback.com>2005-03-23 18:30:11 +0000
committerAaron Bentley <abentley@panoramicfeedback.com>2005-03-23 18:30:11 +0000
commitdb039bf8987e6148bca5fc3bd417ad0d04dfa3ab (patch)
treed153fdffa85a254d85cd0035800c7fc7432f62cc /libbe
parent6fc191d83c62ec44184b113193e6046bb4999ece (diff)
downloadbugseverywhere-db039bf8987e6148bca5fc3bd417ad0d04dfa3ab.tar.gz
Added editor_string utility function
Diffstat (limited to 'libbe')
-rw-r--r--libbe/utility.py25
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
+