[node-patches] Change in ovirt-node[master]: [DRAFT] ui: Installer

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Jan 15 13:39:38 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: [DRAFT] ui: Installer
......................................................................

[DRAFT] ui: Installer

Change-Id: I28b163d626448f29d24addd0024d930dd2528156
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/installer/boot_device_page.py
M scripts/tui/src/ovirt/node/installer/installation_device_page.py
M scripts/tui/src/ovirt/node/installer/keyboard_page.py
M scripts/tui/src/ovirt/node/installer/password_page.py
M scripts/tui/src/ovirt/node/installer/progress_page.py
M scripts/tui/src/ovirt/node/installer/welcome_page.py
6 files changed, 103 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/45/11045/1

diff --git a/scripts/tui/src/ovirt/node/installer/boot_device_page.py b/scripts/tui/src/ovirt/node/installer/boot_device_page.py
index 3c83212..15e100f 100644
--- a/scripts/tui/src/ovirt/node/installer/boot_device_page.py
+++ b/scripts/tui/src/ovirt/node/installer/boot_device_page.py
@@ -26,8 +26,7 @@
 
 
 class Plugin(plugins.NodePlugin):
-    _model = None
-    _elements = None
+    _model = {}
 
     def name(self):
         return "Boot Device"
@@ -54,7 +53,7 @@
 
         self.widgets.add(ws)
         page = ui.Page("boot", ws)
-        page.buttons = [ui.Button("button.quit", "Quit"),
+        page.buttons = [ui.QuitButton("button.quit", "Quit"),
                         ui.Button("button.back", "Back"),
                         ui.Button("button.next", "Continue")]
         return page
@@ -66,14 +65,15 @@
                 for name, d in all_devices]
 
     def on_change(self, changes):
-        if "button.next" in changes:
-            self._elements["label.details"].set_device(changes["button.next"])
+        if changes.contains_any(["boot.device"]):
+            self._model.update(changes)
 
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
         if changes.contains_any(["button.next", "boot.device"]):
-            self.transaction = "a"
             self.application.ui.navigate.to_next_plugin()
+        elif changes.contains_any(["button.back"]):
+            self.application.ui.navigate.to_previous_plugin()
 
 
 class DeviceDetails(ui.Label):
