diff options
Diffstat (limited to 'subplotlib/src/steplibrary')
-rw-r--r-- | subplotlib/src/steplibrary/datadir.rs | 11 | ||||
-rw-r--r-- | subplotlib/src/steplibrary/runcmd.rs | 15 |
2 files changed, 26 insertions, 0 deletions
diff --git a/subplotlib/src/steplibrary/datadir.rs b/subplotlib/src/steplibrary/datadir.rs index 8aa6f00..88e6375 100644 --- a/subplotlib/src/steplibrary/datadir.rs +++ b/subplotlib/src/steplibrary/datadir.rs @@ -91,6 +91,17 @@ impl Datadir { .open(full_path)? } + /// Open a file for reading + #[throws(StepError)] + pub fn open_read<S: AsRef<Path>>(&self, subpath: S) -> File { + let full_path = self.canonicalise_filename(subpath)?; + OpenOptions::new() + .create(false) + .write(false) + .read(true) + .open(full_path)? + } + #[throws(StepError)] pub fn create_dir_all<S: AsRef<Path>>(&self, subpath: S) { let full_path = self.canonicalise_filename(subpath)?; diff --git a/subplotlib/src/steplibrary/runcmd.rs b/subplotlib/src/steplibrary/runcmd.rs index f42df6e..5fc12eb 100644 --- a/subplotlib/src/steplibrary/runcmd.rs +++ b/subplotlib/src/steplibrary/runcmd.rs @@ -67,9 +67,24 @@ impl ContextElement for Runcmd { } impl Runcmd { + /// Prepend the given location to the run path pub fn prepend_to_path<S: Into<OsString>>(&mut self, element: S) { self.paths.push(element.into()); } + + /// Retrieve the last run command's stdout as a string. + /// + /// This does a lossy conversion from utf8 so should always succeed. + pub fn stdout_as_string(&self) -> String { + String::from_utf8_lossy(&self.stdout).into_owned() + } + + /// Retrieve the last run command's stderr as a string. + /// + /// This does a lossy conversion from utf8 so should always succeed. + pub fn stderr_as_string(&self) -> String { + String::from_utf8_lossy(&self.stderr).into_owned() + } } #[step] |