diff --git a/CHANGELOG.md b/CHANGELOG.md index f115c2e..1744e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Subcommand `add-master-log` to parse master log for shiftwork 0.1.0 and write out to CSV +- Subcommand `add-master-log` to parse master log for shiftwork 0.1.0 and write out to CSV. +- Subcommand `check-db` to validate the database CSV file. [Unreleased]: https://gitlab.cern.ch diff --git a/src/main.rs b/src/main.rs index 6ed3bb6..c178377 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,18 @@ pub enum Commands { // #[arg(default_value = get_default_log_path().into_os_string())] outfile: PathBuf, }, + /// Check CSV format + CheckDB { + /// Database CSV file. + csvfile: PathBuf, + }, + /// Get LVDS TX skew from slave log _clk file. + AddSkew { + /// Slave _clk log file. + logfile: PathBuf, + /// Output CSV file. + outfile: PathBuf, + }, } /// Layer @@ -473,15 +485,6 @@ fn main() -> Result<()> { }; debug!("{:?}", result); - // { - // let file = File::options() - // .read(true) - // .open(args.outfile)?; - // - // let mut rdr = csv::Reader::from_reader(file); - // rdr.records(); - // } - let expanded_results = PsbQaqcResult::from_masterlogresult(result); let mut wtr = match outfile.exists() { @@ -504,6 +507,22 @@ fn main() -> Result<()> { } wtr.flush()?; } + Commands::CheckDB { csvfile } => { + // TODO: more friendly message (like row number) + // TODO: more validation options (e.g. for each stage(Master log, Slave log(end of + // campaign))) + // TODO: Masterログが得られたときや、行として完成していかないときなど複数段階のチェックを用意する + let file = File::options().read(true).open(csvfile)?; + + let rdr = csv::Reader::from_reader(file); + if !rdr + .into_deserialize::() + .all(|row| row.is_ok()) + { + return Err(anyhow!("Invalid csv")); + }; + } + Commands::AddSkew { logfile, outfile } => todo!("Not implemented"), } Ok(()) } diff --git a/tests/cli.rs b/tests/cli.rs index 989dfe3..e4daef9 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -6,7 +6,7 @@ mod integrated_test { }; use anyhow::Result; - use assert_cmd::{assert::OutputAssertExt, Command}; + use assert_cmd::Command; use predicates::prelude::*; #[test] @@ -42,6 +42,14 @@ mod integrated_test { .assert() .success(); + // check + let mut cmd = Command::cargo_bin("psb-qaqc")?; + cmd.current_dir("tests") + .arg("check-db") + .arg(test_out.as_path()) + .assert() + .success(); + Ok(()) }