@@ -90,4 +90,4 @@
                  ("Size", ""),
                  ("Description", ""),
                  ]"""
-        self.set_text("%s" % device)
+        self.text("%s" % device)
diff --git a/scripts/tui/src/ovirt/node/installer/installation_device_page.py b/scripts/tui/src/ovirt/node/installer/installation_device_page.py
index edd3fec..4362c8e 100644
--- a/scripts/tui/src/ovirt/node/installer/installation_device_page.py
+++ b/scripts/tui/src/ovirt/node/installer/installation_device_page.py
@@ -27,8 +27,7 @@
 
 
 class Plugin(plugins.NodePlugin):
-    _model = None
-    _elements = None
+    _model = {}
 
     def name(self):
         return "Data Device"
@@ -55,7 +54,7 @@
 
         self.widgets.add(ws)
         page = ui.Page("device", ws)
-        page.buttons = [ui.Button("button.quit", "Quit"),
+        page.buttons = [ui.QuitButton("button.quit", "Quit"),
                         ui.Button("button.back", "Back"),
                         ui.Button("button.next", "Continue")]
         return page
@@ -67,11 +66,12 @@
                 for name, d in all_devices]
 
     def on_change(self, changes):
-        if "button.next" in changes:
-            self._elements["label.details"].set_device(changes["button.next"])
+        if changes.contains_any(["installation.device"]):
+            self._model.update(changes)
 
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
         if changes.contains_any(["installation.device", "button.next"]):
-            self.transaction = "a"
             self.application.ui.navigate.to_next_plugin()
+        elif changes.contains_any(["button.back"]):
+            self.application.ui.navigate.to_previous_plugin()
diff --git a/scripts/tui/src/ovirt/node/installer/keyboard_page.py b/scripts/tui/src/ovirt/node/installer/keyboard_page.py
index 557c823..ba73e54 100644
--- a/scripts/tui/src/ovirt/node/installer/keyboard_page.py
+++ b/scripts/tui/src/ovirt/node/installer/keyboard_page.py
@@ -27,7 +27,6 @@
 
 class Plugin(plugins.NodePlugin):
     _model = {}
-    _elements = None
 
     def name(self):
         return "Keyboard"
@@ -46,10 +45,11 @@
         ws = [ui.Header("header[0]", "Keyboard Layout Selection"),
               ui.Table("keyboard.layout", "Available Keyboard Layouts",
                        "", kbd.available_layouts()),
+              ui.Label("label[0]", "(Hit return to select a layout)")
               ]
         self.widgets.add(ws)
         page = ui.Page("keyboard", ws)
-        page.buttons = [ui.Button("button.quit", "Quit"),
+        page.buttons = [ui.QuitButton("button.quit", "Quit"),
                         ui.Button("button.next", "Continue")]
         return page
 
@@ -60,5 +60,8 @@
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
         if changes.contains_any(["keyboard.layout", "button.next"]):
-            self.transaction = "a"
+            # Apply kbd layout directly so it takes affect on the password page
+            kbd = utils.Keyboard()
+            self.dry_or(lambda: kbd.set_layout(changes["keyboard.layout"]))
+
             self.application.ui.navigate.to_next_plugin()
diff --git a/scripts/tui/src/ovirt/node/installer/password_page.py b/scripts/tui/src/ovirt/node/installer/password_page.py
index 30327a2..2f66faf 100644
--- a/scripts/tui/src/ovirt/node/installer/password_page.py
+++ b/scripts/tui/src/ovirt/node/installer/password_page.py
@@ -26,8 +26,7 @@
 
 
 class Plugin(plugins.NodePlugin):
-    _model = None
-    _elements = None
+    _model = {}
 
     def name(self):
         return "Console Password"
@@ -51,16 +50,18 @@
               ]
         self.widgets.add(ws)
         page = ui.Page("password", ws)
-        page.buttons = [ui.Button("button.quit", "Quit"),
+        page.buttons = [ui.QuitButton("button.quit", "Quit"),
                         ui.Button("button.back", "Back"),
                         ui.Button("button.next", "Install")]
         return page
 
     def on_change(self, changes):
-        pass
+        if changes.contains_any(["root.password_confirmation"]):
+            self._model.update(changes)
 
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
         if changes.contains_any(["root.password_confirmation", "button.next"]):
-            self.transaction = "a"
             self.application.ui.navigate.to_next_plugin()
+        elif changes.contains_any(["button.back"]):
+            self.application.ui.navigate.to_previous_plugin()
diff --git a/scripts/tui/src/ovirt/node/installer/progress_page.py b/scripts/tui/src/ovirt/node/installer/progress_page.py
index c2dfab7..472fad4 100644
--- a/scripts/tui/src/ovirt/node/installer/progress_page.py
+++ b/scripts/tui/src/ovirt/node/installer/progress_page.py
@@ -19,6 +19,7 @@
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
 from ovirt.node import plugins, ui, utils
+from ovirt.node.config import defaults
 import threading
 import time
 
@@ -29,8 +30,6 @@
 
 
 class Plugin(plugins.NodePlugin):
-    _model = None
-    _elements = None
     _worker = None
 
     def __init__(self, application):
@@ -44,7 +43,7 @@
         return 60
 
     def model(self):
-        return self._model or {}
+        return {}
 
     def validators(self):
         return {}
@@ -83,8 +82,8 @@
         time.sleep(0.3)  # Give the UI some time to build
         transaction = self.__build_transaction()
 
-        progressbar = self.progress_plugin._elements["progressbar"]
-        log = self.progress_plugin._elements["log"]
+        progressbar = self.progress_plugin.widgets["progressbar"]
+        log = self.progress_plugin.widgets["log"]
         log_lines = []
 
         txlen = len(transaction)
@@ -104,27 +103,39 @@
             log.text("EXECPTION: %s" % e)
 
     def __build_transaction(self):
-        self.__update_defaults_from_models()
-
         tx = utils.Transaction("Installation")
 
+        app= self.progress_plugin.application
+        tx.append(self.UpdateDefaultsFromModels(app))
         tx.append(self.PartitionAndFormat())
         tx.append(self.SetPassword("the-password"))
         tx.append(self.InstallBootloader())
+        tx.append(self.SetKeyboardLayout("da-layout"))
 
         return tx
 
-    def __update_defaults_from_models(self):
-        config = {}
-        app = self.progress_plugin.application
-        for pname, plugin in app.plugins().items():
-            self.logger.debug("Config for %s" % (pname))
-            try:
-                model = plugin.model()
-                config.update(model)
-                self.logger.debug("Merged config: %s" % (model))
-            except NotImplementedError:
-                self.logger.debug("Merged no config.")
+    class UpdateDefaultsFromModels(utils.Transaction.Element):
+        title = "Write configuration file"
+
+        def __init__(self, application):
+            super(InstallerThread.UpdateDefaultsFromModels, self).__init__()
+            self.application = application
+
+        def prepare(self):
+            config = {}
+            for pname, plugin in self.application.plugins().items():
+                self.logger.debug("Config for page %s" % (pname))
+                try:
+                    model = plugin.model()
+                    config.update(model)
+                    self.logger.debug("Merged config: %s" % (model))
+                except NotImplementedError:
+                    self.logger.debug("Merged no config.")
+            self.logger.debug("Final config: %s" % config)
+
+        def commit(self):
+            model = defaults.Storage()
+            raise NotImplementedError
 
     class PartitionAndFormat(utils.Transaction.Element):
         title = "Partitioning and Creating File Systems"
@@ -158,3 +169,14 @@
             boot_setup = install.ovirt_boot_setup()
             if not boot_setup:
                 raise RuntimeError("Failed to set install bootloader")
+
+    class SetKeyboardLayout(utils.Transaction.Element):
+        title = "Setting keyboard layout to '{kbd_layout}'"
+
+        def __init__(self, kbd_layout):
+            super(InstallerThread.SetKeyboardLayout, self).__init__()
+            self.kbd_layout = kbd_layout
+            self.title = self.title.format(kbd_layout=kbd_layout)
+
+        def commit(self):
+            utils.Keyboard().set_layout(self.kbd_layout)
diff --git a/scripts/tui/src/ovirt/node/installer/welcome_page.py b/scripts/tui/src/ovirt/node/installer/welcome_page.py
index 26aaffa..0f06be3 100644
--- a/scripts/tui/src/ovirt/node/installer/welcome_page.py
+++ b/scripts/tui/src/ovirt/node/installer/welcome_page.py
@@ -18,6 +18,8 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
+from ovirt.node import plugins, ui, utils
+import os
 
 """
 Welcome page of the installer
