[node-patches] Change in ovirt-node[master]: plugin: Track invalid changes

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


Fabian Deutsch has uploaded a new change for review.

Change subject: plugin: Track invalid changes
......................................................................

plugin: Track invalid changes

To allow a correct and quick validation check on the plugins changes.

Change-Id: I2113d56ed69ad73883178acf458ff04db8e92cb5
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins.py
M scripts/tui/src/ovirt/node/ui/builder.py
2 files changed, 16 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/70/9970/1

diff --git a/scripts/tui/src/ovirt/node/plugins.py b/scripts/tui/src/ovirt/node/plugins.py
index 2ae6d3c..ac1225f 100644
--- a/scripts/tui/src/ovirt/node/plugins.py
+++ b/scripts/tui/src/ovirt/node/plugins.py
@@ -71,6 +71,7 @@
     def __init__(self, application):
         super(NodePlugin, self).__init__()
         self.__changes = {}
+        self.__invalid_changes = {}
         self.application = application
         self.sig_valid = self.register_signal("valid")
 
@@ -227,11 +228,15 @@
                 self.validate(change)
             self.on_change(change)
         except exceptions.InvalidData as e:
+            self.__invalid_changes.update(change)
             self.sig_valid.emit(False)
             raise e
         self.__changes.update(change)
         self.logger.debug("Sum of all UI changes up to now: %s" % \
                           self.__changes)
+        self.__invalid_changes = {k: v
+                                  for k, v in self.__invalid_changes.items()
+                                  if k not in change}
         self.sig_valid.emit(True)
         return True
 
@@ -291,6 +296,14 @@
         return self.__effective_changes() if only_effective_changes \
                                           else self.__changes
 
+    def is_valid_changes(self):
+        """If all changes are valid or not
+        Returns:
+            If there are no invalid changes - so all changes valid
+        """
+        self.logger.debug("Invalid changes: %s" % self.__invalid_changes)
+        return len(self.__invalid_changes) == 0
+
     def __effective_changes(self):
         """Calculates the effective changes, so changes which change the
         value of a path.
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 4710d51..245dbad 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -194,7 +194,9 @@
     widget = ui.widgets.Button(item.text())
 
     if itemtype in [ui.SaveButton]:
-        plugin.sig_valid.connect(lambda w, v: widget.enable(v))
+        def on_valid_cb(w, v):
+            widget.enable(plugin.is_valid_changes())
+        plugin.sig_valid.connect(on_valid_cb)
 
     def on_widget_click_cb(widget, data=None):
         LOGGER.debug("Button click: %s" % {"path": path, "widget": widget})


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

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