mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
remove unused functionality
This commit is contained in:
@@ -186,7 +186,7 @@ impl FactoryComponent for Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {
|
fn update_cmd(&mut self, message: Self::CommandOutput, _sender: FactorySender<Self>) {
|
||||||
match message {
|
match message {
|
||||||
CommandMessage::SetStarted => self.status = ContainerStatus::Running,
|
CommandMessage::SetStarted => self.status = ContainerStatus::Running,
|
||||||
CommandMessage::SetStopped => self.status = ContainerStatus::NotRunning,
|
CommandMessage::SetStopped => self.status = ContainerStatus::NotRunning,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use std::{fmt::Display, process::Command, str::FromStr};
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum ToolbxError {
|
pub enum ToolbxError {
|
||||||
ParseStatusError(String),
|
ParseStatusError(String),
|
||||||
JSONSerializationError(String),
|
|
||||||
CommandExecutionError(String),
|
CommandExecutionError(String),
|
||||||
CommandUnsuccessfulError(String),
|
CommandUnsuccessfulError(String),
|
||||||
}
|
}
|
||||||
@@ -18,9 +17,6 @@ impl Display for ToolbxError {
|
|||||||
ToolbxError::CommandExecutionError(command_exec_error) => {
|
ToolbxError::CommandExecutionError(command_exec_error) => {
|
||||||
write!(f, "{}", command_exec_error)
|
write!(f, "{}", command_exec_error)
|
||||||
}
|
}
|
||||||
ToolbxError::JSONSerializationError(msg) => {
|
|
||||||
write!(f, "{}", msg)
|
|
||||||
}
|
|
||||||
ToolbxError::CommandUnsuccessfulError(command_unsuc_error) => {
|
ToolbxError::CommandUnsuccessfulError(command_unsuc_error) => {
|
||||||
write!(f, "{}", command_unsuc_error)
|
write!(f, "{}", command_unsuc_error)
|
||||||
}
|
}
|
||||||
@@ -68,85 +64,12 @@ pub struct ToolbxContainer {
|
|||||||
pub image: String,
|
pub image: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PodmanInspectArray = Vec<PodmanInspectInfo>;
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PodmanInspectInfo {
|
|
||||||
#[serde(rename = "Id")]
|
|
||||||
pub id: String,
|
|
||||||
#[serde(rename = "Created")]
|
|
||||||
pub created: String,
|
|
||||||
#[serde(rename = "State")]
|
|
||||||
pub state: PodManInspectState,
|
|
||||||
#[serde(rename = "Image")]
|
|
||||||
pub image: String,
|
|
||||||
#[serde(rename = "ImageName")]
|
|
||||||
pub image_name: String,
|
|
||||||
#[serde(rename = "Name")]
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PodManInspectState {
|
|
||||||
#[serde(rename = "Status")]
|
|
||||||
pub status: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ToolboxCreateParameter {
|
|
||||||
None,
|
|
||||||
Distro(String),
|
|
||||||
Image(String),
|
|
||||||
Release(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToolbxContainer {
|
impl ToolbxContainer {
|
||||||
pub fn new(name: String) -> ToolbxContainer {
|
|
||||||
ToolbxContainer {
|
|
||||||
name: name,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create(name: String, parameter: ToolboxCreateParameter) {
|
|
||||||
todo!("Implement actual functionality to create toolbox via commandline")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_toolboxes() -> Vec<ToolbxContainer> {
|
pub fn get_toolboxes() -> Vec<ToolbxContainer> {
|
||||||
let output = run_cmd_toolbx_list_containers();
|
let output = run_cmd_toolbx_list_containers();
|
||||||
println!("{}", output);
|
println!("{}", output);
|
||||||
parse_cmd_list_containers(output.as_str())
|
parse_cmd_list_containers(output.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_status(output: &str) -> Result<PodmanInspectInfo, ToolbxError> {
|
|
||||||
let result: Result<PodmanInspectArray, _> = serde_json::from_str(output);
|
|
||||||
match result {
|
|
||||||
Ok(inspect_vec) => match inspect_vec.first() {
|
|
||||||
Some(info) => Ok(info.clone()),
|
|
||||||
None => Err(ToolbxError::JSONSerializationError(
|
|
||||||
"Inspect command returned empty vector.".to_string(),
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
Err(e) => Err(ToolbxError::JSONSerializationError(e.to_string())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_status(&mut self) -> Result<(), ToolbxError> {
|
|
||||||
let output = Command::new("flatpak-spawn")
|
|
||||||
.arg("--host")
|
|
||||||
.arg("podman")
|
|
||||||
.arg("container")
|
|
||||||
.arg("inspect")
|
|
||||||
.arg(self.name.clone())
|
|
||||||
.output()
|
|
||||||
.expect("Failed to execute command");
|
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout).to_string();
|
|
||||||
let inspect_result = ToolbxContainer::parse_status(output.as_str())?;
|
|
||||||
self.status = ToolbxStatus::from_str(inspect_result.state.status.as_str())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_toolbox_container_in_terminal(hash: &str) -> Result<(), ToolbxError> {
|
pub fn open_toolbox_container_in_terminal(hash: &str) -> Result<(), ToolbxError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user