pass collection path into backend

This commit is contained in:
Damien Elmes 2019-12-29 20:36:23 +10:00
parent d782569b33
commit caab7092ef
4 changed files with 11 additions and 13 deletions

View file

@ -42,8 +42,8 @@ def proto_template_reqs_to_legacy(
class Backend: class Backend:
def __init__(self): def __init__(self, path: str):
self._backend = _ankirs.Backend() self._backend = _ankirs.Backend(path)
def _run_command(self, input: pb.BackendInput) -> pb.BackendOutput: def _run_command(self, input: pb.BackendInput) -> pb.BackendOutput:
input_bytes = input.SerializeToString() input_bytes = input.SerializeToString()

View file

@ -30,7 +30,7 @@ def Collection(
path: str, lock: bool = True, server: Optional[ServerData] = None, log: bool = False path: str, lock: bool = True, server: Optional[ServerData] = None, log: bool = False
) -> _Collection: ) -> _Collection:
"Open a new or existing collection. Path must be unicode." "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 # fixme: this call is temporarily here to ensure the brige is working
# on all platforms, and should be removed in a future beta # on all platforms, and should be removed in a future beta
assert backend.plus_one(5) == 6 assert backend.plus_one(5) == 6

View file

@ -5,13 +5,11 @@ use crate::sched::sched_timing_today;
use crate::template::{FieldMap, FieldRequirements, ParsedTemplate}; use crate::template::{FieldMap, FieldRequirements, ParsedTemplate};
use prost::Message; use prost::Message;
use std::collections::HashSet; use std::collections::HashSet;
use std::path::PathBuf;
pub struct Backend {} pub struct Backend {
#[allow(dead_code)]
impl Default for Backend { path: PathBuf,
fn default() -> Self {
Backend {}
}
} }
/// Convert an Anki error to a protobuf error. /// Convert an Anki error to a protobuf error.
@ -37,8 +35,8 @@ impl std::convert::From<AnkiError> for pt::backend_output::Value {
} }
impl Backend { impl Backend {
pub fn new() -> Backend { pub fn new<P: Into<PathBuf>>(path: P) -> Backend {
Backend::default() Backend { path: path.into() }
} }
/// Decode a request, process it, and return the encoded result. /// Decode a request, process it, and return the encoded result.

View file

@ -10,10 +10,10 @@ struct Backend {
#[pymethods] #[pymethods]
impl Backend { impl Backend {
#[new] #[new]
fn init(obj: &PyRawObject) { fn init(obj: &PyRawObject, path: String) {
obj.init({ obj.init({
Backend { Backend {
backend: Default::default(), backend: RustBackend::new(path),
} }
}); });
} }