Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Patro committed Feb 1, 2024
1 parent c521a6d commit 410af7c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 71 deletions.
68 changes: 15 additions & 53 deletions src/utils/af_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use anyhow::{anyhow, bail, Result};
use anyhow::{bail, Result};
use cmd_lib::run_fun;
use phf::phf_map;
use seq_geom_parser::{AppendToCmdArgs, FragmentGeomDesc, PiscemGeomDesc, SalmonSeparateGeomDesc};
use seq_geom_xform::{FifoXFormData, FragmentGeomDescExt};
use std::path::{Path, PathBuf};
use tracing::error;

use crate::utils::prog_utils;
//use ureq;
//use minreq::Response;

Expand Down Expand Up @@ -173,25 +175,17 @@ pub fn get_permit_if_absent(af_home: &Path, chem: &Chemistry) -> Result<PermitLi
let opt_dl_url: Option<String>;
match chem {
Chemistry::TenxV2 => {
if let Some(ref d) = permit_dict.get("10xv2") {
opt_chem_file = if let Some(cf) = d
if let Some(d) = permit_dict.get("10xv2") {
opt_chem_file = d
.get("filename")
.expect("value for filename field should be a string")
.as_str()
{
Some(cf.to_string())
} else {
None
};
opt_dl_url = if let Some(url) = d
.map(|cf| cf.to_string());
opt_dl_url = d
.get("url")
.expect("value for url field should be a string")
.as_str()
{
Some(url.to_string())
} else {
None
};
.map(|url| url.to_string());
} else {
bail!(
"could not obtain \"10xv2\" key from the fetched permit_dict at {} = {:?}",
Expand All @@ -201,25 +195,17 @@ pub fn get_permit_if_absent(af_home: &Path, chem: &Chemistry) -> Result<PermitLi
}
}
Chemistry::TenxV3 => {
if let Some(ref d) = permit_dict.get("10xv3") {
opt_chem_file = if let Some(cf) = d
if let Some(d) = permit_dict.get("10xv3") {
opt_chem_file = d
.get("filename")
.expect("value for filename field should be a string")
.as_str()
{
Some(cf.to_string())
} else {
None
};
opt_dl_url = if let Some(url) = d
.map(|cf| cf.to_string());
opt_dl_url = d
.get("url")
.expect("value for url field should be a string")
.as_str()
{
Some(url.to_string())
} else {
None
};
.map(|url| url.to_string());
} else {
bail!(
"could not obtain \"10xv3\" key from the fetched permit_dict at {} = {:?}",
Expand All @@ -240,33 +226,9 @@ pub fn get_permit_if_absent(af_home: &Path, chem: &Chemistry) -> Result<PermitLi
} else {
run_fun!(mkdir -p $odir)?;

let permit_request = minreq::get(dl_url).with_timeout(120).send()?;
match permit_request.status_code {
200..=299 => {
// success
},
x => {
bail!("could not obtain the permit list; HTTP status code {}, reason {}", x, permit_request.reason_phrase);
}
}
let output_file = odir.join(&chem_file).to_string_lossy().to_string();
prog_utils::download_to_file(dl_url, &output_file)?;

let mut permit_file = std::fs::File::create(odir.join(&chem_file).to_string_lossy().to_string())?;
use std::io::Write;
permit_file.write_all(permit_request.as_bytes())?;

/*
let mut dl_cmd = std::process::Command::new("wget");
dl_cmd
.arg("-v")
.arg("-O")
.arg(odir.join(&chem_file).to_string_lossy().to_string())
.arg("-L")
.arg(dl_url);
let r = dl_cmd.output()?;
if !r.status.success() {
return Err(anyhow!("failed to download permit list {:?}", r.status));
}
*/
Ok(PermitListResult::DownloadSuccessful(odir.join(&chem_file)))
}
} else {
Expand Down
24 changes: 23 additions & 1 deletion src/utils/prog_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, bail, Context, Result};
use cmd_lib::run_fun;
use semver::{Version, VersionReq};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -48,6 +48,28 @@ pub fn shell<S: AsRef<OsStr>>(cmd: S) -> Command {
command
}

pub fn download_to_file<T: AsRef<str>>(url: T, filename: &str) -> Result<()> {
let url = url.as_ref();
let request = minreq::get(url).with_timeout(120).send()?;
match request.status_code {
200..=299 => {
// success
}
x => {
bail!(
"could not obtain the permit list; HTTP status code {}, reason {}",
x,
request.reason_phrase
);
}
}

let mut out_file = std::fs::File::create(filename)?;
use std::io::Write;
out_file.write_all(request.as_bytes())?;
Ok(())
}

pub fn get_cmd_line_string(prog: &std::process::Command) -> String {
let mut prog_vec = vec![prog.get_program().to_string_lossy().to_string()];
prog_vec.extend(
Expand Down
19 changes: 2 additions & 17 deletions src/utils/workflow_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,23 +1291,8 @@ pub fn get_protocol_estuary<T: AsRef<Path>>(
run_cmd!(mkdir -p $pe_dir)?;
}

// download github repo as a zip file
let mut dl_cmd = std::process::Command::new("wget");
dl_cmd
.arg("-v")
.arg("-O")
.arg(pe_zip_file.to_string_lossy().to_string())
.arg("-L")
.arg(dl_url);
match prog_utils::execute_command(&mut dl_cmd, CommandVerbosityLevel::Quiet) {
Ok(_output) => {}
Err(e) => {
return Err(anyhow!(
"failed to download protocol-estuary GitHub repository; error: {:?}",
e
));
}
}
let out_fname = pe_zip_file.to_string_lossy().to_string();
prog_utils::download_to_file(dl_url, &out_fname)?;

// unzip
let mut unzip_cmd = std::process::Command::new("unzip");
Expand Down

0 comments on commit 410af7c

Please sign in to comment.