From 4478ec1654e22df6bbf269e5b143048d8e132ba4 Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Wed, 11 Sep 2024 10:31:28 +0900 Subject: [PATCH 1/4] bump to v2.0.1 fix version in Cargo.toml --- CHANGELOG.md | 7 +++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e8a4e2..6f87356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.0.1] + +### Fix + +- version in Cargo.toml + ## [2.0.0] ### Added @@ -44,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Subcommand `check-db` to validate the database CSV file. [Unreleased]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/main...v1.0.1 +[2.0.1]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v2.0.1...v2.0.0 [2.0.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v2.0.0...v1.1.0 [1.1.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.1.0...v1.0.1 [1.0.1]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.0.1...v1.0.0 diff --git a/Cargo.lock b/Cargo.lock index e11698d..17eb944 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -730,7 +730,7 @@ dependencies = [ [[package]] name = "psb-qaqc" -version = "1.1.0" +version = "2.0.1" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 4e924c9..3d49cf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "psb-qaqc" -version = "1.1.0" +version = "2.0.1" edition = "2021" [dependencies] From 3fdbe5ad4c46ede95dd7cda051a661cde91c9f02 Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Wed, 11 Sep 2024 15:19:13 +0900 Subject: [PATCH 2/4] update: print error when no editor is specified & add-master-log doesn't append csv file --- src/main.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index bceb1c6..7c3d4e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use std::{ fmt::Display, fs::{self, File}, io::{self, BufRead, BufReader}, - path::{self, Path, PathBuf}, + path::{self, PathBuf}, str::FromStr, }; @@ -351,11 +351,12 @@ impl PsbQaqcResult { // .collect_vec() // } -fn write_psbqaqc_csv(result: MasterLogResult, outfile: PathBuf) -> Result<()> { +/// If `nonewfile` is `true`, out file is not created when there is already a file. +fn write_psbqaqc_csv(result: MasterLogResult, outfile: PathBuf, nonewfile: bool) -> Result<()> { let expanded_results = PsbQaqcResult::from_masterlogresult(result); - let mut wtr = match outfile.exists() { - true => { + let mut wtr = match (outfile.exists(), nonewfile) { + (true, false) => { let file = File::options() .read(true) .append(true) @@ -364,7 +365,7 @@ fn write_psbqaqc_csv(result: MasterLogResult, outfile: PathBuf) -> Result<()> { .has_headers(false) .from_writer(file) } - false => { + (false, _) => { println!("Creating new file: {}", outfile.display()); let file = File::options() .create_new(true) @@ -374,6 +375,10 @@ fn write_psbqaqc_csv(result: MasterLogResult, outfile: PathBuf) -> Result<()> { .has_headers(true) .from_writer(file) } + (true, true) => { + error!("Out file already exists but specified not to make new file"); + return Err(anyhow!("Out file already exists")); + } }; for result in expanded_results { wtr.serialize(result)?; @@ -409,7 +414,7 @@ fn main() -> Result<()> { let outfile = outfile.unwrap_or(get_output_filename(&result)); - write_psbqaqc_csv(result, outfile.clone())?; + write_psbqaqc_csv(result, outfile.clone(), true)?; println!("Add comments about errors in the last column of the CSV file"); println!("Press any key to start editting..."); @@ -428,14 +433,17 @@ fn main() -> Result<()> { editor } (None, Err(e1), Err(e2)) => { - info!("No VISUAL nor EDITOR found, {}, {}", e1, e2); + warn!("No VISUAL nor EDITOR found, {}, {}", e1, e2); + warn!("Using `nano` as a fallback editor"); "nano".to_string() } }; std::process::Command::new(editor) .arg(outfile.clone()) - .spawn()? - .wait()?; + .spawn() + .context("Error during spawning editor")? + .wait() + .context("Error while waiting editor")?; { let f = File::open(outfile.clone())?; @@ -444,7 +452,7 @@ fn main() -> Result<()> { } println!(); println!("Copy the CSV above and paste it to the database(Google sheets)"); - println!("Choose Data->Split text to columns to format it"); + println!("Choose `Data->Split text to columns` to format it"); println!("Press any key when upload finished..."); terminal::enable_raw_mode()?; @@ -483,7 +491,7 @@ fn main() -> Result<()> { let outfile = outfile.unwrap_or(get_output_filename(&result)); - write_psbqaqc_csv(result, outfile)?; + write_psbqaqc_csv(result, outfile, false)?; } Commands::CheckDB { csvfile } => { // TODO: more friendly message (like row number) From 2dd0c20ce49451b0d47aeaa6570169f1f3432392 Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Wed, 11 Sep 2024 15:25:50 +0900 Subject: [PATCH 3/4] update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f87356..1609e74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- `add-master-log` now always create CSV file +- `convert-master-log` can still append to a CSV file + ## [2.0.1] ### Fix From a78416a18dce4cb87803731c42cbb8b3d3ba0643 Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Wed, 11 Sep 2024 15:31:09 +0900 Subject: [PATCH 4/4] fix: CHANGELOG diff links --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1609e74..8fa002d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,9 +54,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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/wotsubo/psboard-qaqc-postprocess/-/compare/main...v1.0.1 -[2.0.1]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v2.0.1...v2.0.0 -[2.0.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v2.0.0...v1.1.0 -[1.1.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.1.0...v1.0.1 -[1.0.1]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.0.1...v1.0.0 +[Unreleased]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.0.1...main +[2.0.1]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v2.0.0...v2.0.1 +[2.0.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.1.0...v2.0.0 +[1.1.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.0.1...v1.1.0 +[1.0.1]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/compare/v1.0.0...v1.0.1 [1.0.0]: https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess/-/tags/v1.0.0