mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-25 00:21:37 +09:00
update: organize commands to subcommands and rename bin
- existing functions are moved to subcommand `add-master-log`
This commit is contained in:
parent
bdb415e6e6
commit
a94a871e52
5 changed files with 81 additions and 56 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -637,7 +637,7 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "psb-qaqc-parse"
|
name = "psb-qaqc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "psb-qaqc-parse"
|
name = "psb-qaqc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@ cargo build
|
||||||
cargo run -- -h
|
cargo run -- -h
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Build for JATHub using cross:
|
||||||
|
```sh
|
||||||
|
CROSS_CONTAINER_ENGINE=podman cross build --release --target armv7-unknown-linux-musleabihf
|
||||||
|
```
|
||||||
|
|
||||||
### test
|
### test
|
||||||
```sh
|
```sh
|
||||||
cargo test
|
cargo test
|
||||||
|
|
45
src/main.rs
45
src/main.rs
|
@ -10,24 +10,33 @@ use std::{
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use chrono::{DateTime, Local, Utc};
|
use chrono::{DateTime, Local, Utc};
|
||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::{serde_as, DisplayFromStr};
|
use serde_with::{serde_as, DisplayFromStr};
|
||||||
|
|
||||||
/// Parse master jathub logfile for PS Board QAQC and write out to CSV.
|
/// PS Board QAQC shift related commands.
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Commands,
|
||||||
|
#[command(flatten)]
|
||||||
|
verbose: clap_verbosity_flag::Verbosity,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
pub enum Commands {
|
||||||
|
/// Parse master jathub logfile for PS Board QAQC and write out to CSV.
|
||||||
|
AddMasterLog {
|
||||||
/// Master log file.
|
/// Master log file.
|
||||||
master_log: path::PathBuf,
|
master_log: path::PathBuf,
|
||||||
/// Output CSV file.
|
/// Output CSV file.
|
||||||
// #[arg(default_value = get_default_log_path().into_os_string())]
|
// #[arg(default_value = get_default_log_path().into_os_string())]
|
||||||
outfile: PathBuf,
|
outfile: PathBuf,
|
||||||
#[command(flatten)]
|
},
|
||||||
verbose: clap_verbosity_flag::Verbosity,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Layer
|
/// Layer
|
||||||
|
@ -444,12 +453,17 @@ fn main() -> Result<()> {
|
||||||
" 1".split_whitespace().next().unwrap().parse::<u8>()
|
" 1".split_whitespace().next().unwrap().parse::<u8>()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
match args.command {
|
||||||
|
Commands::AddMasterLog {
|
||||||
|
master_log,
|
||||||
|
outfile,
|
||||||
|
} => {
|
||||||
let result = {
|
let result = {
|
||||||
let file = File::open(args.master_log.clone())?;
|
let file = File::open(master_log.clone())?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
MasterLogResult::parse_file(
|
MasterLogResult::parse_file(
|
||||||
reader,
|
reader,
|
||||||
args.master_log
|
master_log
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -470,19 +484,16 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
||||||
|
|
||||||
let mut wtr = match args.outfile.exists() {
|
let mut wtr = match outfile.exists() {
|
||||||
true => {
|
true => {
|
||||||
let file = File::options().read(true).append(true).open(args.outfile)?;
|
let file = File::options().read(true).append(true).open(outfile)?;
|
||||||
csv::WriterBuilder::new()
|
csv::WriterBuilder::new()
|
||||||
.has_headers(false)
|
.has_headers(false)
|
||||||
.from_writer(file)
|
.from_writer(file)
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
println!("Creating new file: {}", args.outfile.display());
|
println!("Creating new file: {}", outfile.display());
|
||||||
let file = File::options()
|
let file = File::options().create_new(true).write(true).open(outfile)?;
|
||||||
.create_new(true)
|
|
||||||
.write(true)
|
|
||||||
.open(args.outfile)?;
|
|
||||||
csv::WriterBuilder::new()
|
csv::WriterBuilder::new()
|
||||||
.has_headers(true)
|
.has_headers(true)
|
||||||
.from_writer(file)
|
.from_writer(file)
|
||||||
|
@ -492,7 +503,8 @@ fn main() -> Result<()> {
|
||||||
wtr.serialize(result)?;
|
wtr.serialize(result)?;
|
||||||
}
|
}
|
||||||
wtr.flush()?;
|
wtr.flush()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,4 +637,9 @@ mod test {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
|
// fn parse_file() {
|
||||||
|
// let logfile = r"""""";
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,9 @@ mod integrated_test {
|
||||||
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
||||||
|
|
||||||
// 1st file
|
// 1st file
|
||||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||||
cmd.current_dir("tests")
|
cmd.current_dir("tests")
|
||||||
|
.arg("add-master-log")
|
||||||
.arg("./example_logs/valid/20240720_171418.log")
|
.arg("./example_logs/valid/20240720_171418.log")
|
||||||
.arg(test_out.as_path())
|
.arg(test_out.as_path())
|
||||||
.assert()
|
.assert()
|
||||||
|
@ -33,8 +34,9 @@ mod integrated_test {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2nd file
|
// 2nd file
|
||||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||||
cmd.current_dir("tests")
|
cmd.current_dir("tests")
|
||||||
|
.arg("add-master-log")
|
||||||
.arg("./example_logs/valid/20240720_171418.log")
|
.arg("./example_logs/valid/20240720_171418.log")
|
||||||
.arg(test_out.as_path())
|
.arg(test_out.as_path())
|
||||||
.assert()
|
.assert()
|
||||||
|
@ -48,8 +50,9 @@ mod integrated_test {
|
||||||
let test_out_dir = assert_fs::TempDir::new()?;
|
let test_out_dir = assert_fs::TempDir::new()?;
|
||||||
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
||||||
|
|
||||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||||
cmd.current_dir("tests")
|
cmd.current_dir("tests")
|
||||||
|
.arg("add-master-log")
|
||||||
.arg("./example_logs/valid/20240720_171419.log")
|
.arg("./example_logs/valid/20240720_171419.log")
|
||||||
.arg(test_out.as_path())
|
.arg(test_out.as_path())
|
||||||
.assert()
|
.assert()
|
||||||
|
|
Loading…
Reference in a new issue