From 9d68343219224c22479944689479c5173f0e991155aaa296c0b41bd5ec477559 Mon Sep 17 00:00:00 2001 From: kira Date: Fri, 20 Nov 2026 22:30:49 +0100 Subject: [PATCH] Locale stage code cleanup --- src/stages/locale/mod.rs | 95 +++++++--------------------------------- 1 file changed, 15 insertions(+), 80 deletions(-) diff --git a/src/stages/locale/mod.rs b/src/stages/locale/mod.rs index a2945a5..7b70542 100644 --- a/src/stages/locale/mod.rs +++ b/src/stages/locale/mod.rs @@ -29,17 +29,12 @@ use rust_i18n::t; use std::collections::HashMap; const LOCALES_GEN_FILE_NAME: &str = "/etc/locale.gen"; -const LOCALES_GEN_START_LINE: usize = 17; - -// fn default_locale() -> (String, String) { -// ("C.UTF-8".to_string(), "UTF-8".to_string()) -// } #[derive(Debug, Clone, PartialEq, Eq)] pub struct LocaleData { - code: String, - charset: String, - description: Option, + pub code: String, + pub charset: String, + pub description: Option, } impl std::fmt::Display for LocaleData { @@ -60,6 +55,18 @@ impl LocaleData { description: Some("C locale".into()), } } + + // creates text to be appended to locale.gen file + // in case of C locale outputs empty string + pub fn locale_gen_line(&self) -> String { + if self.code == "C.UTF-8" { + String::new() + } + else { + format!("{} {}", &self.code, &self.charset) + } + + } } /// gets locales list from system "/etc/locale.gen" file @@ -107,27 +114,9 @@ fn get_locales_blocking(filter_charset: Option<&str>) -> Result, charset: charset, description: description, }); - // let subvol_name = &captured[1]; - // let date_time = captured[2].to_string(); } } - //if let Some(captured) = re.captures(&dir_name) - // let mut res: Vec<(String, String)> = file_content - // .split('\n') - // .skip(LOCALES_GEN_START_LINE) - // .filter_map(|l| { - // let trimmed = l.trim_start_matches('#').trim(); - // if trimmed.len() > 0 { - // trimmed.split_once(' ') - // } else { - // None - // } - // }) - // .map(|(loc, charset)| (loc.to_string(), charset.to_string())) - // .filter(|(_, chrs)| chrs == "UTF-8") // yeld only UTF-8 locales - // .collect(); - res.push(LocaleData::default()); Ok(res) @@ -154,42 +143,6 @@ fn get_loc_descr_blocking() -> Result, ExecCommandError> } } - // match Command::new("grep") - // .args(["-r", "title ", "/usr/share/i18n/locales/"]) - // .output() - // { - // Ok(cmd_output) => { - // if cmd_output.status.success() { - // match String::from_utf8(cmd_output.stdout) { - // Ok(raw_str_list) => Ok(raw_str_list - // .split("\n") - // .filter_map(|s| s.trim().split_once(":title")) - // .filter_map(|(code_part, description_part)| { - // code_part.rsplit_once("/").and_then(|(_, loc_code)| { - // Some(( - // loc_code.trim().to_string(), - // description_part.trim().trim_matches('\"').to_string(), - // )) - // }) - // }) - // .collect()), - // Err(ex) => Err(format!( - // "Exception while converting locales description to UTF8 {}", - // ex - // )), - // } - // } else { - // Err(format!( - // "Error getting locales description list: {}", - // String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into()) - // )) - // } - // } - // Err(ex) => Err(format!( - // "Exception while trying to get locales description {}", - // ex - // )), - // } Ok(res) } @@ -225,25 +178,7 @@ impl LocaleStage { .as_ref() .and_then(|rw| Some(rw.loc_code.clone())); - // let raw_loc_codes = get_locales_codes_list_blocking().unwrap(); - // let raw_loc_descr = get_locales_description_blocking().unwrap(); - let locales: Vec = get_locales_blocking(Some("UTF-8")).unwrap(); - // .iter() - // .filter_map(|(code, _)| { - // code.split_once('.') - // .and_then(|(key_code, _)| Some((key_code, code))) - // }) - // .filter_map(|(key_code, code)| { - // raw_loc_descr - // .get(key_code) - // .and_then(|descr| Some((code.clone(), descr.clone()))) - // }) - // .map(|(code, descr)| LocaleData { - // code: code, - // description: descr, - // }) - // .collect(); // if we get lang code from wellcome stage, try to fing match with system locales let lang_match = if let Some(lang) = maybe_lang