-_WIN32_PATH_EXT = [ext.lower() for ext in os.getenv('PATHEXT', '').split(';')]
+_WIN32_PATH_EXT = [unicode(ext.lower())
+ for ext in os.getenv('PATHEXT', '').split(';')]
class MergeTool(object):
@@ -80,20 +81,20 @@
return name
@@ -299,9 +300,9 @@ Option('list', help='Lists the currently defined external merge tools.', short_name='l'), Option('remove', help='Removes the external merge tool called ARG.',
- type=str, short_name='r'),
+ type=unicode, short_name='r'), Option('update', help='Updates the external merge tool called ARG '
- 'using ARGS as the command-line.', type=str, short_name='u'),
+ 'using ARGS as the command-line.', type=unicode, short_name='u')
,
]
def run(self, args_list=None, add=False, detect=False, list=False,
@@ -309,8 +310,8 @@
if (not add and not detect and not list and remove is None and
update is None):
raise errors.BzrCommandError(
- 'You must supply one of --add, --detect, --list, --remove or '
- '--update')
+ u'You must supply one of --add, --detect, --list, --remove or '
+ u'--update')
if add: self.add_tool(args_list)
elif detect:
@@ -325,19 +326,19 @@
def add_tool(self, args):
if args is None or len(args) == 0:
raise errors.BzrCommandError(
- 'You must supply the command-line for the external merge tool')
+ u'You must supply the command-line for the external merge tool'
)
new_mt = MergeTool(args)
if find_merge_tool(new_mt.get_name()) is not None:
raise errors.BzrCommandError(
- 'External merge tool already exists: %s' % new_mt.get_name())
+ u'External merge tool already exists: %s' % new_mt.get_name()) merge_tools = get_merge_tools() merge_tools.append(new_mt) set_merge_tools(merge_tools)
uif = ui.ui_factory
- uif.note('Added external merge tool: %s' % new_mt.get_name())
+ uif.note(u'Added external merge tool: %s' % new_mt.get_name())
if not new_mt.is_available(): uif.show_warning(
- 'External merge tool is not available: %s' % new_mt.get_name())
+ u'External merge tool is not available: %s' % new_mt.get_name()
)
def update_tool(self, name, args):
if args is None or len(args) == 0:
raise errors.BzrCommandError(
- 'You must supply the command-line for the external merge tool')
+ u'You must supply the command-line for the external merge tool') merge_tools = get_merge_tools()
for mt in merge_tools:
if mt.get_name() == name: mt.set_executable(args[0]) mt.set_arguments(args[1:]) uif = ui.ui_factory
- uif.note('Updated external merge tool: %s' % name)
+ uif.note(u'Updated external merge tool: %s' % name)
if not mt.is_available(): uif.show_warning(
- 'External merge tool is not available: %s' %
+ u'External merge tool is not available: %s' % mt.get_name()) break
else:
raise errors.BzrCommandError(
- 'Unknown external merge tool: %s' % name)
+ u'Unknown external merge tool: %s' % name) set_merge_tools(merge_tools)
Martin (gz) asked "What happens with non-ascii filenames? I see no handling, so will you just be throwing UnicodeError somewhere?"
I'm not sure what handling I'm meant to do other than use unicode literals (e.g. u'blah') when working with the command-line in a merge tool, like so:
=== modified file 'bzrlib/ mergetools. py' mergetools. py 2010-10-27 01:56:55 +0000 mergetools. py 2010-10-27 04:35:10 +0000
--- a/bzrlib/
+++ b/bzrlib/
@@ -39,11 +39,11 @@
substitution_help = {
- '%b' : 'file.BASE',
- '%t' : 'file.THIS',
- '%o' : 'file.OTHER',
- '%r' : 'file (output)',
- '%T' : 'file.THIS (temp copy, used to overwrite "file" if merge succeeds)'
+ u'%b' : u'file.BASE',
+ u'%t' : u'file.THIS',
+ u'%o' : u'file.OTHER',
+ u'%r' : u'file (output)',
+ u'%T' : u'file.THIS (temp copy, used to overwrite "file" if merge succeeds)
'
}
@@ -53,7 +53,8 @@
return retcode
-_WIN32_PATH_EXT = [ext.lower() for ext in os.getenv( 'PATHEXT' , '').split(';')] ext.lower( )) 'PATHEXT' , '').split(';')]
+_WIN32_PATH_EXT = [unicode(
+ for ext in os.getenv(
class MergeTool(object):
@@ -80,20 +81,20 @@
return name
def get_commandline (self): self._commandli ne) self._commandli ne)
- return ' '.join(
+ return u' '.join(
def get_commandline _as_list( self):
return self._commandline
def get_executable( self): _commandline) < 1: ne[0]
if len(self.
- return ''
+ return u''
return self._commandli
def get_arguments( self): _commandline) < 2: self._commandli ne[1:]) self._commandli ne[1:])
if len(self.
- return ''
- return ' '.join(
+ return u''
+ return u' '.join(
def set_executable( self, executable):
self. _commandline[ :1] = [executable] mktemp( "_bzr_mergetool s_%s.THIS" % mktemp( u"_bzr_ mergetools_ %s.THIS" %
os.path. basename( filename) ) copy(filename + ".THIS", tmp_file) copy(filename + u".THIS", tmp_file)
subst_ args.append( arg)
@@ -130,26 +131,26 @@
tmp_file = None
subst_args = []
for arg in args:
- arg = arg.replace('%b', filename + '.BASE')
- arg = arg.replace('%t', filename + '.THIS')
- arg = arg.replace('%o', filename +'.OTHER')
- arg = arg.replace('%r', filename)
- if '%T' in arg:
- tmp_file = tempfile.
+ arg = arg.replace(u'%b', filename + u'.BASE')
+ arg = arg.replace(u'%t', filename + u'.THIS')
+ arg = arg.replace(u'%o', filename + u'.OTHER')
+ arg = arg.replace(u'%r', filename)
+ if u'%T' in arg:
+ tmp_file = tempfile.
- shutil.
- arg = arg.replace('%T', tmp_file)
+ shutil.
+ arg = arg.replace(u'%T', tmp_file)
return subst_args, tmp_file
_KNOWN_MERGE_TOOLS = (
- 'bcompare %t %o %b %r',
- 'kdiff3 %b %t %o -o %r',
- 'xxdiff -m -O -M %r %t %b %o',
- 'meld %b %T %o',
- 'opendiff %t %o -ancestor %b -merge %r',
- 'winmergeu %r',
+ u'bcompare %t %o %b %r',
+ u'kdiff3 %b %t %o -o %r',
+ u'xxdiff -m -O -M %r %t %b %o',
+ u'meld %b %T %o',
+ u'opendiff %t %o -ancestor %b -merge %r',
+ u'winmergeu %r',
)
@@ -299,9 +300,9 @@
Option( 'list', help='Lists the currently defined external merge tools.',
short_ name='l' ),
Option( 'remove' , help='Removes the external merge tool called ARG.',
Option( 'update' , help='Updates the external merge tool called ARG '
- type=str, short_name='r'),
+ type=unicode, short_name='r'),
- 'using ARGS as the command-line.', type=str, short_name='u'),
+ 'using ARGS as the command-line.', type=unicode, short_name='u')
,
]
def run(self, args_list=None, add=False, detect=False, list=False, BzrCommandError (
self. add_tool( args_list) BzrCommandError ( tool(new_ mt.get_ name()) is not None: BzrCommandError (
merge_ tools = get_merge_tools()
merge_ tools.append( new_mt)
set_merge_ tools(merge_ tools) is_available( ):
uif. show_warning(
@@ -309,8 +310,8 @@
if (not add and not detect and not list and remove is None and
update is None):
raise errors.
- 'You must supply one of --add, --detect, --list, --remove or '
- '--update')
+ u'You must supply one of --add, --detect, --list, --remove or '
+ u'--update')
if add:
elif detect:
@@ -325,19 +326,19 @@
def add_tool(self, args):
if args is None or len(args) == 0:
raise errors.
- 'You must supply the command-line for the external merge tool')
+ u'You must supply the command-line for the external merge tool'
)
new_mt = MergeTool(args)
if find_merge_
raise errors.
- 'External merge tool already exists: %s' % new_mt.get_name())
+ u'External merge tool already exists: %s' % new_mt.get_name())
uif = ui.ui_factory
- uif.note('Added external merge tool: %s' % new_mt.get_name())
+ uif.note(u'Added external merge tool: %s' % new_mt.get_name())
if not new_mt.
- 'External merge tool is not available: %s' % new_mt.get_name())
+ u'External merge tool is not available: %s' % new_mt.get_name()
)
def detect_tools(self):
new_merge_ tools = detect_ merge_tools( ) merge_tools) > 0:
new_merge_ tools.extend( merge_tools)
set_merge_ tools(new_ merge_tools) make_output_ stream( )
merge_ tools = get_merge_tools() commandline( ))) commandline( )))
@@ -350,9 +351,9 @@
uif = ui.ui_factory
if len(new_
for mt in new_merge_tools:
- uif.note('Detected external merge tool: %s' % mt.get_name())
+ uif.note(u'Detected external merge tool: %s' % mt.get_name())
else:
- uif.note('No external merge tools detected')
+ uif.note(u'No external merge tools detected')
return
@@ -361,7 +362,7 @@
s = ui.ui_factory.
for mt in merge_tools:
- s.write('%s: %s\n' % (mt.get_name(), mt.get_
+ s.write(u'%s: %s\n' % (mt.get_name(), mt.get_
def remove_tool(self, name):
merge_ tools = get_merge_tools()
break BzrCommandError (
set_merge_ tools(merge_ tools)
@@ -371,26 +372,26 @@
else:
raise errors.
- 'Unknown external merge tool: %s' % name)
+ u'Unknown external merge tool: %s' % name)
def update_tool(self, name, args): BzrCommandError (
if args is None or len(args) == 0:
raise errors.
- 'You must supply the command-line for the external merge tool')
+ u'You must supply the command-line for the external merge tool')
merge_ tools = get_merge_tools()
mt.set_ executable( args[0] )
mt.set_ arguments( args[1: ])
uif = ui.ui_factory
uif.show_ warning(
mt. get_name( ))
break BzrCommandError (
set_merge_ tools(merge_ tools)
for mt in merge_tools:
if mt.get_name() == name:
- uif.note('Updated external merge tool: %s' % name)
+ uif.note(u'Updated external merge tool: %s' % name)
if not mt.is_available():
- 'External merge tool is not available: %s' %
+ u'External merge tool is not available: %s' %
else:
raise errors.
- 'Unknown external merge tool: %s' % name)
+ u'Unknown external merge tool: %s' % name)