Alon Bar-Lev has uploaded a new change for review. Change subject: dialog: support template hint for queryString ......................................................................
dialog: support template hint for queryString Change-Id: Ia204c59e9b553a4b6b76f40b7b1d4d2c55bd19cb Signed-off-by: Alon Bar-Lev <[email protected]> --- M src/otopi/dialog.py M src/plugins/otopi/dialog/human.py M src/plugins/otopi/dialog/machine.py 3 files changed, 53 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/24/11524/1 diff --git a/src/otopi/dialog.py b/src/otopi/dialog.py index 5889e75..d5a982b 100644 --- a/src/otopi/dialog.py +++ b/src/otopi/dialog.py @@ -272,5 +272,36 @@ if flush: self.__flush(self.__output) + def _queryStringNote( + self, + name, + note=None, + validValues=None, + default=None, + ): + def _subst(s): + ret = s + if validValues is not None: + ret = ret.replace('@VALUES@', ', '.join(validValues)) + if default is not None: + ret = ret.replace('@DEFAULT@', default) + return ret + + if note is None: + note = _("\nPlease specify '{name}'") + if validValues is not None: + note += ' (@VALUES@)' + if default is not None: + note += ' [@DEFAULT@]' + + if isinstance(note, str): + note = [note] + note = [_subst(n) for n in note] + + if len(note) == 1: + note = note[0] + + return note + # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/plugins/otopi/dialog/human.py b/src/plugins/otopi/dialog/human.py index 0f8139f..4089b98 100644 --- a/src/plugins/otopi/dialog/human.py +++ b/src/plugins/otopi/dialog/human.py @@ -149,19 +149,22 @@ prompt=False, default=None, ): + if default is not None: + default = str(default) + if validValues is not None: + validValues = [str(v) for v in validValues] + note = self._queryStringNote( + name=name, + note=note, + validValues=validValues, + default=default, + ) + if not caseSensitive and validValues is not None: validValues = [v.lower() for v in validValues] accepted = False while not accepted: - if note is None: - note = _( - "\nPlease specify '{name}' {values} [{default}]: " - ).format( - name=name, - values=validValues, - default=default, - ) self.dialog.note(text=note, prompt=prompt) value = self._readline(hidden=hidden) if not value and default is not None: diff --git a/src/plugins/otopi/dialog/machine.py b/src/plugins/otopi/dialog/machine.py index 94d7bcd..c412196 100644 --- a/src/plugins/otopi/dialog/machine.py +++ b/src/plugins/otopi/dialog/machine.py @@ -137,14 +137,20 @@ prompt=False, default=False, ): + if default is not None: + default = str(default) + if validValues is not None: + validValues = [str(v) for v in validValues] + note = self._queryStringNote( + name=name, + note=note, + validValues=validValues, + default=default, + ) + if not caseSensitive and validValues is not None: validValues = [v.lower() for v in validValues] - if note is None: - note = _("\nPlease specify value for '{name}' {values}: ").format( - name=name, - values=validValues, - ) self._write( text='%s%s %s\n' % ( dialogcons.DialogMachineConst.REQUEST_PREFIX, -- To view, visit http://gerrit.ovirt.org/11524 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia204c59e9b553a4b6b76f40b7b1d4d2c55bd19cb Gerrit-PatchSet: 1 Gerrit-Project: otopi Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