@@ -29,14 +31,12 @@
 NOTE: Each page stores the information in the config page
 NOTE II: Or shall we build the transactions per page?
 """
-from ovirt.node import plugins, ui
 
 
 class Plugin(plugins.NodePlugin):
     """The welcome page plugin
     """
     _model = {}
-    _elements = None
 
     def name(self):
         return "Welcome"
@@ -51,12 +51,11 @@
         return {}
 
     def ui_content(self):
-        ws = [ui.Button("button.install", "Install %s" %
-                        str(self.application.product)),
-              ]
+        ws = [ui.Header("header[0]", "Installation")]
+        ws.append(self.___installation_option())
         self.widgets.add(ws)
         page = ui.Page("welcome", ws)
-        page.buttons = [ui.Button("button.quit", "Quit")]
+        page.buttons = [ui.QuitButton("button.quit", "Quit")]
         return page
 
     def on_change(self, changes):
@@ -64,5 +63,37 @@
 
     def on_merge(self, effective_changes):
         if "button.install" in effective_changes:
-            self.transaction = "a"
             self.application.ui.navigate.to_next_plugin()
+
+    def ___installation_option(self):
+        if self.application.args.dry:
+            return ui.Button("button.install", "Install Hypervisor (dry)")
+
+        media = utils.system.InstallationMedia()
+        installed = utils.system.InstalledMedia()
+
+        has_hostvg = os.path.exists("/dev/HostVG")
+        has_root = os.path.exists("/dev/disk/by-label/ROOT")
+
+        if has_hostvg and has_root:
+            return ui.Label("Major version upgrades are unsupported, " +
+                            "uninstall existing version first")
+
+        if has_hostvg:
+            try:
+                if media > installed:
+                    return ui.Button("button.upgrade",
+                                     "Upgrade %s to %s" % (media, installed))
+                elif media < installed:
+                    return ui.Button("button.downgrade",
+                                     "Downgrade %s to %s" % (media,
+                                                             installed))
+                return ui.Button("button.reinstall",
+                                 "Reinstall %s" % installed)
+            except:
+                self.logger.error("Unable to get version numbers for " +
+                                  "upgrade, invalid installation or media")
+                return ui.Label("Invalid installation, please reboot from " +
+                                "media and choose Reinstall")
+
+        return ui.Button("button.install", "Install Hypervisor %s" % media)


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

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