/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 breezy/mergetools.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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
 
 
21
19
import os
22
20
import shutil
23
21
import subprocess
52
50
        if exe is None:
53
51
            return False
54
52
        base, ext = os.path.splitext(exe)
55
 
        path_ext = [unicode(s.lower())
 
53
        path_ext = [s.lower()
56
54
                    for s in os.getenv('PATHEXT', '').split(os.pathsep)]
57
55
        return os.path.exists(exe) and ext in path_ext
58
56
    else:
59
 
        return (os.access(exe, os.X_OK)
60
 
                or osutils.find_executable_on_path(exe) is not None)
 
57
        return (os.access(exe, os.X_OK) or
 
58
                osutils.find_executable_on_path(exe) is not None)
61
59
 
62
60
 
63
61
def invoke(command_line, filename, invoker=None):
73
71
    if exe is not None:
74
72
        cmd_list[0] = exe
75
73
    args, tmp_file = _subst_filename(cmd_list, filename)
 
74
 
76
75
    def cleanup(retcode):
77
76
        if tmp_file is not None:
78
 
            if retcode == 0: # on success, replace file with temp file
 
77
            if retcode == 0:  # on success, replace file with temp file
79
78
                shutil.move(tmp_file, filename)
80
 
            else: # otherwise, delete temp file
 
79
            else:  # otherwise, delete temp file
81
80
                os.remove(tmp_file)
82
81
    return invoker(args[0], args[1:], cleanup)
83
82
 
98
97
    tmp_file = None
99
98
    subst_args = []
100
99
    for arg in args:
101
 
        if '{this_temp}' in arg and not 'this_temp' in subst_names:
 
100
        if '{this_temp}' in arg and 'this_temp' not in subst_names:
102
101
            fh, tmp_file = tempfile.mkstemp(u"_bzr_mergetools_%s.THIS" %
103
102
                                            os.path.basename(filename))
104
103
            trace.mutter('fh=%r, tmp_file=%r', fh, tmp_file)