import calendar
import time
+import os
+import tempfile
class FileString(object):
"""Bare-bones pseudo-file class
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
+