mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-08 15:40:34 -04:00
Add script_output to get output from a script.
Check for errors, but otherwise get output, using process.wait() to wait for all output, etc.
This commit is contained in:
parent
96b42d1338
commit
c06da2f376
1 changed files with 27 additions and 1 deletions
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError};
|
||||
use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError, Redirection};
|
||||
use zbus_macros::dbus_interface;
|
||||
pub struct SMManager {
|
||||
}
|
||||
|
@ -45,6 +45,20 @@ fn run_script(name: &str, argv: &[impl AsRef<OsStr>]) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn script_output(argv: &[impl AsRef<OsStr>]) -> Result<String, PopenError> {
|
||||
// Run given command and return the output given
|
||||
let mut process = Popen::create(argv, PopenConfig {
|
||||
stdout: Redirection::Pipe,
|
||||
..Default::default()
|
||||
})?;
|
||||
let (output, _err) = process.communicate(None)?;
|
||||
let _exit_status = process.wait()?;
|
||||
match output {
|
||||
Some(output_strings) => Ok(output_strings),
|
||||
None => Err(PopenError::LogicError("Error getting output"))
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "com.steampowered.SteamOSManager1")]
|
||||
impl SMManager {
|
||||
const API_VERSION: u32 = 1;
|
||||
|
@ -79,6 +93,18 @@ impl SMManager {
|
|||
run_script("check hardware support", &["jupiter-check-support"])
|
||||
}
|
||||
|
||||
async fn read_als_calibration(&self) -> f32 {
|
||||
// Run script to get calibration value
|
||||
let result = script_output(&["/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain"]);
|
||||
let mut value: f32 = -1.0;
|
||||
match result {
|
||||
Ok(as_string) => value = as_string.trim().parse().unwrap(),
|
||||
Err(message) => println!("Unable to run als calibration script : {}", message),
|
||||
}
|
||||
|
||||
value
|
||||
}
|
||||
|
||||
/// A version property.
|
||||
#[dbus_interface(property)]
|
||||
async fn version(&self) -> u32 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue