Commit d72f3627 authored by Manuel Jacob's avatar Manuel Jacob

py3: fix custom tools

--HG--
branch : stable
parent 0ddbafd86b8b
Pipeline #9853 passed with stage
in 23 minutes and 3 seconds
......@@ -20,6 +20,8 @@ from __future__ import absolute_import
import re
from mercurial import pycompat
from .qtcore import (
QSettings,
Qt,
......@@ -259,8 +261,7 @@ class ToolsFrame(QFrame):
pass
tools = self.value()
for uname in tools:
name = hglib.fromunicode(uname)
for name in tools:
if name[0] in '|-':
continue
for field in sorted(tools[name]):
......@@ -268,7 +269,8 @@ class ToolsFrame(QFrame):
value = tools[name][field]
# value may be bool if originating from hglib.tortoisehgtools()
if value != '':
ini.set(section, keyname, str(value))
updateIniValue(section, keyname,
hglib.fromunicode(pycompat.unicode(value)))
# 2. Save the new guidefs
for n, toollistwidget in enumerate(self.widgets):
......@@ -278,7 +280,8 @@ class ToolsFrame(QFrame):
emitChanged = True
toollist = toollistwidget.value()
updateIniValue('tortoisehg', toollocation, ' '.join(toollist))
updateIniValue('tortoisehg', toollocation,
hglib.fromunicode(' '.join(toollist)))
return emitChanged
......@@ -567,7 +570,7 @@ class ToolListBox(QListWidget):
if [name] == toollist[-1:]:
continue
else:
name = hglib.fromunicode(uname)
name = uname
guidef.append(name)
return guidef
......@@ -577,7 +580,7 @@ class ToolListBox(QListWidget):
else:
if not icon:
icon = DEFAULTICONNAME
if isinstance(icon, str):
if hglib.isbasestring(icon):
icon = qtlib.geticon(icon)
item = QListWidgetItem(icon, text)
row = self.currentIndex().row()
......
......@@ -2184,11 +2184,15 @@ class RepoWidget(QWidget):
# Perform variable expansion
# This is done in two steps:
# 1. Expand environment variables
if not pycompat.ispy3:
command = hglib.fromunicode(command)
command = os.path.expandvars(command).strip()
if not command:
InfoMsgBox(_('Invalid command'),
_('The selected command is empty'))
return
if not pycompat.ispy3:
workingdir = hglib.fromunicode(workingdir)
if workingdir:
workingdir = os.path.expandvars(workingdir).strip()
......@@ -2257,7 +2261,13 @@ class RepoWidget(QWidget):
_ui.ferr = pycompat.bytesio()
# avoid circular import of hgqt.run by importing it inplace
from . import run
res = run.dispatch(cmd, u=_ui)
cmdb = []
for part in cmd:
if isinstance(part, pycompat.unicode):
cmdb.append(hglib.fromunicode(part))
else:
cmdb.append(part)
res = run.dispatch(cmdb, u=_ui)
if res:
errormsg = _ui.ferr.getvalue().strip()
if errormsg:
......
......@@ -587,11 +587,11 @@ def tortoisehgtools(uiorconfig, selectedlocation=None):
>>> tools, toollist = tortoisehgtools(uiobj)
>>> pprint(tools) #doctest: +NORMALIZE_WHITESPACE
{b'update_to_tip': {b'command': b'hg update tip',
b'icon': b'hg-update',
b'tooltip': b'Update to tip'}}
{'update_to_tip': {'command': 'hg update tip',
'icon': 'hg-update',
'tooltip': 'Update to tip'}}
>>> toollist
[b'update_to_tip']
['update_to_tip']
If selectedlocation is set, only return those tools that have been
configured to be shown at the given "location".
......@@ -619,16 +619,16 @@ def tortoisehgtools(uiorconfig, selectedlocation=None):
>>> tools, toollist = tortoisehgtools(
... uiobj, selectedlocation='workbench.custom-toolbar')
>>> sorted(tools.keys())
[b'explore_wd', b'update_to_tip']
['explore_wd', 'update_to_tip']
>>> toollist
[b'update_to_tip', b'|', b'explore_wd']
['update_to_tip', '|', 'explore_wd']
>>> tools, toollist = tortoisehgtools(
... uiobj, selectedlocation='workbench.revdetails.custom-menu')
>>> sorted(tools.keys())
[b'update_to_null', b'update_to_tip']
['update_to_null', 'update_to_tip']
>>> toollist
[b'update_to_tip', b'update_to_null']
['update_to_tip', 'update_to_null']
Valid "locations lists" are:
- workbench.custom-toolbar
......@@ -645,20 +645,20 @@ def tortoisehgtools(uiorconfig, selectedlocation=None):
>>> cfg.parse(b'<hgrc>', hgrctext)
>>> tools, toollist = tortoisehgtools(cfg)
>>> pprint(tools) #doctest: +NORMALIZE_WHITESPACE
{b'update_to_tip': {b'command': b'hg update tip',
b'icon': b'hg-update',
b'tooltip': b'Update to tip'}}
{'update_to_tip': {'command': 'hg update tip',
'icon': 'hg-update',
'tooltip': 'Update to tip'}}
>>> toollist
[b'update_to_tip']
['update_to_tip']
>>> cfg = config.config()
>>> cfg.parse(b'<hgrc>', hgrctext_full)
>>> tools, toollist = tortoisehgtools(
... cfg, selectedlocation='workbench.custom-toolbar')
>>> sorted(tools.keys())
[b'explore_wd', b'update_to_tip']
['explore_wd', 'update_to_tip']
>>> toollist
[b'update_to_tip', b'|', b'explore_wd']
['update_to_tip', '|', 'explore_wd']
No error for empty config:
......@@ -678,12 +678,14 @@ def tortoisehgtools(uiorconfig, selectedlocation=None):
tools = {}
for key, value in configitems(b'tortoisehg-tools'):
toolname, field = key.split(b'.', 1)
toolname, field = tounicode(key).split('.', 1)
if toolname not in tools:
tools[toolname] = {}
bvalue = stringutil.parsebool(value)
if bvalue is not None:
value = bvalue
else:
value = tounicode(value)
tools[toolname][field] = value
if selectedlocation is None:
......@@ -698,7 +700,8 @@ def tortoisehgtools(uiorconfig, selectedlocation=None):
toollist = []
selectedtools = {}
for name in guidef:
if name != b'|':
name = tounicode(name)
if name != '|':
info = tools.get(name, None)
if info is None:
continue
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment