mirror of
https://github.com/ankitects/anki.git
synced 2026-01-14 22:39:06 -05:00
- Adding files inside Anki now updates the media DB, so a full file scan at sync time is no longer required if no other changes have been made. - Use a protobuf message for backend initialization, and return a string error if initialization fails.
42 lines
1 KiB
Rust
42 lines
1 KiB
Rust
use anki::backend::{init_backend, Backend as RustBackend};
|
|
use pyo3::prelude::*;
|
|
use pyo3::types::PyBytes;
|
|
use pyo3::{exceptions, wrap_pyfunction};
|
|
|
|
#[pyclass]
|
|
struct Backend {
|
|
backend: RustBackend,
|
|
}
|
|
|
|
#[pyfunction]
|
|
fn buildhash() -> &'static str {
|
|
include_str!("../../meta/buildhash").trim()
|
|
}
|
|
|
|
#[pymethods]
|
|
impl Backend {
|
|
#[new]
|
|
fn init(obj: &PyRawObject, init_msg: &PyBytes) -> PyResult<()> {
|
|
match init_backend(init_msg.as_bytes()) {
|
|
Ok(backend) => {
|
|
obj.init({ Backend { backend } });
|
|
Ok(())
|
|
}
|
|
Err(e) => Err(exceptions::Exception::py_err(e)),
|
|
}
|
|
}
|
|
|
|
fn command(&mut self, py: Python, input: &PyBytes) -> PyObject {
|
|
let out_bytes = self.backend.run_command_bytes(input.as_bytes());
|
|
let out_obj = PyBytes::new(py, &out_bytes);
|
|
out_obj.into()
|
|
}
|
|
}
|
|
|
|
#[pymodule]
|
|
fn ankirspy(_py: Python, m: &PyModule) -> PyResult<()> {
|
|
m.add_class::<Backend>()?;
|
|
m.add_wrapped(wrap_pyfunction!(buildhash)).unwrap();
|
|
|
|
Ok(())
|
|
}
|