Alon Bar-Lev has uploaded a new change for review.

Change subject: core: dialog: queryString: replace mandatory with default
......................................................................

core: dialog: queryString: replace mandatory with default

Change-Id: I57219123dc33dafedd982b0c7edf2e3123752391
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, 15 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/46/11346/1

diff --git a/src/otopi/dialog.py b/src/otopi/dialog.py
index 6d3dbb4..28a1df2 100644
--- a/src/otopi/dialog.py
+++ b/src/otopi/dialog.py
@@ -61,9 +61,9 @@
         name,
         note=None,
         validValues=None,
-        mandatory=False,
         hidden=False,
         prompt=False,
+        default=None,
     ):
         """Query string from manager.
 
@@ -71,9 +71,9 @@
         name -- name of variable.
         note -- note to present.
         validValues -- tuple of valid values.
-        mandatory -- if value must be provided.
         hidden -- if tty echo will be disabled.
         prompt -- do not echo new line after note if possible.
+        default -- if not None use this if empty.
 
         """
         raise NotImplementedError(_('Dialog queryString not implemented'))
diff --git a/src/plugins/otopi/dialog/human.py 
b/src/plugins/otopi/dialog/human.py
index 882ef8f..3fd5390 100644
--- a/src/plugins/otopi/dialog/human.py
+++ b/src/plugins/otopi/dialog/human.py
@@ -144,22 +144,27 @@
         name,
         note=None,
         validValues=None,
-        mandatory=False,
         hidden=False,
         prompt=False,
+        default=None,
     ):
         accepted = False
         while not accepted:
             if note is None:
-                note = _("\nPlease specify '{name}' {values}: ").format(
+                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:
+                value = default
             if validValues is not None and value not in validValues:
                 self.logger.error(_('Invalid value'))
-            elif mandatory and not value:
+            elif not value and value != default:
                 self.logger.error(_('Please specify value'))
             else:
                 accepted = True
diff --git a/src/plugins/otopi/dialog/machine.py 
b/src/plugins/otopi/dialog/machine.py
index 72cc160..9d3ca61 100644
--- a/src/plugins/otopi/dialog/machine.py
+++ b/src/plugins/otopi/dialog/machine.py
@@ -132,9 +132,9 @@
         name,
         note=None,
         validValues=None,
-        mandatory=False,
         hidden=False,
         prompt=False,
+        default=False,
     ):
         if note is None:
             note = _("\nPlease specify value for '{name}' {values}: ").format(
@@ -150,9 +150,11 @@
         )
         self.dialog.note(text=note, prompt=prompt)
         value = self._readline()
+        if not value and default is not None:
+            value = default
         if (
-            validValues is not None and value not in validValues or
-            mandatory and not value
+            (validValues is not None and value not in validValues) or
+            (not value and value != default)
         ):
             raise RuntimeError(
                 _("Invalid value provided to '{name}'").format(


--
To view, visit http://gerrit.ovirt.org/11346
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I57219123dc33dafedd982b0c7edf2e3123752391
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

Reply via email to