[node-patches] Change in ovirt-node[master]: validation: Work on validation

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Dec 11 20:09:33 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: validation: Work on validation
......................................................................

validation: Work on validation

Change-Id: I7223a1620cdea94df386bd76b9d601fd12c4df7e
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins/__init__.py
M scripts/tui/src/ovirt/node/plugins/kdump.py
M scripts/tui/src/ovirt/node/tui.py
M scripts/tui/src/ovirt/node/widgets.py
4 files changed, 60 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/78/9878/1

diff --git a/scripts/tui/src/ovirt/node/plugins/__init__.py b/scripts/tui/src/ovirt/node/plugins/__init__.py
index 1230368..6e0cdd4 100644
--- a/scripts/tui/src/ovirt/node/plugins/__init__.py
+++ b/scripts/tui/src/ovirt/node/plugins/__init__.py
@@ -58,7 +58,7 @@
         Returns:
             The name of the plugin
         """
-        raise Exception("Not yet implemented.")
+        raise NotImplementedError()
 
     def rank(self):
         """Is used to add a order in-between plugins 0<n<100
@@ -73,7 +73,7 @@
         Returns:
             The model (dict) of the plugin
         """
-        raise Exception("Not yet implemented.")
+        raise NotImplementedError()
 
     def validators(self):
         """Returns a dict of validators.
@@ -85,6 +85,7 @@
         Returns:
             A dict of validators
         """
+        raise NotImplementedError()
 
     def validate(self, path, value):
         """Validates a value against the validator of a given path
@@ -123,7 +124,7 @@
         Returns:
             List of (path, widget)
         """
-        raise Exception("Not yet implemented.")
+        raise NotImplementedError()
 
     def ui_config(self):
         """Specifies additional details for the UI
@@ -147,7 +148,29 @@
         Raises:
             Errors
         """
-        raise Exception("Not yet implemented.")
+        raise NotImplementedError()
+
+    def validate_model(self):
+        """Simulate a complete model change.
+        This runs all current model values throught the checks to see
+        if the model validates.
+
+        Returns:
+            True if the model validates
+        Raises:
+            An exception on a problem
+        """
+        LOGGER.debug("Triggering revalidation of model")
+        is_valid = True
+        try:
+            for path, value in self.model().items():
+                self.on_change({path: value})
+        except NotImplementedError:
+            LOGGER.debug("Plugin has no model")
+        except InvalidData:
+            LOGGER.warning("Plugin has invalid model")
+            is_valid = False
+        return is_valid
 
     def on_merge(self, changes):
         """Handles the changes and throws an Exception if something goes wrong
@@ -160,7 +183,7 @@
         Raises:
             Errors
         """
-        raise Exception("Not yet implemented.")
+        raise NotImplementedError()
 
     def ui_name(self):
         return self.name()
diff --git a/scripts/tui/src/ovirt/node/plugins/kdump.py b/scripts/tui/src/ovirt/node/plugins/kdump.py
index 4e690dd..aabe5a5 100644
--- a/scripts/tui/src/ovirt/node/plugins/kdump.py
+++ b/scripts/tui/src/ovirt/node/plugins/kdump.py
@@ -44,7 +44,7 @@
         """Validators validate the input on change and give UI feedback
         """
         return {
-                "kdump.type": ovirt.node.valid.Options([t[1] for t in self._types]),
+                "kdump.type": ovirt.node.valid.Options(dict(self._types).keys()),
                 "kdump.ssh_location": ovirt.node.valid.Text(),
                 "kdump.nfs_location": ovirt.node.valid.Text(),
             }
diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/tui.py
index 9c0022e..8cfc11c 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -34,11 +34,12 @@
                ('main.menu.frame', 'light gray', ''),
                ('plugin.widget.entry', 'dark gray', ''),
                ('plugin.widget.entry.frame', 'light gray', ''),
-               ('plugin.widget.disabled', 'dark gray', 'light gray'),
+               ('plugin.widget.entry.disabled', 'dark gray', 'light gray'),
                ('plugin.widget.notice', 'light red', ''),
                ('plugin.widget.header', 'light blue', 'light gray'),
                ('plugin.widget.divider', 'dark gray', ''),
                ('plugin.widget.button', 'dark blue', ''),
+               ('plugin.widget.button.disabled', 'light gray', ''),
                ]
 
     def __init__(self, app):
@@ -105,14 +106,16 @@
                     plugin.validate(path, new_value)
                     plugin._on_ui_change({path: new_value})
                     widget.notice = ""
-                    # FIXME change state of Save button
+                    plugin.__save_button.enable(True)
 
                 except ovirt.node.plugins.Concern as e:
                     LOGGER.error("Concern when updating: %s" % e)
 
                 except ovirt.node.plugins.InvalidData as e:
-                    widget.notice = e.message
                     LOGGER.error("Invalid data when updating: %s" % e)
+                    widget.notice = e.message
+                    plugin.__save_button.enable(False)
+
                 self.__loop.draw_screen()
             urwid.connect_signal(widget, 'change', on_widget_value_change)
 
@@ -172,10 +175,18 @@
 
         if config["save_button"]:
             save = ovirt.node.widgets.Button("Save")
+            save.enable(False)
             urwid.connect_signal(save, 'click', lambda x: plugin._on_ui_save())
             widgets.append(urwid.Filler(save))
+            plugin.__save_button = save
 
         widgets.append(urwid.Filler(urwid.Text("")))
+
+        LOGGER.debug("Triggering initial sematic checks for '%s'" % plugin)
+        try:
+            plugin.validate_model()
+        except:
+            self.notify("error", "Initial model validation failed.")
 
         pile = urwid.Pile(widgets)
         # FIXME why is this fixed?
@@ -206,6 +217,10 @@
         self.register_hotkey(["esc"], self.quit)
         self.register_hotkey(["q"], self.quit)
 
+    def notify(self, category, msg):
+        LOGGER.info("UI notification (%s): %s" % (category, msg))
+        # FIXME do notification
+
     def popup(self, title, msg, buttons=None):
         LOGGER.debug("Launching popup")
 
diff --git a/scripts/tui/src/ovirt/node/widgets.py b/scripts/tui/src/ovirt/node/widgets.py
index bab83c2..2a01c82 100644
--- a/scripts/tui/src/ovirt/node/widgets.py
+++ b/scripts/tui/src/ovirt/node/widgets.py
@@ -163,7 +163,7 @@
             self._edit_attrmap.set_attr_map({None: ""})
         else:
             self._edit_attrmap.set_attr_map({
-                None: "plugin.widget.disabled"
+                None: "plugin.widget.entry.disabled"
                 })
 
     def __init__(self, label, value=None, mask=None):
@@ -199,6 +199,9 @@
 class Button(urwid.WidgetWrap):
     signals = ["click"]
 
+    selectable = lambda self: True
+
+
     def __init__(self, label):
         self._button = urwid.Button(label)
 
@@ -214,6 +217,15 @@
 
         super(Button, self).__init__(self._padding)
 
+    def enable(self, is_enabled):
+        self.selectable = lambda: is_enabled
+        if is_enabled:
+            self._button_attrmap.set_attr_map({None: ""})
+        else:
+            self._button_attrmap.set_attr_map({
+                None: "plugin.widget.button.disabled"
+                })
+
 
 class Divider(urwid.WidgetWrap):
     def __init__(self, char=u" "):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7223a1620cdea94df386bd76b9d601fd12c4df7e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list