[node-patches] Change in ovirt-node[master]: Screen can be suspended, validation

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


Fabian Deutsch has uploaded a new change for review.

Change subject: Screen can be suspended, validation
......................................................................

Screen can be suspended, validation

Change-Id: I3893e6f323e0ab87fccc5d476c3c9d65f3de6c76
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/README
M scripts/tui/src/ovirt/node/plugins/example.py
M scripts/tui/src/ovirt/node/tui.py
R scripts/tui/src/ovirt/node/valid.py
4 files changed, 45 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/65/9865/1

diff --git a/scripts/tui/README b/scripts/tui/README
index 1dd35bc..3230304 100644
--- a/scripts/tui/README
+++ b/scripts/tui/README
@@ -1,6 +1,6 @@
 A simple system to build a TUI (based on urwid) by plugins.
 
-$ sudo yum install python python-urwind
+$ sudo yum install python python-urwid
 $ cd src
 $ ./app
 
diff --git a/scripts/tui/src/ovirt/node/plugins/example.py b/scripts/tui/src/ovirt/node/plugins/example.py
index 366a386..9eeca4f 100644
--- a/scripts/tui/src/ovirt/node/plugins/example.py
+++ b/scripts/tui/src/ovirt/node/plugins/example.py
@@ -4,7 +4,7 @@
 import logging
 
 import ovirt.node.plugins
-import ovirt.node.pattern
+import ovirt.node.valid
 from ovirt.node.plugins import Header, Entry, Password
 
 LOGGER = logging.getLogger(__name__)
@@ -30,11 +30,12 @@
         return self._model
 
     def validators(self):
+        nospace = lambda v: "No space allowed." if " " in v else None
+
         return {
-                "foo.hostname": ovirt.node.pattern.ValidHostname(),
-                "foo.port": ovirt.node.pattern.Number(),
-                "foo.password": lambda v: "No space allowed." \
-                                          if " " in v else None
+                "foo.hostname": ovirt.node.valid.Hostname(),
+                "foo.port": ovirt.node.valid.Number(),
+                "foo.password": nospace
             }
 
     def ui_content(self):
diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/tui.py
index 691b16c..af2c8b6 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -214,21 +214,16 @@
 
     def suspended(self):
         """Supspends the screen to do something in the foreground
-        TODO resizing is curently broken after resuming
         """
         class SuspendedScreen(object):
             def __init__(self, loop):
                 self.__loop = loop
 
             def __enter__(self):
-                self.screen = urwid.raw_display.Screen()
-                self.screen.stop()
+                self.__loop.screen.stop()
 
             def __exit__(self, a, b, c):
-                self.screen.start()
-                # Hack to force a screen refresh
-                self.__loop.process_input(["up"])
-                self.__loop.process_input(["down"])
+                self.__loop.screen.start()
         return SuspendedScreen(self.__loop)
 
     def register_plugin(self, title, plugin):
diff --git a/scripts/tui/src/ovirt/node/pattern.py b/scripts/tui/src/ovirt/node/valid.py
similarity index 63%
rename from scripts/tui/src/ovirt/node/pattern.py
rename to scripts/tui/src/ovirt/node/valid.py
index 24f44ca..b59f551 100644
--- a/scripts/tui/src/ovirt/node/pattern.py
+++ b/scripts/tui/src/ovirt/node/valid.py
@@ -10,7 +10,7 @@
 LOGGER = logging.getLogger(__name__)
 
 
-class RegexValidationWrapper(str):
+class RegexValidator(str):
     # pattern defined by subclass
     # description defined by subclass
     __exception_msg = "The field must contain {description}."
@@ -22,7 +22,7 @@
         return True
 
 
-class Text(RegexValidationWrapper):
+class Text(RegexValidator):
     description = "anything"
     pattern = ".*"
 
@@ -32,32 +32,61 @@
             self.description += " (min. %d chars)" % min_length
 
 
-class Number(RegexValidationWrapper):
+class Number(RegexValidator):
     description = "a number"
     pattern = "^\d+$"
 
 
-class NoSpaces(RegexValidationWrapper):
+class NoSpaces(RegexValidator):
     description = "a string without spaces"
     pattern = "^\S*$"
 
 
-class ValidHostname(RegexValidationWrapper):
+class Hostname(RegexValidator):
     description = "a valid hostname"
     pattern = ("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)" +
                "*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$")
 
 
-class ValidIPv4Address(RegexValidationWrapper):
+class IPv4Address(RegexValidator):
     description = "a valid IPv4 address"
     pattern = ("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.)" +
                "{3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")
 
 
-class ValidIPv6Address(RegexValidationWrapper):
+class IPv6Address(RegexValidator):
     description = "a valid IPv6 address"
     pattern = ("/^(?>(?>([a-f0-9]{1,4})(?>:(?1)){7}|(?!(?:.*[a-f0-9](?>:|$" +
                ")){7,})((?1)(?>:(?1)){0,5})?::(?2)?)|(?>(?>(?1)(?>:(?1)){5}" +
                ":|(?!(?:.*[a-f0-9]:){5,})(?3)?::(?>((?1)(?>:(?1)){0,3}):)?)?" +
                "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?" +
                "4)){3}))$/iD")
+
+
+class OrCombinedValidator(str):
+    _validators = None
+
+    def __init__(self, validators):
+        self._validators = validators
+
+    def __call__(self, value):
+        is_valid = False
+        msgs = []
+
+        for v in self._validators:
+            LOGGER.debug(v)
+            try:
+                msg = v(value)
+                if msg:
+                    msgs.append(msg)
+                else:
+                    is_valid = True
+                    break
+            except ovirt.node.plugins.InvalidData as e:
+                msgs.append(str(e))
+
+        if not is_valid:
+            msg = ", ".join(msgs)
+            raise ovirt.node.plugins.InvalidData(msg)
+
+        return True


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

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