mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
pass collection path into backend
This commit is contained in:
parent
d782569b33
commit
caab7092ef
4 changed files with 11 additions and 13 deletions
|
@ -42,8 +42,8 @@ def proto_template_reqs_to_legacy(
|
|||
|
||||
|
||||
class Backend:
|
||||
def __init__(self):
|
||||
self._backend = _ankirs.Backend()
|
||||
def __init__(self, path: str):
|
||||
self._backend = _ankirs.Backend(path)
|
||||
|
||||
def _run_command(self, input: pb.BackendInput) -> pb.BackendOutput:
|
||||
input_bytes = input.SerializeToString()
|
||||
|
|
|
@ -30,7 +30,7 @@ def Collection(
|
|||
path: str, lock: bool = True, server: Optional[ServerData] = None, log: bool = False
|
||||
) -> _Collection:
|
||||
"Open a new or existing collection. Path must be unicode."
|
||||
backend = Backend()
|
||||
backend = Backend(path)
|
||||
# fixme: this call is temporarily here to ensure the brige is working
|
||||
# on all platforms, and should be removed in a future beta
|
||||
assert backend.plus_one(5) == 6
|
||||
|
|
|
@ -5,13 +5,11 @@ use crate::sched::sched_timing_today;
|
|||
use crate::template::{FieldMap, FieldRequirements, ParsedTemplate};
|
||||
use prost::Message;
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct Backend {}
|
||||
|
||||
impl Default for Backend {
|
||||
fn default() -> Self {
|
||||
Backend {}
|
||||
}
|
||||
pub struct Backend {
|
||||
#[allow(dead_code)]
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
/// Convert an Anki error to a protobuf error.
|
||||
|
@ -37,8 +35,8 @@ impl std::convert::From<AnkiError> for pt::backend_output::Value {
|
|||
}
|
||||
|
||||
impl Backend {
|
||||
pub fn new() -> Backend {
|
||||
Backend::default()
|
||||
pub fn new<P: Into<PathBuf>>(path: P) -> Backend {
|
||||
Backend { path: path.into() }
|
||||
}
|
||||
|
||||
/// Decode a request, process it, and return the encoded result.
|
||||
|
|
|
@ -10,10 +10,10 @@ struct Backend {
|
|||
#[pymethods]
|
||||
impl Backend {
|
||||
#[new]
|
||||
fn init(obj: &PyRawObject) {
|
||||
fn init(obj: &PyRawObject, path: String) {
|
||||
obj.init({
|
||||
Backend {
|
||||
backend: Default::default(),
|
||||
backend: RustBackend::new(path),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue