mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-24 16:11:11 +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]]
|
||||
name = "psb-qaqc-parse"
|
||||
name = "psb-qaqc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "psb-qaqc-parse"
|
||||
name = "psb-qaqc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
|
@ -9,6 +9,11 @@ cargo build
|
|||
cargo run -- -h
|
||||
```
|
||||
|
||||
Build for JATHub using cross:
|
||||
```sh
|
||||
CROSS_CONTAINER_ENGINE=podman cross build --release --target armv7-unknown-linux-musleabihf
|
||||
```
|
||||
|
||||
### test
|
||||
```sh
|
||||
cargo test
|
||||
|
|
45
src/main.rs
45
src/main.rs
|
@ -10,24 +10,33 @@ use std::{
|
|||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use clap::Parser;
|
||||
use clap::{Parser, Subcommand};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use regex::Regex;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
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)]
|
||||
#[command(version, about, long_about = None)]
|
||||
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: path::PathBuf,
|
||||
/// Output CSV file.
|
||||
// #[arg(default_value = get_default_log_path().into_os_string())]
|
||||
outfile: PathBuf,
|
||||
#[command(flatten)]
|
||||
verbose: clap_verbosity_flag::Verbosity,
|
||||
},
|
||||
}
|
||||
|
||||
/// Layer
|
||||
|
@ -444,12 +453,17 @@ fn main() -> Result<()> {
|
|||
" 1".split_whitespace().next().unwrap().parse::<u8>()
|
||||
);
|
||||
|
||||
match args.command {
|
||||
Commands::AddMasterLog {
|
||||
master_log,
|
||||
outfile,
|
||||
} => {
|
||||
let result = {
|
||||
let file = File::open(args.master_log.clone())?;
|
||||
let file = File::open(master_log.clone())?;
|
||||
let reader = BufReader::new(file);
|
||||
MasterLogResult::parse_file(
|
||||
reader,
|
||||
args.master_log
|
||||
master_log
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
|
@ -470,19 +484,16 @@ fn main() -> Result<()> {
|
|||
|
||||
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
||||
|
||||
let mut wtr = match args.outfile.exists() {
|
||||
let mut wtr = match outfile.exists() {
|
||||
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()
|
||||
.has_headers(false)
|
||||
.from_writer(file)
|
||||
}
|
||||
false => {
|
||||
println!("Creating new file: {}", args.outfile.display());
|
||||
let file = File::options()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.open(args.outfile)?;
|
||||
println!("Creating new file: {}", outfile.display());
|
||||
let file = File::options().create_new(true).write(true).open(outfile)?;
|
||||
csv::WriterBuilder::new()
|
||||
.has_headers(true)
|
||||
.from_writer(file)
|
||||
|
@ -492,7 +503,8 @@ fn main() -> Result<()> {
|
|||
wtr.serialize(result)?;
|
||||
}
|
||||
wtr.flush()?;
|
||||
|
||||
}
|
||||
}
|
||||
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");
|
||||
|
||||
// 1st file
|
||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
||||
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||
cmd.current_dir("tests")
|
||||
.arg("add-master-log")
|
||||
.arg("./example_logs/valid/20240720_171418.log")
|
||||
.arg(test_out.as_path())
|
||||
.assert()
|
||||
|
@ -33,8 +34,9 @@ mod integrated_test {
|
|||
}
|
||||
|
||||
// 2nd file
|
||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
||||
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
||||
cmd.current_dir("tests")
|
||||
.arg("add-master-log")
|
||||
.arg("./example_logs/valid/20240720_171418.log")
|
||||
.arg(test_out.as_path())
|
||||
.assert()
|
||||
|
@ -48,8 +50,9 @@ mod integrated_test {
|
|||
let test_out_dir = assert_fs::TempDir::new()?;
|
||||
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")
|
||||
.arg("add-master-log")
|
||||
.arg("./example_logs/valid/20240720_171419.log")
|
||||
.arg(test_out.as_path())
|
||||
.assert()
|
||||
|
|
Loading…
Reference in a new issue