use docker_api::models::ExecInspect200Response;
use docker_api::opts::ExecResizeOpts;
use docker_api::Exec;
use pyo3::exceptions;
use pyo3::prelude::*;
use pythonize::pythonize;
use crate::Pyo3Docker;
#[pymodule]
pub fn exec(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Pyo3Exec>()?;
Ok(())
}
#[pyclass(name = "Exec")]
pub struct Pyo3Exec {
exec: Exec,
exec_id: String,
}
#[pymethods]
impl Pyo3Exec {
#[new]
pub fn new(docker: Pyo3Docker, id: &str) -> Self {
Pyo3Exec {
exec: Exec::get(docker.0, id),
exec_id: id.to_string(),
}
}
pub fn id(&self) -> String {
self.exec_id.clone()
}
pub fn inspect(&self) -> PyResult<Py<PyAny>> {
let rv = __exec_inspect(&self.exec);
match rv {
Ok(rv) => Ok(pythonize_this!(rv)),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
#[pyo3(signature = (width, height))]
pub fn resize(&self, width: u64, height: u64) -> PyResult<()> {
let opts = ExecResizeOpts::builder()
.width(width)
.height(height)
.build();
let rv = __exec_resize(&self.exec, &opts);
match rv {
Ok(_) => Ok(()),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
}
#[tokio::main]
async fn __exec_inspect(exec: &Exec) -> Result<ExecInspect200Response, docker_api::Error> {
exec.inspect().await
}
#[tokio::main]
async fn __exec_resize(exec: &Exec, opts: &ExecResizeOpts) -> Result<(), docker_api::Error> {
exec.resize(opts).await
}