From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id BF4BA1FF38C for ; Thu, 16 May 2024 15:40:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 78812548; Thu, 16 May 2024 15:40:00 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Thu, 16 May 2024 15:39:32 +0200 Message-ID: <20240516133945.1087246-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240516133945.1087246-1-c.heiss@proxmox.com> References: <20240516133945.1087246-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.006 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer 2/6] auto, tui: move low-level installer message struct to common crate X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Signed-off-by: Christoph Heiss --- .../src/bin/proxmox-auto-installer.rs | 8 ++-- proxmox-auto-installer/src/utils.rs | 23 --------- proxmox-installer-common/src/setup.rs | 23 +++++++++ .../src/views/install_progress.rs | 48 +++++-------------- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs index 9fcec1e..e607a9c 100644 --- a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs +++ b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs @@ -8,14 +8,12 @@ use std::{ }; use proxmox_installer_common::setup::{ - installer_setup, read_json, spawn_low_level_installer, LocaleInfo, RuntimeInfo, SetupInfo, + installer_setup, read_json, spawn_low_level_installer, LocaleInfo, LowLevelMessage, + RuntimeInfo, SetupInfo, }; use proxmox_auto_installer::{ - answer::Answer, - log::AutoInstLogger, - udevinfo::UdevInfo, - utils::{parse_answer, LowLevelMessage}, + answer::Answer, log::AutoInstLogger, udevinfo::UdevInfo, utils::parse_answer, }; static LOGGER: AutoInstLogger = AutoInstLogger; diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index 202ad41..7f3688d 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -380,26 +380,3 @@ pub fn parse_answer( } Ok(config) } - -#[derive(Clone, Debug, Deserialize, PartialEq)] -#[serde(tag = "type", rename_all = "lowercase")] -pub enum LowLevelMessage { - #[serde(rename = "message")] - Info { - message: String, - }, - Error { - message: String, - }, - Prompt { - query: String, - }, - Finished { - state: String, - message: String, - }, - Progress { - ratio: f32, - text: String, - }, -} diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 64d05af..0c62bc3 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -558,3 +558,26 @@ where _ => Err(de::Error::custom("could not find file system: {de_fs}")), } } + +#[derive(Clone, Debug, Deserialize, PartialEq)] +#[serde(tag = "type", rename_all = "lowercase")] +pub enum LowLevelMessage { + #[serde(rename = "message")] + Info { + message: String, + }, + Error { + message: String, + }, + Prompt { + query: String, + }, + Finished { + state: String, + message: String, + }, + Progress { + ratio: f32, + text: String, + }, +} diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs index 6453426..11b12f0 100644 --- a/proxmox-tui-installer/src/views/install_progress.rs +++ b/proxmox-tui-installer/src/views/install_progress.rs @@ -4,7 +4,6 @@ use cursive::{ views::{Dialog, DummyView, LinearLayout, PaddedView, ProgressBar, TextView}, CbSink, Cursive, }; -use serde::Deserialize; use std::{ fs::File, io::{BufRead, BufReader, Write}, @@ -14,7 +13,7 @@ use std::{ }; use crate::{abort_install_button, prompt_dialog, InstallerState}; -use proxmox_installer_common::setup::{spawn_low_level_installer, InstallConfig}; +use proxmox_installer_common::setup::{spawn_low_level_installer, InstallConfig, LowLevelMessage}; pub struct InstallProgressView { view: PaddedView, @@ -105,7 +104,7 @@ impl InstallProgressView { continue; } - let msg = match serde_json::from_str::(&line) { + let msg = match serde_json::from_str::(&line) { Ok(msg) => msg, Err(err) => { // Not a fatal error, so don't abort the installation by returning @@ -116,17 +115,17 @@ impl InstallProgressView { }; let result = match msg.clone() { - UiMessage::Info { message } => cb_sink.send(Box::new(|siv| { + LowLevelMessage::Info { message } => cb_sink.send(Box::new(|siv| { siv.add_layer(Dialog::info(message).title("Information")); })), - UiMessage::Error { message } => cb_sink.send(Box::new(|siv| { + LowLevelMessage::Error { message } => cb_sink.send(Box::new(|siv| { siv.add_layer(Dialog::info(message).title("Error")); })), - UiMessage::Prompt { query } => cb_sink.send({ + LowLevelMessage::Prompt { query } => cb_sink.send({ let writer = writer.clone(); Box::new(move |siv| Self::show_prompt(siv, &query, writer)) }), - UiMessage::Progress { ratio, text } => { + LowLevelMessage::Progress { ratio, text } => { counter.set((ratio * 100.).floor() as usize); cb_sink.send(Box::new(move |siv| { siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| { @@ -134,7 +133,7 @@ impl InstallProgressView { }); })) } - UiMessage::Finished { state, message } => { + LowLevelMessage::Finished { state, message } => { counter.set(100); cb_sink.send(Box::new(move |siv| { siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| { @@ -241,29 +240,6 @@ impl ViewWrapper for InstallProgressView { cursive::wrap_impl!(self.view: PaddedView); } -#[derive(Clone, Debug, Deserialize, PartialEq)] -#[serde(tag = "type", rename_all = "lowercase")] -enum UiMessage { - #[serde(rename = "message")] - Info { - message: String, - }, - Error { - message: String, - }, - Prompt { - query: String, - }, - Finished { - state: String, - message: String, - }, - Progress { - ratio: f32, - text: String, - }, -} - #[cfg(test)] mod tests { use super::*; @@ -292,7 +268,7 @@ mod tests { let mut line = String::new(); reader.read_line(&mut line).expect("a line"); - match serde_json::from_str::(&line) { + match serde_json::from_str::(&line) { Ok(msg) => Some(msg), Err(err) => panic!("unexpected error: '{err}'"), } @@ -300,7 +276,7 @@ mod tests { assert_eq!( next_msg(), - Some(UiMessage::Prompt { + Some(LowLevelMessage::Prompt { query: "Reply anything?".to_owned() }), ); @@ -314,7 +290,7 @@ mod tests { assert_eq!( next_msg(), - Some(UiMessage::Info { + Some(LowLevelMessage::Info { message: "Test Message - got ok".to_owned() }), ); @@ -322,7 +298,7 @@ mod tests { for i in (1..=1000).step_by(3) { assert_eq!( next_msg(), - Some(UiMessage::Progress { + Some(LowLevelMessage::Progress { ratio: (i as f32) / 1000., text: format!("foo {i}"), }), @@ -331,7 +307,7 @@ mod tests { assert_eq!( next_msg(), - Some(UiMessage::Finished { + Some(LowLevelMessage::Finished { state: "ok".to_owned(), message: "Installation finished - reboot now?".to_owned(), }), -- 2.44.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel