* [PATCH] Factorize editor handling.
@ 2007-02-26 19:48 Yann Dirson
2007-02-27 14:17 ` Catalin Marinas
0 siblings, 1 reply; 2+ messages in thread
From: Yann Dirson @ 2007-02-26 19:48 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
At the same time we trap the editor error for all editor calls, not
just when called from "stg mail". We may want to define a new
exception for this though.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
stgit/commands/mail.py | 17 +----------------
stgit/stack.py | 14 +-------------
stgit/utils.py | 23 ++++++++++++++++++++++-
3 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index 762829c..151a408 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -272,22 +272,7 @@ def __edit_message(msg):
f.write(msg)
f.close()
- # the editor
- editor = config.get('stgit.editor')
- if editor:
- pass
- elif 'EDITOR' in os.environ:
- editor = os.environ['EDITOR']
- else:
- editor = 'vi'
- editor += ' %s' % fname
-
- print 'Invoking the editor: "%s"...' % editor,
- sys.stdout.flush()
- err = os.system(editor)
- if err:
- raise CmdException, 'editor failed, exit code: %d' % err
- print 'done'
+ call_editor(fname)
# read the message back
f = file(fname)
diff --git a/stgit/stack.py b/stgit/stack.py
index 99f10e5..feb77e3 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -91,19 +91,7 @@ def edit_file(series, line, comment, show_patch = True):
print >> f, __comment_prefix, 'vi: set textwidth=75 filetype=diff nobackup:'
f.close()
- # the editor
- editor = config.get('stgit.editor')
- if editor:
- pass
- elif 'EDITOR' in os.environ:
- editor = os.environ['EDITOR']
- else:
- editor = 'vi'
- editor += ' %s' % fname
-
- print 'Invoking the editor: "%s"...' % editor,
- sys.stdout.flush()
- print 'done (exit code: %d)' % os.system(editor)
+ call_editor(fname)
f = file(fname, 'r+')
diff --git a/stgit/utils.py b/stgit/utils.py
index 67431ec..d7d4777 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -1,7 +1,8 @@
"""Common utility functions
"""
-import errno, os, os.path
+import errno, os, os.path, sys
+from stgit.config import config
__copyright__ = """
Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
@@ -152,3 +153,23 @@ def rename(basedir, file1, file2):
create_dirs(os.path.dirname(full_file2))
os.rename(os.path.join(basedir, file1), full_file2)
remove_dirs(basedir, os.path.dirname(file1))
+
+def call_editor(filename):
+ """Run the editor on the specified filename."""
+
+ # the editor
+ editor = config.get('stgit.editor')
+ if editor:
+ pass
+ elif 'EDITOR' in os.environ:
+ editor = os.environ['EDITOR']
+ else:
+ editor = 'vi'
+ editor += ' %s' % filename
+
+ print 'Invoking the editor: "%s"...' % editor,
+ sys.stdout.flush()
+ err = os.system(editor)
+ if err:
+ raise Exception, 'editor failed, exit code: %d' % err
+ print 'done'
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Factorize editor handling.
2007-02-26 19:48 [PATCH] Factorize editor handling Yann Dirson
@ 2007-02-27 14:17 ` Catalin Marinas
0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2007-02-27 14:17 UTC (permalink / raw)
To: Yann Dirson; +Cc: git
On 26/02/07, Yann Dirson <ydirson@altern.org> wrote:
> At the same time we trap the editor error for all editor calls, not
> just when called from "stg mail".
I merged this patch. In the initial StGIT versions, someone complained
that an editor (ed) returning a non-zero code is not actually an error
and shouldn't raise an exception. If anyone complains about this in
the future (that person is no longer using StGIT :-)), we could add a
config option to not raise the exception (though with some problems
for them).
> We may want to define a new exception for this though.
I added an EditorException since it needs to cought in main.py to
avoid a stack dump.
--
Catalin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-02-27 14:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-26 19:48 [PATCH] Factorize editor handling Yann Dirson
2007-02-27 14:17 ` Catalin Marinas
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.