def __run(self): app = self.progress_plugin.application reboot_button = self.progress_plugin.widgets["action.reboot"] progressbar = self.progress_plugin.widgets["progressbar"] log = self.progress_plugin.widgets["log"] log_lines = ["Starting ..."] captured_stderr = [] try: self.ui_thread.call(lambda: log.text("\n".join(log_lines))) self.ui_thread.call(lambda: reboot_button.enabled(False)) self.ui_thread.call(lambda: app.ui.hotkeys_enabled(False)) transaction = self.__build_transaction() txlen = len(transaction) 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)) self.ui_thread.call(lambda: log.text("\n".join(log_lines))) def do_commit(): tx_element.commit() with console.CaptureOutput() as captured: # Sometimes a tx_element is wrapping some code that # writes to stdout/stderr which scrambles the screen, # therefore we are capturing this self.progress_plugin.dry_or(do_commit) if captured.stderr.getvalue(): captured_stderr.append(captured.stderr.getvalue()) log_lines[-1] = "%s (Done)" % log_lines[-1] 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: self.logger.exception("Installer transaction failed") msg = "Exception: %s" % repr(e) self.ui_thread.call(lambda: log.text(msg)) finally: pass self.ui_thread.call(lambda: reboot_button.enabled(True)) self.ui_thread.call(lambda: app.ui.hotkeys_enabled(True)) if captured_stderr: self.ui_thread.call( lambda: log.text("Stderr: %s" % str(captured_stderr)))
def run(self): try: self.progress_plugin.widgets["action.reboot"].enabled(False) time.sleep(0.3) # Give the UI some time to build transaction = self.__build_transaction() progressbar = self.progress_plugin.widgets["progressbar"] log = self.progress_plugin.widgets["log"] log_lines = [] txlen = len(transaction) 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)) def do_commit(): tx_element.commit() with console.CaptureOutput() as captured: # Sometimes a tx_element is wrapping some code that # writes to stdout/stderr which scrambles the screen, # 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)) except Exception as e: msg = "Exception: %s" % repr(e) self.logger.debug(msg, exc_info=True) log.text(msg) finally: self.progress_plugin.widgets["action.reboot"].enabled(True) if captured.stderr.getvalue(): se = captured.stderr.getvalue() if se: log.text("Stderr: %s" % se) # We enforce a redraw, because this the non-mainloop thread self.progress_plugin.application.ui.force_redraw()
def __run_transaction(self): try: self.add_update("Checking pre-conditions ...") for idx, tx_element in self.transaction.step(): txt = "(%s/%s) %s" % (idx + 1, len(self.transaction), tx_element.title) self.add_update(txt) with console.CaptureOutput() as captured: # Sometimes a tx_element is wrapping some code that # writes to stdout/stderr which scrambles the screen, # therefore we are capturing this self.plugin.dry_or(lambda: tx_element.commit()) self.add_update("\nAll changes were applied successfully.") except Exception as e: self.logger.info("An exception during the transaction: %s" % e, exc_info=True) self.add_update("\nAn error occurred while applying the changes:") self.add_update("%s" % e) if captured.stderr.getvalue(): se = captured.stderr.getvalue() if se: self.add_update("Stderr: %s" % se)
def do_services(cmd, services): with console.CaptureOutput(): for name in services: system.service(name, cmd, False)