mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-22 07:10:18 +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()
|
// .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<()> {
|
fn main() -> Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
env_logger::Builder::new()
|
env_logger::Builder::new()
|
||||||
|
@ -361,27 +393,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let outfile = outfile.unwrap_or(get_output_filename(&result));
|
let outfile = outfile.unwrap_or(get_output_filename(&result));
|
||||||
|
|
||||||
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
|
write_psbqaqc_csv(result, outfile)?;
|
||||||
|
|
||||||
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()?;
|
|
||||||
}
|
}
|
||||||
Commands::CheckDB { csvfile } => {
|
Commands::CheckDB { csvfile } => {
|
||||||
// TODO: more friendly message (like row number)
|
// TODO: more friendly message (like row number)
|
||||||
|
|
Loading…
Reference in a new issue