[node-patches] Change in ovirt-node[master]: installer: UIThreadConnection in installer thread

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Mar 13 16:08:19 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: installer: UIThreadConnection in installer thread
......................................................................

installer: UIThreadConnection in installer thread

Use the new helper class to interact with the UI.

rhbz#920049

Change-Id: I099a1fbb9106d5501c1f78c6274730b4801ccaf3
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/installer/progress_page.py
1 file changed, 29 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/18/13018/1

diff --git a/scripts/tui/src/ovirt/node/installer/progress_page.py b/scripts/tui/src/ovirt/node/installer/progress_page.py
index 88a0e08..b28a2f5 100644
--- a/scripts/tui/src/ovirt/node/installer/progress_page.py
+++ b/scripts/tui/src/ovirt/node/installer/progress_page.py
@@ -22,7 +22,6 @@
 from ovirt.node.config import defaults
 from ovirt.node.utils import console
 import threading
-import time
 
 
 """
@@ -75,6 +74,8 @@
 
 
 class InstallerThread(threading.Thread):
+    ui_thread = None
+
     def __init__(self, progress_plugin):
         super(InstallerThread, self).__init__()
         self.progress_plugin = progress_plugin
@@ -85,21 +86,30 @@
 
     def run(self):
         try:
-            self.progress_plugin.widgets["action.reboot"].enabled(False)
-            time.sleep(0.3)  # Give the UI some time to build
+            app = self.progress_plugin.application
+            self.ui_thread = app.ui.thread_connection()
+            with self.ui_thread:
+                self.__run()
+        except Exception as e:
+            self.logger.error("Error in installer thread: %s" % e)
+
+    def __run(self):
+        reboot_button = self.progress_plugin.widgets["action.reboot"]
+        progressbar = self.progress_plugin.widgets["progressbar"]
+        log = self.progress_plugin.widgets["log"]
+        log_lines = []
+
+        try:
             transaction = self.__build_transaction()
-
-            progressbar = self.progress_plugin.widgets["progressbar"]
-            log = self.progress_plugin.widgets["log"]
-            log_lines = []
-
             txlen = len(transaction)
+
+            self.ui_thread.call(lambda: reboot_button.enabled(False))
 
             for idx, tx_element in transaction.step():
                 idx += 1
                 self.logger.debug("Running %s: %s" % (idx, tx_element))
                 log_lines.append("(%s/%s) %s" % (idx, txlen, tx_element.title))
-                log.text("\n".join(log_lines))
+                self.ui_thread.call(lambda: log.text("\n".join(log_lines)))
 
                 def do_commit():
                     tx_element.commit()
@@ -110,25 +120,29 @@
                     # therefore we are capturing this
                     self.progress_plugin.dry_or(do_commit)
 
-                progressbar.current(int(100.0 / txlen * idx))
                 log_lines[-1] = "%s (Done)" % log_lines[-1]
-                log.text("\n".join(log_lines))
+
+                def update_ui():
+                    progressbar.current(int(100.0 / txlen * idx))
+                    log.text("\n".join(log_lines))
+                self.ui_thread.call(update_ui)
 
         except Exception as e:
             msg = "Exception: %s" % repr(e)
             self.logger.debug(msg, exc_info=True)
-            log.text(msg)
+            self.ui_thread.call(lambda: log.text(msg))
 
         finally:
-            self.progress_plugin.widgets["action.reboot"].enabled(True)
+            self.ui_thread.call(lambda: reboot_button.enabled(True))
 
         if captured.stderr.getvalue():
             se = captured.stderr.getvalue()
             if se:
-                log.text("Stderr: %s" % se)
+                self.ui_thread.call(lambda: log.text("Stderr: %s" % se))
 
         # We enforce a redraw, because this the non-mainloop thread
-        self.progress_plugin.application.ui.force_redraw()
+        #window.in_thread(lambda: self.progress_plugin
+        #    .application.ui.force_redraw())
 
     def __build_transaction(self):
         """Determin what kind of transaction to build


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

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