Skip to content

Commit

Permalink
serval capture: adapt cross-platform path
Browse files Browse the repository at this point in the history
  • Loading branch information
wsyxbcl committed Dec 18, 2024
1 parent 4360532 commit e480482
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
22 changes: 9 additions & 13 deletions src/tags.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{
absolute_path, append_ext, get_path_seperator, ignore_timezone, is_temporal_independent,
absolute_path, append_ext, get_path_levels, ignore_timezone, is_temporal_independent,
path_enumerate, sync_modified_time, ExtractFilterType, ResourceType, TagType,
};
use chrono::{DateTime, Local};
Expand Down Expand Up @@ -830,19 +830,13 @@ pub fn get_temporal_independence(csv_path: PathBuf, output_dir: PathBuf) -> anyh
// Find deployment
let path_sample = df.column("path")?.get(0)?.to_string().replace('"', "");
println!("\nHere is a sample of the file path ({})", path_sample);
let mut num_option = 0;
for (i, entry) in absolute_path(Path::new(&path_sample).to_path_buf())?
.parent()
.unwrap()
.ancestors()
.enumerate()
{
println!("{}): {}", i + 1, entry.to_string_lossy());
num_option += 1;
let path_levels = get_path_levels(path_sample);
for (i, entry) in path_levels.iter().enumerate() {
println!("{}): {}", i + 1, entry);
}
let h = NumericSelectValidator {
min: 1,
max: num_option,
max: path_levels.len().try_into()?,
};
rl.set_helper(Some(h));
let readline = rl.readline("Select the path corresponding to the deployment: ");
Expand All @@ -867,9 +861,11 @@ pub fn get_temporal_independence(csv_path: PathBuf, output_dir: PathBuf) -> anyh
col("path"),
col("path")
.str()
.split(lit(get_path_seperator()))
.replace_all(lit("\\"), lit("/"), true)
.str()
.split(lit("/"))
.list()
.get(lit(num_option - deploy_path_index), false)
.get(lit(deploy_path_index), false)
.alias("deployment"),
col("datetime").alias("time"),
col(target.col_name()),
Expand Down
16 changes: 10 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,16 @@ pub fn is_temporal_independent(
Ok(diff >= chrono::Duration::try_minutes(min_delta_time.into()).unwrap())
}

pub fn get_path_seperator() -> &'static str {
if env::consts::OS == "windows" {
r"\"
} else {
r"/"
}
pub fn get_path_levels(path: String) -> Vec<String> {
let normalized_path = path.replace('\\', "/");

let levels: Vec<String> = Path::new(&normalized_path)
.components()
.map(|comp| comp.as_os_str().to_string_lossy().into_owned())
.filter(|comp| !comp.is_empty())
.collect();

levels[1..levels.len() - 1].to_vec()
}

pub fn ignore_timezone(time: String) -> anyhow::Result<String> {
Expand Down

0 comments on commit e480482

Please sign in to comment.