mirror of
https://github.com/LastExceed/spacermake.git
synced 2025-04-20 18:26:31 +02:00
create missing files
This commit is contained in:
parent
e028ce62b0
commit
a97b6edaa4
15
src/utils.rs
15
src/utils.rs
@ -1,15 +1,26 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::ErrorKind;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
use tap::Pipe;
|
||||||
|
|
||||||
pub mod logs;
|
pub mod logs;
|
||||||
pub mod booking;
|
pub mod booking;
|
||||||
pub mod index;
|
pub mod index;
|
||||||
|
|
||||||
pub fn parse_toml_file<T: DeserializeOwned>(path: &str) -> T {
|
pub fn parse_toml_file<T: DeserializeOwned>(path: &str) -> T {
|
||||||
let file_content = fs::read_to_string(path).expect("failed to read .toml file");
|
match fs::read_to_string(path) {
|
||||||
toml::from_str(&file_content).expect("failed to parse toml")
|
Ok(s) => s,
|
||||||
|
Err(e) if e.kind() == ErrorKind::NotFound => {
|
||||||
|
File::create(path).expect("failed to create file");
|
||||||
|
String::new()
|
||||||
|
},
|
||||||
|
_ => panic!("error reading {path}")
|
||||||
|
}
|
||||||
|
.pipe_as_ref(toml::from_str)
|
||||||
|
.expect("failed to parse toml")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_power_state(payload: &str) -> Result<String, &'static str> {
|
pub fn get_power_state(payload: &str) -> Result<String, &'static str> {
|
||||||
|
@ -32,6 +32,7 @@ pub fn machinelog(machine: &str, booking: &Booking) -> io::Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let file_writer = File::options()
|
let file_writer = File::options()
|
||||||
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open("/root/machinelog.csv")?;
|
.open("/root/machinelog.csv")?;
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ pub fn machinelog(machine: &str, booking: &Booking) -> io::Result<()> {
|
|||||||
|
|
||||||
pub fn log_start() -> io::Result<()> {
|
pub fn log_start() -> io::Result<()> {
|
||||||
File::options()
|
File::options()
|
||||||
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open("/root/machinelog_debug.csv")?
|
.open("/root/machinelog_debug.csv")?
|
||||||
.write_all(format!("\n\n===== startup {} =====\n\n", Local::now()).as_bytes())
|
.write_all(format!("\n\n===== startup {} =====\n\n", Local::now()).as_bytes())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user