Compare commits
No commits in common. "38d03f9d55beded38bb18bd64a99b96e3afc3b50" and "4b22958a05027a8f73b013b52d34e2bc768b5d7a" have entirely different histories.
38d03f9d55
...
4b22958a05
|
@ -1,22 +1,13 @@
|
||||||
// prints output to the stderr if the verbosity is
|
fn l1_log(verbosity: u8, message: &str) {
|
||||||
// greater than or equal to the logging level of the
|
if verbosity > 0 {
|
||||||
// notification.
|
println!("{}", message);
|
||||||
#[macro_export]
|
|
||||||
macro_rules! log {
|
|
||||||
// NOTE: this uses a variadic argument system
|
|
||||||
// copied from the std::fmt eprintln! macro
|
|
||||||
// see the appropriate documentation
|
|
||||||
($l:expr, $v:expr, $($arg:tt)*) => {{
|
|
||||||
if $v >= $l {
|
|
||||||
eprintln!($($arg)*);
|
|
||||||
}
|
}
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
fn l2_log(verbosity: u8, message: &str) {
|
||||||
mod tests {
|
if verbosity > 1 {
|
||||||
#[test]
|
println!("{}", message);
|
||||||
fn test_name() {
|
|
||||||
log!(1, 1, "this is a {}", "test");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO unit test, but these are trivial
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
use std::{path::{PathBuf, Path, Components, Component}, fs, collections::{HashMap, VecDeque}, borrow::BorrowMut};
|
use std::{path::{PathBuf, Path, Components, Component}, fs, collections::{HashMap, VecDeque}, borrow::BorrowMut};
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
use crate::log;
|
|
||||||
|
|
||||||
pub fn validate(verbosity: u8, config: util::config::Config) {
|
pub fn validate(verbosity: u8, config: util::config::Config) {
|
||||||
println!("Validating");
|
println!("Validating");
|
||||||
|
|
||||||
let in_suffix = "in"; //TODO make this configurable?
|
let in_suffix = "in"; //TODO make this configurable?
|
||||||
let out_suffix = "out";
|
let out_suffix = "out";
|
||||||
log!(1, verbosity, "LOG 1: Input suffix: {} \nOutput suffix: {}", in_suffix, out_suffix);
|
|
||||||
// get list of all file names in input/output
|
// get list of all file names in input/output
|
||||||
log!(1, verbosity, "LOG 1:Reading the list of input and output files");
|
|
||||||
let in_files: Vec<PathBuf> = get_dir_files(&config.input_path, verbosity).expect("Failed to read the input directory contents");
|
let in_files: Vec<PathBuf> = get_dir_files(&config.input_path, verbosity).expect("Failed to read the input directory contents");
|
||||||
let out_files: Vec<PathBuf> = get_dir_files(&config.output_path, verbosity).expect("Failed to read the output directory contents");
|
let out_files: Vec<PathBuf> = get_dir_files(&config.output_path, verbosity).expect("Failed to read the output directory contents");
|
||||||
|
|
||||||
|
let mismatch: Vec<(PathBuf, PathBuf)>;
|
||||||
|
|
||||||
// check the files for valid suffixes
|
// check the files for valid suffixes
|
||||||
log!(1, verbosity, "LOG 1:Collecting files with invalid suffixes");
|
|
||||||
let invalid_suffix_in: Vec<PathBuf> = collect_invalid(&in_files, in_suffix, verbosity);
|
let invalid_suffix_in: Vec<PathBuf> = collect_invalid(&in_files, in_suffix, verbosity);
|
||||||
let invalid_suffix_out: Vec<PathBuf> = collect_invalid(&out_files, out_suffix, verbosity);
|
let invalid_suffix_out: Vec<PathBuf> = collect_invalid(&out_files, out_suffix, verbosity);
|
||||||
|
|
||||||
|
@ -29,9 +27,7 @@ pub fn validate(verbosity: u8, config: util::config::Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure each has a match
|
// make sure each has a match
|
||||||
log!(1, verbosity, "LOG 1:Checking if valid mappings exist between input and output files");
|
|
||||||
let in_to_out: (Vec<(PathBuf, PathBuf)>, Vec<PathBuf>) = map_files(in_files, out_files, &config, verbosity);
|
let in_to_out: (Vec<(PathBuf, PathBuf)>, Vec<PathBuf>) = map_files(in_files, out_files, &config, verbosity);
|
||||||
log!(1, verbosity, "LOG 1:Verifying file matches");
|
|
||||||
let invalid: Vec<(PathBuf, PathBuf)> = check_mappings(in_to_out.0, in_suffix, out_suffix, verbosity);
|
let invalid: Vec<(PathBuf, PathBuf)> = check_mappings(in_to_out.0, in_suffix, out_suffix, verbosity);
|
||||||
|
|
||||||
print_unmached(in_to_out.1, verbosity);
|
print_unmached(in_to_out.1, verbosity);
|
||||||
|
@ -56,13 +52,11 @@ fn map_files(in_files: Vec<PathBuf>, out_files: Vec<PathBuf>, config: &util::con
|
||||||
for pre in config.input_path.components() {
|
for pre in config.input_path.components() {
|
||||||
in_prefix.push(pre);
|
in_prefix.push(pre);
|
||||||
}
|
}
|
||||||
log!(2, verbosity, "LOG 2: Input prefixes found: {:?}", in_prefix);
|
|
||||||
|
|
||||||
let mut out_prefix = vec![];
|
let mut out_prefix = vec![];
|
||||||
for pre in config.output_path.components() {
|
for pre in config.output_path.components() {
|
||||||
out_prefix.push(pre);
|
out_prefix.push(pre);
|
||||||
}
|
}
|
||||||
log!(2, verbosity, "LOG 2: Output prefixes found: {:?}", out_prefix);
|
|
||||||
|
|
||||||
// check if the files have the same paths relative to in/out directory
|
// check if the files have the same paths relative to in/out directory
|
||||||
for ifile in &in_files {
|
for ifile in &in_files {
|
||||||
|
@ -87,21 +81,16 @@ fn map_files(in_files: Vec<PathBuf>, out_files: Vec<PathBuf>, config: &util::con
|
||||||
// println!("{:?}", ofile);
|
// println!("{:?}", ofile);
|
||||||
// println!("{:?}", out_comp);
|
// println!("{:?}", out_comp);
|
||||||
|
|
||||||
log!(2, verbosity, "LOG 2: Checking mapping of {} to {}",
|
|
||||||
&ifile.to_str().expect("failed to parse string"),
|
|
||||||
&ofile.to_str().expect("failed to parse string"));
|
|
||||||
// check if the file names are the same
|
// check if the file names are the same
|
||||||
if ofile.file_stem() == ifile.file_stem() {
|
if ofile.file_stem() == ifile.file_stem() {
|
||||||
// check that their paths are the same relative to the input/output directory
|
// check that their paths are the same relative to the input/output directory
|
||||||
for comp in &in_prefix { if &comp == &in_comp.front().expect("Failed to extract") { in_comp.pop_front(); } }
|
for comp in &in_prefix { if &comp == &in_comp.front().expect("Failed to extract") { in_comp.pop_front(); } }
|
||||||
for comp in &out_prefix { if &comp == &out_comp.front().expect("Failed to extract") { out_comp.pop_front(); } }
|
for comp in &out_prefix { if &comp == &out_comp.front().expect("Failed to extract") { out_comp.pop_front(); } }
|
||||||
// println!("{:?}\n{:?}\n{:?}", in_prefix, in_comp,out_comp);
|
println!("{:?}\n{:?}\n{:?}", in_prefix, in_comp,out_comp);
|
||||||
|
|
||||||
// if the files match, then we add them to the mapping
|
// if the files match, then we add them to the mapping
|
||||||
if out_comp == in_comp {
|
if out_comp == in_comp {
|
||||||
log!(1, verbosity, "LOG 1: Adding the mapping between {} and {} to the list of file mappings.",
|
println!("Added to map");
|
||||||
ifile.to_str().expect("failed to parse string"),
|
|
||||||
ofile.to_str().expect("failed to parse string"));
|
|
||||||
res.0.push((ifile.clone(), ofile.clone()));
|
res.0.push((ifile.clone(), ofile.clone()));
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
@ -109,9 +98,7 @@ fn map_files(in_files: Vec<PathBuf>, out_files: Vec<PathBuf>, config: &util::con
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we fail to find a match, we add the file to the rest
|
// if we fail to find a match, we add the file to the rest
|
||||||
if !found {
|
if !found { res.1.push(ifile.clone()); }
|
||||||
log!(1, verbosity, "LOG 1: Adding {} to the list of unmapped files", ifile.to_str().expect("failed to parse string"));
|
|
||||||
res.1.push(ifile.clone()); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cl: Vec<PathBuf> = Vec::from(out_files.clone());
|
let mut cl: Vec<PathBuf> = Vec::from(out_files.clone());
|
||||||
|
@ -121,7 +108,6 @@ fn map_files(in_files: Vec<PathBuf>, out_files: Vec<PathBuf>, config: &util::con
|
||||||
}
|
}
|
||||||
|
|
||||||
cl.retain(|x| !r.contains(&x));
|
cl.retain(|x| !r.contains(&x));
|
||||||
log!(1, verbosity, "LOG 1: Adding the following files to the list of unmapped files:\n{:?}", cl);
|
|
||||||
res.1.append(&mut cl);
|
res.1.append(&mut cl);
|
||||||
// println!("{:?}", res);
|
// println!("{:?}", res);
|
||||||
return res;
|
return res;
|
||||||
|
@ -140,10 +126,8 @@ fn check_mappings(mappings: Vec<(PathBuf, PathBuf)>, in_suffix: &str, out_suffix
|
||||||
let mut res: Vec<(PathBuf, PathBuf)> = vec![];
|
let mut res: Vec<(PathBuf, PathBuf)> = vec![];
|
||||||
|
|
||||||
for tup in &mappings {
|
for tup in &mappings {
|
||||||
log!(2, verbosity, "LOG 2: Verifying the mapping {:?}", tup);
|
|
||||||
if !(tup.0.as_path().extension().unwrap() == in_suffix) || !(tup.1.as_path().extension().unwrap() == out_suffix) {
|
if !(tup.0.as_path().extension().unwrap() == in_suffix) || !(tup.1.as_path().extension().unwrap() == out_suffix) {
|
||||||
res.push(tup.clone());
|
res.push(tup.clone());
|
||||||
log!(2, verbosity, "LOG 2: Added {:?} to the list of invalid mappings", tup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// println!("{:?}", res);
|
// println!("{:?}", res);
|
||||||
|
@ -162,19 +146,12 @@ fn collect_invalid(files: &Vec<PathBuf>, suf: &str, verbosity: u8) -> Vec<PathBu
|
||||||
let mut res: Vec<PathBuf> = vec![];
|
let mut res: Vec<PathBuf> = vec![];
|
||||||
|
|
||||||
for file in files {
|
for file in files {
|
||||||
log!(2, verbosity, "LOG 2: Checking the validity of {} against the suffix {}:\n$${}$$\n$${}$$",
|
|
||||||
file.to_str().expect("failed to parse string"),
|
|
||||||
suf,
|
|
||||||
file.extension().expect("Failed to extract suffix").to_str().expect("Failed to parse string"),
|
|
||||||
suf);
|
|
||||||
|
|
||||||
let extension = file.extension().expect("Invalid file name for validation");
|
let extension = file.extension().expect("Invalid file name for validation");
|
||||||
if extension.to_str() != Some(suf) {
|
if extension.to_str() != Some(suf) {
|
||||||
res.push(file.clone());
|
res.push(file.clone());
|
||||||
log!(2, verbosity, "LOG 2: Added {} to invalid files", file.to_str().expect("failed to parse string"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// println!("{:?}", res);
|
println!("{:?}", res);
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -187,7 +164,6 @@ fn collect_invalid(files: &Vec<PathBuf>, suf: &str, verbosity: u8) -> Vec<PathBu
|
||||||
fn get_dir_files(path: &PathBuf, verbosity: u8) -> Result<Vec<PathBuf>, &'static str> {
|
fn get_dir_files(path: &PathBuf, verbosity: u8) -> Result<Vec<PathBuf>, &'static str> {
|
||||||
let mut res: Vec<PathBuf> = vec![];
|
let mut res: Vec<PathBuf> = vec![];
|
||||||
|
|
||||||
log!(2, verbosity, "LOG 2: Checking the directory {} for files", path.to_str().expect("failed to parse string"));
|
|
||||||
// get the readout of the path for error handling
|
// get the readout of the path for error handling
|
||||||
let entries = match fs::read_dir(path) {
|
let entries = match fs::read_dir(path) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
|
@ -199,7 +175,6 @@ fn get_dir_files(path: &PathBuf, verbosity: u8) -> Result<Vec<PathBuf>, &'static
|
||||||
if p.path().is_dir() {
|
if p.path().is_dir() {
|
||||||
();
|
();
|
||||||
} else {
|
} else {
|
||||||
log!(2, verbosity, "LOG 2: Found file {}", stringify!(p));
|
|
||||||
res.push(p.path());
|
res.push(p.path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue