From caab7092ef9c0c86f93350779364fc7c73e4a55d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 29 Dec 2019 20:36:23 +1000 Subject: [PATCH] pass collection path into backend --- anki/backend.py | 4 ++-- anki/storage.py | 2 +- rs/ankirs/src/backend.rs | 14 ++++++-------- rs/pymod/src/lib.rs | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/anki/backend.py b/anki/backend.py index 6aa3ff664..945c1de8c 100644 --- a/anki/backend.py +++ b/anki/backend.py @@ -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() diff --git a/anki/storage.py b/anki/storage.py index 26533c350..7556298fb 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -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 diff --git a/rs/ankirs/src/backend.rs b/rs/ankirs/src/backend.rs index 86fe70e36..5236c9bfc 100644 --- a/rs/ankirs/src/backend.rs +++ b/rs/ankirs/src/backend.rs @@ -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 for pt::backend_output::Value { } impl Backend { - pub fn new() -> Backend { - Backend::default() + pub fn new>(path: P) -> Backend { + Backend { path: path.into() } } /// Decode a request, process it, and return the encoded result. diff --git a/rs/pymod/src/lib.rs b/rs/pymod/src/lib.rs index dbb18c339..8956a38b8 100644 --- a/rs/pymod/src/lib.rs +++ b/rs/pymod/src/lib.rs @@ -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), } }); }