mirror of
https://github.com/LastExceed/spacermake.git
synced 2025-04-19 17:56:27 +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::File;
|
||||
use std::io::ErrorKind;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use tap::Pipe;
|
||||
|
||||
pub mod logs;
|
||||
pub mod booking;
|
||||
pub mod index;
|
||||
|
||||
pub fn parse_toml_file<T: DeserializeOwned>(path: &str) -> T {
|
||||
let file_content = fs::read_to_string(path).expect("failed to read .toml file");
|
||||
toml::from_str(&file_content).expect("failed to parse toml")
|
||||
match fs::read_to_string(path) {
|
||||
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> {
|
||||
|
@ -32,6 +32,7 @@ pub fn machinelog(machine: &str, booking: &Booking) -> io::Result<()> {
|
||||
};
|
||||
|
||||
let file_writer = File::options()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open("/root/machinelog.csv")?;
|
||||
|
||||
@ -47,6 +48,7 @@ pub fn machinelog(machine: &str, booking: &Booking) -> io::Result<()> {
|
||||
|
||||
pub fn log_start() -> io::Result<()> {
|
||||
File::options()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open("/root/machinelog_debug.csv")?
|
||||
.write_all(format!("\n\n===== startup {} =====\n\n", Local::now()).as_bytes())
|
||||
|
Loading…
x
Reference in New Issue
Block a user