mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-21 23:00:20 +09:00
refactor: split csv writing to func
This commit is contained in:
parent
7529d003a6
commit
7fe5218d39
1 changed files with 33 additions and 21 deletions
54
src/main.rs
54
src/main.rs
|
@ -336,6 +336,38 @@ impl PsbQaqcResult {
|
|||
// .collect_vec()
|
||||
// }
|
||||
|
||||
fn write_psbqaqc_csv(result: MasterLogResult, outfile: PathBuf) -> Result<()> {
|
||||
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
||||
|
||||
let mut wtr = match outfile.exists() {
|
||||
true => {
|
||||
let file = File::options()
|
||||
.read(true)
|
||||
.append(true)
|
||||
.open(outfile.clone())?;
|
||||
csv::WriterBuilder::new()
|
||||
.has_headers(false)
|
||||
.from_writer(file)
|
||||
}
|
||||
false => {
|
||||
println!("Creating new file: {}", outfile.display());
|
||||
let file = File::options()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.open(outfile.clone())?;
|
||||
csv::WriterBuilder::new()
|
||||
.has_headers(true)
|
||||
.from_writer(file)
|
||||
}
|
||||
};
|
||||
for result in expanded_results {
|
||||
wtr.serialize(result)?;
|
||||
}
|
||||
wtr.flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
env_logger::Builder::new()
|
||||
|
@ -361,27 +393,7 @@ fn main() -> Result<()> {
|
|||
|
||||
let outfile = outfile.unwrap_or(get_output_filename(&result));
|
||||
|
||||
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
||||
|
||||
let mut wtr = match outfile.exists() {
|
||||
true => {
|
||||
let file = File::options().read(true).append(true).open(outfile)?;
|
||||
csv::WriterBuilder::new()
|
||||
.has_headers(false)
|
||||
.from_writer(file)
|
||||
}
|
||||
false => {
|
||||
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)
|
||||
}
|
||||
};
|
||||
for result in expanded_results {
|
||||
wtr.serialize(result)?;
|
||||
}
|
||||
wtr.flush()?;
|
||||
write_psbqaqc_csv(result, outfile)?;
|
||||
}
|
||||
Commands::CheckDB { csvfile } => {
|
||||
// TODO: more friendly message (like row number)
|
||||
|
|
Loading…
Reference in a new issue