changeset 6:81c0de264b86

add a tmpbuffer utility, from http://k0s.org/hg/bitsyblog/file/4df927b0d847/bitsyblog/blogme.py
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Nov 2010 11:32:15 -0700
parents 43fb6fd8903d
children 873a703555e9
files bzconsole/utils.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bzconsole/utils.py	Tue Nov 02 11:32:15 2010 -0700
@@ -0,0 +1,11 @@
+def tmpbuffer(editor=None):
+    """open an editor and retreive the resulting editted buffer"""
+    if not editor:
+        editor = os.environ['EDITOR']
+    tmpfile = tempfile.mktemp(suffix='.txt')
+    cmdline = editor.split()
+    cmdline.append(tmpfile)
+    edit = subprocess.call(cmdline)
+    buffer = file(tmpfile).read().strip()
+    os.remove(tmpfile)
+    return buffer
\ No newline at end of file