/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/mergetools.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Utility functions for managing external merge tools such as kdiff3."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import os
20
22
import shutil
21
23
import subprocess
22
24
import sys
23
25
import tempfile
24
26
 
25
 
from .lazy_import import lazy_import
 
27
from bzrlib.lazy_import import lazy_import
26
28
lazy_import(globals(), """
27
 
from breezy import (
 
29
from bzrlib import (
28
30
    cmdline,
29
31
    osutils,
30
32
    trace,
50
52
        if exe is None:
51
53
            return False
52
54
        base, ext = os.path.splitext(exe)
53
 
        path_ext = [s.lower()
 
55
        path_ext = [unicode(s.lower())
54
56
                    for s in os.getenv('PATHEXT', '').split(os.pathsep)]
55
57
        return os.path.exists(exe) and ext in path_ext
56
58
    else:
57
 
        return (os.access(exe, os.X_OK) or
58
 
                osutils.find_executable_on_path(exe) is not None)
 
59
        return (os.access(exe, os.X_OK)
 
60
                or osutils.find_executable_on_path(exe) is not None)
59
61
 
60
62
 
61
63
def invoke(command_line, filename, invoker=None):
71
73
    if exe is not None:
72
74
        cmd_list[0] = exe
73
75
    args, tmp_file = _subst_filename(cmd_list, filename)
74
 
 
75
76
    def cleanup(retcode):
76
77
        if tmp_file is not None:
77
 
            if retcode == 0:  # on success, replace file with temp file
 
78
            if retcode == 0: # on success, replace file with temp file
78
79
                shutil.move(tmp_file, filename)
79
 
            else:  # otherwise, delete temp file
 
80
            else: # otherwise, delete temp file
80
81
                os.remove(tmp_file)
81
82
    return invoker(args[0], args[1:], cleanup)
82
83
 
97
98
    tmp_file = None
98
99
    subst_args = []
99
100
    for arg in args:
100
 
        if '{this_temp}' in arg and 'this_temp' not in subst_names:
 
101
        if '{this_temp}' in arg and not 'this_temp' in subst_names:
101
102
            fh, tmp_file = tempfile.mkstemp(u"_bzr_mergetools_%s.THIS" %
102
103
                                            os.path.basename(filename))
103
104
            trace.mutter('fh=%r, tmp_file=%r', fh, tmp_file)
115
116
    arg = arg.replace('{this}', subst_names['this'])
116
117
    arg = arg.replace('{other}', subst_names['other'])
117
118
    arg = arg.replace('{result}', subst_names['result'])
118
 
    if 'this_temp' in subst_names:
 
119
    if subst_names.has_key('this_temp'):
119
120
        arg = arg.replace('{this_temp}', subst_names['this_temp'])
120
121
    return arg
121
122