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 496FD1FF173 for ; Mon, 25 Nov 2024 12:29:19 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AB28311169; Mon, 25 Nov 2024 12:29:11 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 25 Nov 2024 12:27:15 +0100 Message-ID: <20241125112900.988346-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125112900.988346-1-c.heiss@proxmox.com> References: <20241125112900.988346-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 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 v2 1/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" .. effectively de-duplicating the struct, which currently is defined in both the auto-installer and the tui-installer separately. Signed-off-by: Christoph Heiss --- Changes v1 -> v2: * no changes .../src/bin/proxmox-auto-installer.rs | 5 +- proxmox-auto-installer/src/utils.rs | 23 --------- proxmox-installer-common/src/setup.rs | 23 +++++++++ .../src/views/install_progress.rs | 50 +++++-------------- 4 files changed, 39 insertions(+), 62 deletions(-) diff --git a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs index 4b9d73d..151694f 100644 --- a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs +++ b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs @@ -10,7 +10,8 @@ use std::{ use proxmox_installer_common::{ http, setup::{ - installer_setup, read_json, spawn_low_level_installer, LocaleInfo, RuntimeInfo, SetupInfo, + installer_setup, read_json, spawn_low_level_installer, LocaleInfo, LowLevelMessage, + RuntimeInfo, SetupInfo, }, FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME, RUNTIME_DIR, }; @@ -19,7 +20,7 @@ use proxmox_auto_installer::{ answer::{Answer, FirstBootHookInfo, FirstBootHookSourceMode}, log::AutoInstLogger, udevinfo::UdevInfo, - utils::{parse_answer, LowLevelMessage}, + utils::parse_answer, }; static LOGGER: AutoInstLogger = AutoInstLogger; diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index ea7176a..2be81ea 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -441,26 +441,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 1a9a71c..e22ce4e 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -551,3 +551,26 @@ pub struct InstallConfig { pub first_boot: InstallFirstBootSetup, } + +#[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 4b4a418..585877c 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| { @@ -245,39 +244,16 @@ 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::*; use std::env; - fn next_msg(reader: &mut R) -> Option { + fn next_msg(reader: &mut R) -> Option { 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) => { eprintln!("invalid json: '{err}'"); @@ -310,7 +286,7 @@ mod tests { assert_eq!( next_msg(&mut reader), - Some(UiMessage::Prompt { + Some(LowLevelMessage::Prompt { query: "Reply anything?".to_owned() }), ); @@ -324,7 +300,7 @@ mod tests { assert_eq!( next_msg(&mut reader), - Some(UiMessage::Info { + Some(LowLevelMessage::Info { message: "Test Message - got ok".to_owned() }), ); @@ -332,7 +308,7 @@ mod tests { for i in (1..=1000).step_by(3) { assert_eq!( next_msg(&mut reader), - Some(UiMessage::Progress { + Some(LowLevelMessage::Progress { ratio: (i as f32) / 1000., text: format!("foo {i}"), }), @@ -341,7 +317,7 @@ mod tests { assert_eq!( next_msg(&mut reader), - Some(UiMessage::Finished { + Some(LowLevelMessage::Finished { state: "ok".to_owned(), message: "Installation finished - reboot now?".to_owned(), }), -- 2.47.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel