Skip to content

Commit

Permalink
Split output into output_dir and output_filename
Browse files Browse the repository at this point in the history
This commit syncs the app with `gwasm-rust-api` v0.1.2 which now
requires specifying `output_path` field in the `Task::Options`
definition. To achieve this, this commit splits the `output` path
into two subcomponents: `output_dir` and `output_filename`.

This commit partially addresses #28.
  • Loading branch information
Jakub Konka authored and kubkon committed Nov 1, 2019
1 parent 4a741b8 commit f84e518
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "g-flite"
version = "0.4.0"
version = "0.4.1"
authors = ["Golem RnD Team <[email protected]>"]
edition = "2018"
license = "GPL-3.0"
Expand All @@ -16,7 +16,7 @@ log = "0.4.6"
env_logger = "0.6.1"
failure="0.1.5"
appdirs = "0.2"
gwasm-api = { git = "https://github.com/golemfactory/gwasm-rust-api", tag = "0.1.0" }
gwasm-api = { git = "https://github.com/golemfactory/gwasm-rust-api", tag = "0.1.2" }
hound = { git = "https://github.com/kubkon/hound" }
openssl = "0.10.20"
structopt = "0.2.18"
Expand Down
Binary file modified assets/flite.wasm
Binary file not shown.
50 changes: 33 additions & 17 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ impl ProgressUpdate for ProgressUpdater {
#[derive(Debug)]
pub struct App {
input: PathBuf,
output: PathBuf,
output_dir: PathBuf,
output_filename: PathBuf,
datadir: PathBuf,
address: String,
port: u16,
Expand Down Expand Up @@ -156,11 +157,13 @@ impl App {
js: FLITE_JS,
wasm: FLITE_WASM,
};
// get expected output dir (if any)
let mut task_builder = TaskBuilder::new(&self.workspace, binary)
.name("g_flite")
.bid(self.bid)
.timeout(self.task_timeout)
.subtask_timeout(self.subtask_timeout);
.subtask_timeout(self.subtask_timeout)
.output_path(&self.output_dir);

for chunk in chunks {
task_builder = task_builder.push_subtask_data(chunk.as_bytes());
Expand All @@ -172,11 +175,12 @@ impl App {
}

fn combine_output(&self, task: ComputedTask) -> Result<()> {
let output = self.output_dir.join(&self.output_filename);
println!(
"{} {}Combining output into '{}'...",
style("[4/4]").bold().dim(),
CLIP,
self.output.display()
output.display()
);

let mut writer: Option<hound::WavWriter<_>> = None;
Expand All @@ -189,15 +193,9 @@ impl App {
.map_err(|e| format!("parsing WAVE input: {}", e))?;

if writer.is_none() {
writer = Some(
hound::WavWriter::create(&self.output, reader.spec()).map_err(|e| {
format!(
"creating output WAVE file '{}': {}",
self.output.display(),
e
)
})?,
);
writer = Some(hound::WavWriter::create(&output, reader.spec()).map_err(
|e| format!("creating output WAVE file '{}': {}", output.display(), e),
)?);
}

let mut wrt = writer.as_mut().unwrap().get_i16_writer(reader.len());
Expand All @@ -209,7 +207,7 @@ impl App {
wrt.flush().map_err(|e| {
format!(
"writing audio samples to file '{}': {}",
self.output.display(),
output.display(),
e
)
})?;
Expand All @@ -223,6 +221,8 @@ impl App {
let chunks = self.split_input()?;
let task = self.prepare_task(chunks)?;

log::debug!("g_flite run task = {:?}", task);

println!(
"{} {}Sending task to Golem...",
style("[2/4]").bold().dim(),
Expand Down Expand Up @@ -264,16 +264,31 @@ impl TryFrom<Opt> for App {
}

// verify output path excluding topmost file exists
if let Some(parent) = opt.output.parent() {
let output_dir = if let Some(parent) = opt.output.parent() {
let parent_str = parent.to_string_lossy();
if !parent_str.is_empty() && !parent.exists() {
return Err(format!(
"Output path '{}' doesn't exist. Did you make a typo anywhere?",
parent_str,
));
}
}
let output = opt.output;

parent
} else {
Path::new(".")
};
let output_dir = output_dir.canonicalize().map_err(|e| {
format!(
"working out absolute path for the expected output path '{}': {}",
output_dir.display(),
e
)
})?;
let output_filename = opt
.output
.file_name()
.map(PathBuf::from)
.ok_or(format!("working out the expected output filename"))?;

let datadir = match opt.datadir {
Some(datadir) => datadir.canonicalize().map_err(|e| {
Expand Down Expand Up @@ -325,7 +340,8 @@ impl TryFrom<Opt> for App {

Ok(Self {
input,
output,
output_dir,
output_filename,
datadir,
address,
port,
Expand Down

0 comments on commit f84e518

Please sign in to comment.