Skip to content

Commit

Permalink
Impl for Python Api with Recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
wychlw committed Aug 29, 2024
1 parent 75040b5 commit 09efec2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/device/device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(dead_code)]

use std::error::Error;

use crate::term::{serial::Serial, ssh::SshPass, tty::{DynTty, Tty}};
use crate::term::{ssh::SshPass, tty::DynTty};


struct ShellOptions {
Expand Down
62 changes: 44 additions & 18 deletions src/pythonapi/shell_like.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
use std::{
any::TypeId,
ops::Deref,
ptr::{null, null_mut},
};
use std::ptr::null_mut;

use pyo3::{exceptions::PyTypeError, prelude::*};
use serde::Deserialize;

use crate::{
dyn_into,
exec::cli_api::{CliTestApi, SudoCliTestApi},
term::{
asciicast::Asciicast,
recorder::{self, Recorder, SimpleRecorder},
serial::Serial,
shell::Shell,
ssh::Ssh,
tty::{DynTty, Tty, WrapperTty},
},
util::anybase::AnyBase,
use crate::term::{
asciicast::Asciicast,
recorder::{Recorder, SimpleRecorder},
serial::Serial,
shell::Shell,
ssh::Ssh,
tty::{DynTty, WrapperTty},
};

type TtyType = DynTty;
Expand Down Expand Up @@ -368,6 +359,41 @@ impl PyTty {
}

fn swap(&mut self, other: &mut Self) -> PyResult<()> {
todo!()
let inner = self.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<Shell>() {
Err(PyTypeError::new_err("Can't convert to the type you want"))
} else if let Some(_) = inner.downcast_ref::<Serial>() {
Err(PyTypeError::new_err("Can't convert to the type you want"))
} else if let Some(_) = inner.downcast_ref::<Ssh>() {
Err(PyTypeError::new_err("Can't convert to the type you want"))
} else if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
let inner = inner.downcast_mut::<SimpleRecorder>().unwrap();
let target = other.inner.safe_take()?;
let target = Box::into_inner(target);
let target = inner.swap(target);
if let Err(e) = target {
return Err(PyTypeError::new_err(e.to_string()));
}
let target = target.unwrap();
other.inner.tty = heap_raw(target);
Ok(())
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
let inner = inner.downcast_mut::<Asciicast>().unwrap();
let target = other.inner.safe_take()?;
let target = Box::into_inner(target);
let target = inner.swap(target);
if let Err(e) = target {
return Err(PyTypeError::new_err(e.to_string()));
}
let target = target.unwrap();
other.inner.tty = heap_raw(target);
Ok(())
} else {
Err(PyTypeError::new_err(
"What type is this? How do you get it?",
))
}
}
}
2 changes: 1 addition & 1 deletion src/term/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
time::Duration,
};

use ssh2::{Channel, Session};
use ssh2::Channel;

use crate::{
consts::SHELL_DURATION,
Expand Down

0 comments on commit 09efec2

Please sign in to comment.