def process_import(self): logging.debug("Importing key") existing_password = self.ui.existing_password.text() if self.ui.is_key_encrypted.isChecked() \ else None password = self.ui.new_password.text() key_data = None if self.ui.import_from_file.isChecked() else \ bytes(self.ui.key_data.toPlainText(), "utf8") filepath = None if self.ui.paste_as_plain_text.isChecked() else \ self.ui.key_file_path.text() if self.is_private: try: logging.debug("Importing as private key") self.key_manager.import_private_key( new_password=password, existing_password=existing_password, key_data=key_data, alias=self.ui.key_alias.text(), filepath=filepath) self.close() except KeyImportError as e: show_user_error_window(self, str(e)) else: try: self.key_manager.import_public_key( key_data=key_data, alias=self.ui.key_alias.text(), filepath=filepath) self.close() except KeyImportError as e: show_user_error_window(self, str(e))
def check_input(self): if self.is_private: passwd = self.ui.new_password.text() confirm = self.ui.confirm_password.text() if passwd != confirm: show_user_error_window( self, "Password and confirmation do not match!") return if len(passwd) < PASSWORD_LENGTH: show_user_error_window( self, "Password length must be at least %d symbols" % PASSWORD_LENGTH) return if self.ui.import_from_file.isChecked(): filepath = self.ui.key_file_path.text() if not path.exists(filepath): show_user_error_window(self, "Key file is not found") return if self.ui.paste_as_plain_text.isChecked() and len( self.ui.key_data.toPlainText().strip(" ")) == 0: show_user_error_window(self, "Please paste key data!") return try: self.process_import() except Exception as e: logging.error(e) show_user_error_window(self, e)
def process_install_error(self, code, msg): """ Install error signal handler :param code: :param msg: :return: """ log.error("Install error signal received. Code: %s Message: %s" % (str(code), str(msg))) util.show_user_error_window(self, msg)
def process_update_result(self, is_success, msg=""): self.working = False if is_success: QM.information(self, "Update successful", "Update completed successfully!", QM.Ok) self.close() else: self.lock_form(False) show_user_error_window(self, "UPDATE ERROR: %s " % msg) self.update_els_visibility()
def form_errors_found(self): log.debug("Verifying user input") log.debug("Checking image file") if not os.path.exists(self.ui.source_file.text()): show_user_error_window(self, "Source file not found...") return True if not os.path.isdir(self.ui.path_to_dest.text()): show_user_error_window(self, "Destination directory does not exist") return True required_fields = [] if self.ui.private_key_password.text().strip(" ") == "": required_fields.append("Private key password") if self.ui.private_key_password.text().strip(" ") == "": required_fields.append("Island version") if self.ui.private_key_password.text().strip(" ") == "": required_fields.append("Image version") if len(required_fields) > 0: show_user_error_window( self, "Please fill the required fields: %s" % " ".join(required_fields)) return True if self.ui.select_private_key.count() == 0: show_user_error_window( self, "You have not created your key yet. Create a key and try again" ) return True return False
def run_update(self): """ Launches VM installation """ log.debug("Running update") self.on_message("Initializing islands update") self.ui.output_console.setVisible(True) if not (self.ui.opt_from_file.isChecked() or self.ui.opt_download.isChecked()): msg = "None of VM update option are selected" log.debug(msg) show_user_error_window(self, msg) return if self.island_manager.is_running(): self.on_message("Islands currently running. Shutting down...") self.island_manager.stop_island_sync(force=True) self.on_message("Islands was shut down. Now updating...") data_path = get_full_path(self.config["data_folder"]) self.lock_form() log.info("Attempting to update islands VM...") self.unknown_key_confirm_request.connect(self.untrusted_key_confirm) self.lock_form(True) self.repaint() if self.ui.opt_download.isChecked(): self.download_timeout_signal.connect(self.on_download_timeout) log.debug("Trying to import VM from %s " % self.ui.path_to_image.text()) self.working = True self.setup.run_update( on_message=self.on_message, on_complete=lambda res, opt_msg="": self.update_completed.emit( res, opt_msg), on_error=self.on_error, init_progres_bar=self.get_init_progress_bar_handler(), update_progres_bar=self.get_update_progress_bar_handler(), finalize_progres_bar=self.get_finalize_progress_bar_handler(), download=self.ui.opt_download.isChecked(), setup=self.setup, island_manager=self.island_manager, on_download_timeout=lambda: self.download_timeout_signal.emit(), magnet_link=self.ui.magnet_link.text().strip(), on_confirm_required=lambda: self.unknown_key_confirm_request.emit( ), image_path=self.ui.path_to_image.text().strip(), config=self.config, on_configuration_in_progress=lambda x: self. configuration_in_progress_signal.emit(x), data_path=data_path)
def proceed_vm_install(self): """ Launches VM installation """ data_path = self.ui.data_folder_path.text() log.info("Attempting to installing islands VM...") self.ui.vm_install_output_console.setVisible(True) self.set_enabled_vm_install_options(False) self.unknown_key_confirm_request.connect(self.untrusted_key_confirm) self.ui.btn_install_islands.setEnabled(False) self.ui.btn_select_data_path.setEnabled(False) self.vm_install_in_progress = True if not (self.ui.opt_vm_local.isChecked() or self.ui.opt_download.isChecked()): msg = "None of VM install option are selected" log.debug(msg) util.show_user_error_window(self, msg) return if self.ui.opt_download.isChecked(): self.download_timeout_signal.connect(self.on_download_timeout) log.debug("Trying to import VM from %s " % self.ui.path_islands_vm.text()) self.setup.run_vm_installer( on_message=self.get_on_message_handler(console=1), on_complete=lambda is_success, opt_msg="": self. vm_install_completed.emit(is_success, opt_msg), on_error=self.get_on_error_handler(console=1), init_progres_bar=self.get_init_progress_bar_handler(console=1), update_progres_bar=self.get_update_progress_bar_handler(console=1), finalize_progres_bar=self.get_finalize_progress_bar_handler( console=1), download=not self.ui.opt_vm_local.isChecked(), setup=self.setup, island_manager=self.island_manager, on_download_timeout=lambda: self.download_timeout_signal.emit(), magnet_link=self.ui.magnet_link.text().strip(), on_configuration_in_progress=lambda x: self. configuration_in_progress_signal.emit(x), on_confirm_required=lambda: self.unknown_key_confirm_request.emit( ), image_path=self.ui.path_islands_vm.text().strip(), config=self.config, data_path=data_path)
def create_torrent(self): log.debug("Attempting to create torrent") path_to_data = self.ui.path_to_data.text().strip(" ") if len(path_to_data) == 0: log.debug("No file selected") show_user_error_window(self, "No file or directory selected") return try: self.torrent_manager.create_torrent( os.path.abspath(path_to_data), self.ui.chk_start_seeding.isChecked()) log.debug("Torrent created.") self.close() except Exception as e: msg = "Error creating torrent: %s" % str(e) log.error(msg) log.exception(e) raise e
def process_delete_vm_request(self): res = QM.warning( self, "Delete Island", "This is going to unregister Island virtual machine, " "wipe its files and reset VM settings to default. " "Data files will be saved. Continue?", QM.Yes | QM.No) if res == QM.Yes: try: if self.island_manager.is_running(): self.island_manager.stop_island_sync(force=True) time.sleep(3) self.setup.delete_islands_vm() self.setup.reset_vm_config() self.refresh_vm_info() show_notification(self, "Island virtual machine has been deleted") except Exception as e: errmsg = "Island deletion error: %s " % str(e) log.error(errmsg) log.exception(e) show_user_error_window(self, errmsg)
def delete_torrent(self, infohash, name): dialog = QMessageBox(self) dialog.setIcon(QMessageBox.Warning) dialog.setText("Delete torrent") dialog.setInformativeText("The torrent %s and all its metadata will be deleted" \ "\nWould you like to delete torrent data as well?" % name) dialog.addButton(QMessageBox.Cancel) dialog.addButton(QMessageBox.No) dialog.addButton(QMessageBox.Yes) dialog.setDefaultButton(QMessageBox.No) res = dialog.exec() if res == QMessageBox.Cancel or not (res == QMessageBox.Yes or res == QMessageBox.No): log.debug("Cancel torrent deletion") return try: log.debug("Deleting torrent: %s %s" % (infohash, name)) self.torrent_manager.delete_torrent(infohash, (res == QMessageBox.Yes)) except Exception as e: msg = "Error deleting torrent %s " % str(e) log.error(msg) log.exception(e) show_user_error_window(self, msg)
def on_error(self, msg): self.ui.lbl_action.setText( "ERROR! Authoring process has not been finished") self.ui.lbl_action.setStyleSheet('color: "red"') show_user_error_window(self, msg)