libsysf -> sysf + complete unit type
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
450e604518
commit
f8858501d7
12 changed files with 192 additions and 44 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1,13 +1,13 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "libsysf"
|
||||
name = "sysf"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "sysf-init"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libsysf 0.1.0",
|
||||
"sysf 0.1.0",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"libsysf",
|
||||
"sysf",
|
||||
"sysf-init"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
#[allow(dead_code)]
|
||||
pub struct Unit {
|
||||
description: String,
|
||||
documentation: Vec<String>,
|
||||
wants: Vec<String>,
|
||||
requires: Vec<String>,
|
||||
requisite: Vec<String>,
|
||||
binds_to: Vec<String>,
|
||||
part_of: Vec<String>,
|
||||
conflicts: Vec<String>,
|
||||
before: Vec<String>,
|
||||
after: Vec<String>,
|
||||
}
|
||||
|
|
@ -5,4 +5,4 @@ authors = ["eater <=@eater.me>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
libsysf = { path = "../libsysf" }
|
||||
sysf = { path = "../sysf" }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
extern crate libsysf;
|
||||
extern crate sysf;
|
||||
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
4
libsysf/Cargo.lock → sysf/Cargo.lock
generated
4
libsysf/Cargo.lock → sysf/Cargo.lock
generated
|
|
@ -1,6 +1,8 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "systemf"
|
||||
name = "sysf"
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
crate-type = "dylib"
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
[package]
|
||||
name = "libsysf"
|
||||
name = "sysf"
|
||||
version = "0.1.0"
|
||||
authors = ["eater <=@eater.me>"]
|
||||
edition = "2018"
|
||||
edition = "2018"
|
||||
crate-type = "dylib"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use crate::config::parser::{ParserError, parse_config};
|
||||
use crate::time::{parse_time_span, TimeSpan};
|
||||
use crate::time::{parse_finite_time_span, FiniteTimeSpan, TimeSpan, parse_time_span};
|
||||
|
||||
pub mod parser;
|
||||
|
||||
|
|
@ -66,6 +66,10 @@ impl Section {
|
|||
self.entries.get(name).map(|x| x.get_list())
|
||||
}
|
||||
|
||||
pub fn get_finite_time_span(&self, name: &str) -> Option<FiniteTimeSpan> {
|
||||
self.entries.get(name).and_then(|x| x.get_finite_time_span())
|
||||
}
|
||||
|
||||
pub fn get_time_span(&self, name: &str) -> Option<TimeSpan> {
|
||||
self.entries.get(name).and_then(|x| x.get_time_span())
|
||||
}
|
||||
|
|
@ -130,6 +134,10 @@ impl Entry {
|
|||
pub fn get_time_span(&self) -> Option<TimeSpan> {
|
||||
self.last_value().and_then(parse_time_span)
|
||||
}
|
||||
|
||||
pub fn get_finite_time_span(&self) -> Option<FiniteTimeSpan> {
|
||||
self.last_value().and_then(parse_finite_time_span)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
|
@ -88,7 +88,8 @@ pub(crate) fn parse_config(config: &mut Config, filename: String, contents: Stri
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::config::TimeSpan;
|
||||
use crate::time::FiniteTimeSpan;
|
||||
use crate::time::TimeSpan::{Finite, Infinite};
|
||||
|
||||
#[test]
|
||||
fn test_parse() {
|
||||
|
|
@ -165,6 +166,8 @@ Jump=Oh no\
|
|||
4=3m
|
||||
5=1M1m
|
||||
6=blaat
|
||||
7=infinite
|
||||
8=infinity
|
||||
".to_string());
|
||||
|
||||
assert!(res.is_ok());
|
||||
|
|
@ -172,11 +175,15 @@ Jump=Oh no\
|
|||
|
||||
let unit = config.sections.get("Unit").unwrap();
|
||||
|
||||
assert_eq!(unit.get_time_span("1"), Some(TimeSpan::new().with_hours(3)));
|
||||
assert_eq!(unit.get_time_span("2"), Some(TimeSpan::new().with_hours(1)));
|
||||
assert_eq!(unit.get_time_span("3"), Some(TimeSpan::new().with_months(3)));
|
||||
assert_eq!(unit.get_time_span("4"), Some(TimeSpan::new().with_minutes(3)));
|
||||
assert_eq!(unit.get_time_span("5"), Some(TimeSpan::new().with_months(1).with_minutes(1)));
|
||||
assert_eq!(unit.get_time_span("1"), Some(Finite(FiniteTimeSpan::new().with_hours(3))));
|
||||
assert_eq!(unit.get_time_span("2"), Some(Finite(FiniteTimeSpan::new().with_hours(1))));
|
||||
assert_eq!(unit.get_time_span("3"), Some(Finite(FiniteTimeSpan::new().with_months(3))));
|
||||
assert_eq!(unit.get_time_span("4"), Some(Finite(FiniteTimeSpan::new().with_minutes(3))));
|
||||
assert_eq!(unit.get_time_span("5"), Some(Finite(FiniteTimeSpan::new().with_months(1).with_minutes(1))));
|
||||
assert_eq!(unit.get_time_span("6"), None);
|
||||
assert_eq!(unit.get_finite_time_span("8"), None);
|
||||
assert_eq!(unit.get_finite_time_span("9"), None);
|
||||
assert_eq!(unit.get_time_span("8"), Some(Infinite));
|
||||
assert_eq!(unit.get_time_span("9"), Some(Infinite));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,13 @@
|
|||
use crate::time::TimeSpan::{Infinite, Finite};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum TimeSpan {
|
||||
Infinite,
|
||||
Finite(FiniteTimeSpan)
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct TimeSpan {
|
||||
pub struct FiniteTimeSpan {
|
||||
pub years: usize,
|
||||
pub months: usize,
|
||||
pub weeks: usize,
|
||||
|
|
@ -12,69 +20,69 @@ pub struct TimeSpan {
|
|||
pub nanoseconds: usize,
|
||||
}
|
||||
|
||||
impl TimeSpan {
|
||||
pub fn with_years(&self, years: usize) -> TimeSpan {
|
||||
impl FiniteTimeSpan {
|
||||
pub fn with_years(&self, years: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.years = years;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_months(&self, months: usize) -> TimeSpan {
|
||||
pub fn with_months(&self, months: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.months = months;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_weeks(&self, weeks: usize) -> TimeSpan {
|
||||
pub fn with_weeks(&self, weeks: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.weeks = weeks;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_days(&self, days: usize) -> TimeSpan {
|
||||
pub fn with_days(&self, days: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.days = days;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_hours(&self, hours: usize) -> TimeSpan {
|
||||
pub fn with_hours(&self, hours: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.hours = hours;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_minutes(&self, minutes: usize) -> TimeSpan {
|
||||
pub fn with_minutes(&self, minutes: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.minutes = minutes;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_seconds(&self, seconds: usize) -> TimeSpan {
|
||||
pub fn with_seconds(&self, seconds: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.seconds = seconds;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_milliseconds(&self, milliseconds: usize) -> TimeSpan {
|
||||
pub fn with_milliseconds(&self, milliseconds: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.milliseconds = milliseconds;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_microseconds(&self, microseconds: usize) -> TimeSpan {
|
||||
pub fn with_microseconds(&self, microseconds: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.microseconds = microseconds;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn with_nanoseconds(&self, nanoseconds: usize) -> TimeSpan {
|
||||
pub fn with_nanoseconds(&self, nanoseconds: usize) -> FiniteTimeSpan {
|
||||
let mut new = self.clone();
|
||||
new.nanoseconds = nanoseconds;
|
||||
new
|
||||
}
|
||||
|
||||
pub fn new() -> TimeSpan {
|
||||
TimeSpan {
|
||||
pub fn new() -> FiniteTimeSpan {
|
||||
FiniteTimeSpan {
|
||||
years: 0,
|
||||
months: 0,
|
||||
weeks: 0,
|
||||
|
|
@ -89,10 +97,17 @@ impl TimeSpan {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn parse_time_span(val: &str) -> Option<TimeSpan> {
|
||||
if val.trim() == "infinite" || val.trim() == "infinity" {
|
||||
Some(Infinite)
|
||||
} else {
|
||||
parse_finite_time_span(val).map(|x| Finite(x))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_finite_time_span(val: &str) -> Option<FiniteTimeSpan> {
|
||||
let parse = val.replace(" ", "");
|
||||
let mut time_span = TimeSpan::default();
|
||||
let mut time_span = FiniteTimeSpan::default();
|
||||
let mut current_value = String::new();
|
||||
let mut current_num = 0usize;
|
||||
|
||||
128
sysf/src/unit.rs
Normal file
128
sysf/src/unit.rs
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
use crate::unit::JobMode::Replace;
|
||||
use crate::time::{TimeSpan, FiniteTimeSpan};
|
||||
use crate::time::TimeSpan::Infinite;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Unit {
|
||||
description: String,
|
||||
|
||||
// Space only
|
||||
documentation: Vec<String>,
|
||||
|
||||
// Space -and- list
|
||||
wants: Vec<String>,
|
||||
requires: Vec<String>,
|
||||
requisite: Vec<String>,
|
||||
binds_to: Vec<String>,
|
||||
part_of: Vec<String>,
|
||||
|
||||
// Space only
|
||||
conflicts: Vec<String>,
|
||||
|
||||
// Space -and- list
|
||||
before: Vec<String>,
|
||||
after: Vec<String>,
|
||||
|
||||
// Space only
|
||||
on_failure: Vec<String>,
|
||||
|
||||
// Space -and- list
|
||||
propagates_reload_to: Vec<String>,
|
||||
propagates_reload_from: Vec<String>,
|
||||
joins_namespace_of: Vec<String>,
|
||||
requires_mounts_for: Vec<String>,
|
||||
|
||||
on_failure_job_mode: JobMode,
|
||||
|
||||
ignore_on_isolate: bool,
|
||||
stop_when_unneeded: bool,
|
||||
refuse_manual_start: bool,
|
||||
refuse_manual_stop: bool,
|
||||
allow_isolate: bool,
|
||||
default_dependencies: bool,
|
||||
collect_mode: CollectMode,
|
||||
failure_action: UnitAction,
|
||||
success_action: UnitAction,
|
||||
failure_action_exit_status: u8,
|
||||
success_action_exit_status: u8,
|
||||
job_timeout_sec: TimeSpan,
|
||||
job_running_timeout_sec: TimeSpan,
|
||||
job_timeout_action: UnitAction,
|
||||
job_timeout_reboot_argument: Option<String>,
|
||||
start_limit_interval_sec: FiniteTimeSpan,
|
||||
start_limit_burst: usize,
|
||||
start_limit_action: UnitAction,
|
||||
reboot_argument: Option<String>,
|
||||
source_path: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Unit {
|
||||
fn default() -> Self {
|
||||
Unit {
|
||||
description: "".to_string(),
|
||||
documentation: vec![],
|
||||
wants: vec![],
|
||||
requires: vec![],
|
||||
requisite: vec![],
|
||||
binds_to: vec![],
|
||||
part_of: vec![],
|
||||
conflicts: vec![],
|
||||
before: vec![],
|
||||
after: vec![],
|
||||
on_failure: vec![],
|
||||
propagates_reload_to: vec![],
|
||||
propagates_reload_from: vec![],
|
||||
joins_namespace_of: vec![],
|
||||
requires_mounts_for: vec![],
|
||||
on_failure_job_mode: Replace,
|
||||
ignore_on_isolate: false,
|
||||
stop_when_unneeded: false,
|
||||
refuse_manual_start: false,
|
||||
refuse_manual_stop: false,
|
||||
allow_isolate: false,
|
||||
default_dependencies: true,
|
||||
collect_mode: CollectMode::Inactive,
|
||||
failure_action: UnitAction::None,
|
||||
success_action: UnitAction::None,
|
||||
failure_action_exit_status: 0,
|
||||
success_action_exit_status: 0,
|
||||
job_timeout_sec: Infinite,
|
||||
job_running_timeout_sec: Infinite,
|
||||
job_timeout_action: UnitAction::None,
|
||||
job_timeout_reboot_argument: None,
|
||||
start_limit_interval_sec: Default::default(),
|
||||
start_limit_burst: 0,
|
||||
start_limit_action: UnitAction::None,
|
||||
reboot_argument: None,
|
||||
source_path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum JobMode {
|
||||
Fail,
|
||||
Replace,
|
||||
ReplaceIrreversibly,
|
||||
Isolate,
|
||||
Flush,
|
||||
IgnoreDependencies,
|
||||
IgnoreRequirements,
|
||||
}
|
||||
|
||||
enum CollectMode {
|
||||
Inactive,
|
||||
InactiveOrFailed,
|
||||
}
|
||||
|
||||
enum UnitAction {
|
||||
None,
|
||||
Reboot(UnitActionSeverity),
|
||||
PowerOff(UnitActionSeverity),
|
||||
Exit(UnitActionSeverity),
|
||||
}
|
||||
|
||||
enum UnitActionSeverity {
|
||||
None,
|
||||
Force,
|
||||
Immediate,
|
||||
}
|
||||
Loading…
Reference in a new issue