Changing println to proper log macros and small fixes.

This commit is contained in:
2026-05-26 17:56:02 +02:00
parent e0c6112422
commit 6b4550dc8e
10 changed files with 104 additions and 117 deletions
+12 -12
View File
@@ -18,7 +18,7 @@
Functions for working with disk layout
*/
use log;
use std::collections::HashMap;
use crate::kira_size::{KiraSize};
///
@@ -42,14 +42,14 @@ impl BlkDev {
Self {
name: name,
size: size,
sector_size: KiraSize::new(4096),
sector_size: KiraSize::new_b(4096),
}
}
pub fn from_hash_map(data: &HashMap<String, String>) -> Option<Self> {
Some(Self {
name: data.get("NAME")?.clone(),
size: KiraSize::from_str_bytes(data.get("SIZE")?)?,
sector_size: KiraSize::new(4096),
sector_size: KiraSize::new_b(4096),
})
}
/// this is blocking function
@@ -192,7 +192,7 @@ impl PartInfo {
Some(Self {
name: data.get("NAME")?.clone(),
size: KiraSize::from_str_bytes(data.get("SIZE")?)?,
start: KiraSize::new(0),
start: KiraSize::new_b(0),
fs_type: FSType::from_str(data.get("FSTYPE")?),
gpt_label: data
.get("PARTLABEL")
@@ -268,7 +268,7 @@ fn get_dev_part_blocking(dev_name: &str) -> Result<Vec<PartInfo>, String> {
/// return none if aligment is not possibe (size of partition is less than align)
pub fn align_part(size: u64, start: u64, align: u64) -> Option<(u64, u64, u64)> {
if size < align {
println!("if size < align !!!!!!!");
log::debug!("if size < align !!!!!!!");
return None;
}
@@ -283,14 +283,14 @@ pub fn align_part(size: u64, start: u64, align: u64) -> Option<(u64, u64, u64)>
// decreasing end if not align
let part_end = align_start + size;
let end_mod = part_end % align;
println!("part_end: {} end_mod: {}", part_end, end_mod);
log::debug!("part_end: {} end_mod: {}", part_end, end_mod);
let align_end = part_end - end_mod - 1;
let align_size = align_end - align_start + 1;
if align_size < align {
println!(
"if align_size < align !!!!!!! align_size: {} align: {}",
log::warn!(
"!!! align_size < align !!! align_size: {} align: {}",
align_size, align
);
return None;
@@ -316,7 +316,7 @@ impl PartLayout {
pub fn read_from_disk(dev: &BlkDev) -> Result<Self, String> {
let part_list = get_dev_part_blocking(&dev.name)?;
let parts_size = part_list.iter().fold(KiraSize::new(0), |acc, part| acc + part.size);
let parts_size = part_list.iter().fold(KiraSize::new_b(0), |acc, part| acc + part.size);
Ok(Self {
dev: dev.clone(),
empty_space: dev.size - parts_size,
@@ -351,8 +351,8 @@ impl PartLayout {
let part_name = format!("{}p{}", self.dev.name, self.part_list.len() + 1);
self.part_list.push(PartInfo {
name: part_name,
size: KiraSize::new(size),
start: KiraSize::new(start),
size: KiraSize::new_b(size),
start: KiraSize::new_b(start),
fs_type: fs_type,
gpt_label: gpt_label,
fs_label: fs_label,
@@ -360,7 +360,7 @@ impl PartLayout {
role: role,
});
self.empty_space = self.empty_space - KiraSize::new(size);
self.empty_space = self.empty_space - KiraSize::new_b(size);
self
}
+2 -21
View File
@@ -20,25 +20,6 @@
use std::ops::{Add, Sub};
pub fn format_bytes_size(size: u64) -> String {
let suffixs: [&str; 5] = ["KB", "MB", "GB", "TB", "PB"];
if size < 1000 {
format!("{}B", size)
} else {
let mut s = size as f64;
let mut idx = 0;
for i in 0..5 {
s = s / 1024.0;
idx = i;
if s < 1000.0 {
break;
}
}
format!("{:.2}{}", s, suffixs[idx])
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct KiraSize {
size_bytes: u64,
@@ -65,7 +46,7 @@ impl std::fmt::Display for KiraSize {
impl KiraSize {
pub const SUFFIXS: [&str; 5] = ["KB", "MB", "GB", "TB", "PB"];
pub fn new(size:u64) -> Self {
pub fn new_b(size:u64) -> Self {
Self { size_bytes: size }
}
pub fn new_kb(size:u64) -> Self {
@@ -104,7 +85,7 @@ impl KiraSize {
}
pub fn from_str_bytes(s: &str) -> Option<Self> {
Some(Self::new(u64::from_str_radix(s, 10).ok()?))
Some(Self::new_b(u64::from_str_radix(s, 10).ok()?))
}
pub fn div_c(self, other: u64) -> Self {
+29 -32
View File
@@ -21,6 +21,7 @@
*/
use iced::widget;
use log;
use std::process::ExitCode;
use iced::{Element, Task};
@@ -32,12 +33,13 @@ use crate::stages::welcome;
use crate::stages::welcome::WelcomeStage;
rust_i18n::i18n!("src/locales", fallback = "en");
mod kira_theming;
mod kira_scroll_list;
mod kira_color_bar;
mod kira_disk_layout;
mod kira_logger;
mod kira_scroll_list;
mod kira_size;
mod kira_sysinfo;
mod kira_theming;
mod stage;
mod stages;
@@ -80,7 +82,7 @@ fn load_kira_config(config_path: &str) -> Result<toml::Table, Box<dyn std::error
// 2. Parse the string into a Table
let table: Table = content.parse()?;
println!("{:?}", table);
log::info!("{:?}", table);
Ok(table)
}
@@ -99,7 +101,6 @@ impl KiraState {
}
}
fn view(k_state: &KiraState) -> Element<'_, Message> {
match &k_state.current_view {
Views::Start => Element::new(widget::space()),
@@ -117,13 +118,13 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match message {
Message::Start => match load_kira_config(CONFIG_PATH_STR) {
Ok(conf) => {
println!("Config loaded!");
log::info!("Config loaded!");
k_state.toml_config = conf;
k_state.current_view = Views::Welcome(WelcomeStage::new());
Task::none()
}
Err(ex) => {
println!("Error reading config {}: {}", CONFIG_PATH_STR, ex);
log::error!("Error reading config {}: {}", CONFIG_PATH_STR, ex);
iced::exit()
}
},
@@ -141,7 +142,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
} else {
Task::none()
}
},
}
Message::License(license_message) => {
if let Views::License(license_view) = &mut k_state.current_view {
let action = license_view.update(license_message);
@@ -163,7 +164,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
} else {
Task::none()
}
},
}
Message::Network(network_message) => {
if let Views::Network(network_view) = &mut k_state.current_view {
let update_result = network_view.update(network_message);
@@ -187,14 +188,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
} else {
Task::none()
}
},
}
Message::TimeZone(timezone_message) => {
if let Views::TimeZone(timezone_view) = &mut k_state.current_view {
let action = timezone_view.update(timezone_message);
match action {
StageAction::Next(tz_res) => {
k_state.config.config_trail.push(tz_res);
k_state.current_view = Views::Locale(stages::locale::LocaleStage::new(&k_state.config));
k_state.current_view =
Views::Locale(stages::locale::LocaleStage::new(&k_state.config));
Task::none()
}
StageAction::Abort => iced::exit(),
@@ -209,19 +211,20 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
} else {
Task::none()
}
},
}
Message::Locale(locale_msg) => {
if let Views::Locale(locale_view) = &mut k_state.current_view {
match locale_view.update(locale_msg) {
StageAction::Next(locale_res) => {
k_state.config.config_trail.push(locale_res);
k_state.current_view = Views::Keyboard(stages::keyboard::KeyboardStage::new());
k_state.current_view =
Views::Keyboard(stages::keyboard::KeyboardStage::new());
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view =
Views::TimeZone(stages::timezone::TimeZoneStage::new());
Views::TimeZone(stages::timezone::TimeZoneStage::new());
Task::none()
}
_ => Task::none(),
@@ -229,7 +232,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
} else {
Task::none()
}
},
}
Message::Keyboard(keyboard_msg) => {
if let Views::Keyboard(keyboard_view) = &mut k_state.current_view {
match keyboard_view.update(keyboard_msg) {
@@ -238,17 +241,17 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
Ok(part_stage) => {
k_state.config.config_trail.push(keyboard_res);
k_state.current_view = Views::Partition(part_stage);
},
Err(ex) => {
println!("Error, cannot init partition stage: {}", ex);
}
Err(ex) => {
log::error!("Error, cannot init partition stage: {}", ex);
}
}
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = Views::Locale(stages::locale::LocaleStage::new(&k_state.config));
k_state.current_view =
Views::Locale(stages::locale::LocaleStage::new(&k_state.config));
Task::none()
}
_ => Task::none(),
@@ -256,7 +259,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
} else {
Task::none()
}
},
}
Message::Partition(partition_msg) => {
if let Views::Partition(partition_view) = &mut k_state.current_view {
match partition_view.update(partition_msg) {
@@ -266,7 +269,8 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = Views::Keyboard(stages::keyboard::KeyboardStage::new());
k_state.current_view =
Views::Keyboard(stages::keyboard::KeyboardStage::new());
Task::none()
}
_ => Task::none(),
@@ -278,8 +282,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
}
}
pub fn main() -> ExitCode {
// Init logger
kira_logger::init().unwrap();
let iced_result = iced::application(KiraState::boot, update, view)
.window(iced::window::Settings {
@@ -297,16 +302,8 @@ pub fn main() -> ExitCode {
match iced_result {
Ok(()) => ExitCode::SUCCESS,
Err(ex) => {
println!("ICED Error: {}", ex);
log::error!("ICED Error: {}", ex);
ExitCode::from(42)
}, // Custom error code
} // Custom error code
}
}
// fn main() {
// println!("Hello, world!");
// println!("{}", t!("wellcome.text"));
// // Initialize the state
// let _res = main_interface();
// }
+2 -1
View File
@@ -18,6 +18,7 @@
This is Keyboar stage, used to select Keyboard Layouts
*/
use log;
use crate::kira_scroll_list::{self, ListViewMessage};
use crate::stage::{StageAction, StageResult};
use iced::{Alignment, Length, widget};
@@ -254,7 +255,7 @@ impl KeyboardStage {
}
}
Err(ex) => {
println!(
log::error!(
"Exception while trying to get kayboard layouts data from system {}",
ex
);
-7
View File
@@ -156,8 +156,6 @@ impl LocaleStage {
let raw_loc_codes = get_locales_codes_list_blocking().unwrap();
let raw_loc_descr = get_locales_description_blocking().unwrap();
//println!("{:?}", raw_loc_descr);
let locales: Vec<LocaleData> = raw_loc_codes
.iter()
.filter_map(|(code, _)| {
@@ -187,11 +185,6 @@ impl LocaleStage {
LocaleData::default()
};
//println!("lang_match {:?}", lang_match);
//println!("loc_codes {:?}", raw_loc_codes);
// let locale = locales.iter().find(|l| l.code == lang_match.0).cloned();
let lang_locale_text = format!(
"{}: {}",
t!("locale.select_language_locale"),
+4 -3
View File
@@ -19,6 +19,7 @@
it needed for installation to process.
*/
use log;
use iced::{Alignment, Task, widget};
use iced_moving_picture::widget::apng;
use rust_i18n::t;
@@ -81,7 +82,7 @@ fn check_connection_blocking() -> CheckResult {
}
}
Err(ex) => {
println!("Exception while trying to chen net connectivity: {}", ex);
log::error!("Exception while trying to chen net connectivity: {}", ex);
CheckResult::CheckError
}
}
@@ -103,10 +104,10 @@ impl NetworkStage {
.and_then(|v| v.get("reqire_network"))
.and_then(|v| v.as_bool())
{
println!("Config value reqire_network read {}", reqire_network_conf);
log::debug!("Config value reqire_network read {}", reqire_network_conf);
reqire_network = reqire_network_conf;
} else {
println!("Error parsing network config. Using default values.");
log::error!("Error parsing network config. Using default values.");
}
let spinner_frames =
+11 -10
View File
@@ -18,8 +18,8 @@
This is partition stage!
*/
use log;
use crate::stage::{StageAction, StageResult};
use crate::kira_color_bar;
use crate::kira_disk_layout::{BlkDev, FSType, PartInfo, PartLayout};
use crate::kira_size::KiraSize;
@@ -28,6 +28,7 @@ use iced::{Alignment, Color, widget};
use rust_i18n::t;
use toml::Table;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SwapMode {
NoSwap,
@@ -96,7 +97,7 @@ pub enum Message {
impl PartitionStage {
pub fn new(toml_config: &Table) -> Result<Self, String> {
let maybe_dev_list = BlkDev::list_sys_blk_dev();
log::info!("hiii from partition");
let min_disk_size_mb = toml_config
.get("partition")
.and_then(|v| v.as_table())
@@ -116,13 +117,13 @@ impl PartitionStage {
// getting system memory info
let system_ram_size = KiraSize::new_kb(kira_sysinfo::get_meminfo()["MemTotal"]); // from kB to bytes
let vram_of_all_gpus_size = KiraSize::new(
let vram_of_all_gpus_size = KiraSize::new_b(
kira_sysinfo::get_gpus_list()
.iter()
.fold(0u64, |acc, gpi| acc + gpi.vis_vram_total),
);
println!(
log::debug!(
"stage init ram {} vram {}",
system_ram_size, vram_of_all_gpus_size
);
@@ -144,9 +145,9 @@ impl PartitionStage {
fn get_swap_size(&self) -> KiraSize {
let total_ram = self.system_ram_size + self.vram_of_all_gpus_size;
println!("total_ram {}", total_ram);
log::debug!("total_ram {}", total_ram);
let sys_ram_gb = self.system_ram_size.gb();
println!("sys_ram_gb {}", sys_ram_gb);
log::debug!("sys_ram_gb {}", sys_ram_gb);
let disk_swap_gb = if sys_ram_gb >= 32 {
1u64
} else if sys_ram_gb >= 24 {
@@ -159,11 +160,11 @@ impl PartitionStage {
sys_ram_gb * 2
};
println!("disk_swap_gb {}", disk_swap_gb);
log::debug!("disk_swap_gb {}", disk_swap_gb);
let disk_swap = KiraSize::new_gb(disk_swap_gb);
println!("disk_swap {}", disk_swap);
log::debug!("disk_swap {}", disk_swap);
match self.swap_mode {
Some(SwapMode::NoSwap) => KiraSize::new(0),
Some(SwapMode::NoSwap) => KiraSize::new_b(0),
Some(SwapMode::SwapHibernate) => disk_swap + total_ram,
Some(SwapMode::SwapNoHibernate) => disk_swap,
_ => KiraSize::new_gb(2),
@@ -202,7 +203,7 @@ impl PartitionStage {
.collect(),
),
Err(ex) => {
println!("Error getting dev partitions info: {}", ex);
log::error!("Error getting dev partitions info: {}", ex);
None
}
};
+2 -1
View File
@@ -18,6 +18,7 @@
This is TimeZone stage, used to select timezone
*/
use log;
use crate::stage::{StageAction, StageResult};
use iced::{Alignment, Length, widget};
use rust_i18n::t;
@@ -127,7 +128,7 @@ impl TimeZoneStage {
}
}
Err(ex) => {
println!(
log::error!(
"Exception while trying to get time zones list from system {}",
ex
);