~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: Mark Hammond
  • Date: 2008-12-28 05:21:23 UTC
  • mfrom: (3920 +trunk)
  • mto: (3932.1.1 prepare-1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mhammond@skippinet.com.au-20081228052123-f78xs5sbdkotshwf
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import (
27
27
    config,
28
28
    osutils,
 
29
    trace,
29
30
    )
30
31
from bzrlib.errors import BzrError, BadCommitMessageEncoding
31
32
from bzrlib.hooks import Hooks
32
 
from bzrlib.trace import warning, mutter
33
33
 
34
34
 
35
35
def _get_editor():
36
36
    """Return a sequence of possible editor binaries for the current platform"""
37
37
    try:
38
 
        yield os.environ["BZR_EDITOR"]
 
38
        yield os.environ["BZR_EDITOR"], '$BZR_EDITOR'
39
39
    except KeyError:
40
40
        pass
41
41
 
42
42
    e = config.GlobalConfig().get_editor()
43
43
    if e is not None:
44
 
        yield e
 
44
        yield e, config.config_filename()
45
45
        
46
46
    for varname in 'VISUAL', 'EDITOR':
47
47
        if varname in os.environ:
48
 
            yield os.environ[varname]
 
48
            yield os.environ[varname], '$' + varname
49
49
 
50
50
    if sys.platform == 'win32':
51
51
        for editor in 'wordpad.exe', 'notepad.exe':
52
 
            yield editor
 
52
            yield editor, None
53
53
    else:
54
54
        for editor in ['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe']:
55
 
            yield editor
 
55
            yield editor, None
56
56
 
57
57
 
58
58
def _run_editor(filename):
59
59
    """Try to execute an editor to edit the commit message."""
60
 
    for e in _get_editor():
61
 
        edargs = e.split(' ')
 
60
    for candidate, candidate_source in _get_editor():
 
61
        edargs = candidate.split(' ')
62
62
        try:
63
63
            ## mutter("trying editor: %r", (edargs +[filename]))
64
64
            x = call(edargs + [filename])
65
65
        except OSError, e:
66
66
            # We're searching for an editor, so catch safe errors and continue
67
 
            if e.errno in (errno.ENOENT, ):
 
67
            if e.errno in (errno.ENOENT, errno.EACCES):
 
68
                if candidate_source is not None:
 
69
                    # We tried this editor because some user configuration (an
 
70
                    # environment variable or config file) said to try it.  Let
 
71
                    # the user know their configuration is broken.
 
72
                    trace.warning(
 
73
                        'Could not start editor "%s" (specified by %s): %s\n'
 
74
                        % (candidate, candidate_source, str(e)))
68
75
                continue
69
76
            raise
70
77
        if x == 0:
183
190
            try:
184
191
                os.unlink(msgfilename)
185
192
            except IOError, e:
186
 
                warning("failed to unlink %s: %s; ignored", msgfilename, e)
 
193
                trace.warning(
 
194
                    "failed to unlink %s: %s; ignored", msgfilename, e)
187
195
 
188
196
 
189
197
def _create_temp_file_with_commit_template(infotext,