Support remote libraries #36

Merged
wojtek merged 5 commits from 5---support-remote-libraries into main 2023-04-14 16:21:25 +02:00
3 changed files with 18 additions and 17 deletions
Showing only changes of commit 1c9ef378f7 - Show all commits

View File

@ -95,7 +95,7 @@ trait LibraryPrivate {
} }
impl<BLE: BeetsLibraryExecutor> BeetsLibrary<BLE> { impl<BLE: BeetsLibraryExecutor> BeetsLibrary<BLE> {
/// Create a new beets library with the provided executor, e.g. [`BeetsLibraryCommandExecutor`]. /// Create a new beets library with the provided executor, e.g. [`BeetsLibraryProcessExecutor`].
pub fn new(executor: BLE) -> Self { pub fn new(executor: BLE) -> Self {
BeetsLibrary { executor } BeetsLibrary { executor }
} }
@ -199,15 +199,15 @@ impl<BLE: BeetsLibraryExecutor> LibraryPrivate for BeetsLibrary<BLE> {
} }
/// Beets library executor that executes beets commands in their own process. /// Beets library executor that executes beets commands in their own process.
pub struct BeetsLibraryCommandExecutor { pub struct BeetsLibraryProcessExecutor {
bin: OsString, bin: OsString,
config: Option<PathBuf>, config: Option<PathBuf>,
} }
impl BeetsLibraryCommandExecutor { impl BeetsLibraryProcessExecutor {
/// Create a new [`BeetsLibraryCommandExecutor`] that uses the provided beets executable. /// Create a new [`BeetsLibraryProcessExecutor`] that uses the provided beets executable.
pub fn new<S: Into<OsString>>(bin: S) -> Self { pub fn new<S: Into<OsString>>(bin: S) -> Self {
BeetsLibraryCommandExecutor { BeetsLibraryProcessExecutor {
bin: bin.into(), bin: bin.into(),
config: None, config: None,
} }
@ -220,14 +220,15 @@ impl BeetsLibraryCommandExecutor {
} }
} }
impl Default for BeetsLibraryCommandExecutor { impl Default for BeetsLibraryProcessExecutor {
/// Create a new [`BeetsLibraryCommandExecutor`] that uses the system's default beets executable. /// Create a new [`BeetsLibraryProcessExecutor`] that uses the system's default beets
/// executable.
fn default() -> Self { fn default() -> Self {
BeetsLibraryCommandExecutor::new("beet") BeetsLibraryProcessExecutor::new("beet")
} }
} }
impl BeetsLibraryExecutor for BeetsLibraryCommandExecutor { impl BeetsLibraryExecutor for BeetsLibraryProcessExecutor {
fn exec<S: AsRef<str> + 'static>(&mut self, arguments: &[S]) -> Result<Vec<String>, Error> { fn exec<S: AsRef<str> + 'static>(&mut self, arguments: &[S]) -> Result<Vec<String>, Error> {
let mut cmd = Command::new(&self.bin); let mut cmd = Command::new(&self.bin);
if let Some(ref path) = self.config { if let Some(ref path) = self.config {

View File

@ -8,7 +8,7 @@ use structopt::StructOpt;
use musichoard::{ use musichoard::{
collection::MhCollectionManager, collection::MhCollectionManager,
database::json::{JsonDatabase, JsonDatabaseFileBackend}, database::json::{JsonDatabase, JsonDatabaseFileBackend},
library::beets::{BeetsLibrary, BeetsLibraryCommandExecutor}, library::beets::{BeetsLibrary, BeetsLibraryProcessExecutor},
}; };
mod tui; mod tui;
@ -42,7 +42,7 @@ fn main() {
let opt = Opt::from_args(); let opt = Opt::from_args();
let beets = BeetsLibrary::new( let beets = BeetsLibrary::new(
BeetsLibraryCommandExecutor::default().config(opt.beets_config_file_path.as_deref()), BeetsLibraryProcessExecutor::default().config(opt.beets_config_file_path.as_deref()),
); );
let database = JsonDatabase::new(JsonDatabaseFileBackend::new(&opt.database_file_path)); let database = JsonDatabase::new(JsonDatabaseFileBackend::new(&opt.database_file_path));

View File

@ -8,7 +8,7 @@ use once_cell::sync::Lazy;
use musichoard::{ use musichoard::{
library::{ library::{
beets::{BeetsLibrary, BeetsLibraryCommandExecutor}, beets::{BeetsLibrary, BeetsLibraryProcessExecutor},
Field, Library, Query, Field, Library, Query,
}, },
Artist, Artist,
@ -16,17 +16,17 @@ use musichoard::{
use crate::COLLECTION; use crate::COLLECTION;
static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryCommandExecutor>>>> = static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryProcessExecutor>>>> =
Lazy::new(|| { Lazy::new(|| {
Arc::new(Mutex::new(BeetsLibrary::new( Arc::new(Mutex::new(BeetsLibrary::new(
BeetsLibraryCommandExecutor::default(), BeetsLibraryProcessExecutor::default(),
))) )))
}); });
static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryCommandExecutor>>>> = static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary<BeetsLibraryProcessExecutor>>>> =
Lazy::new(|| { Lazy::new(|| {
Arc::new(Mutex::new(BeetsLibrary::new( Arc::new(Mutex::new(BeetsLibrary::new(
BeetsLibraryCommandExecutor::default().config(Some( BeetsLibraryProcessExecutor::default().config(Some(
&fs::canonicalize("./tests/files/library/config.yml").unwrap(), &fs::canonicalize("./tests/files/library/config.yml").unwrap(),
)), )),
))) )))
@ -45,7 +45,7 @@ fn test_no_config_list() {
#[test] #[test]
fn test_invalid_config() { fn test_invalid_config() {
let mut beets = BeetsLibrary::new(BeetsLibraryCommandExecutor::default().config(Some( let mut beets = BeetsLibrary::new(BeetsLibraryProcessExecutor::default().config(Some(
&PathBuf::from("./tests/files/library/config-does-not-exist.yml"), &PathBuf::from("./tests/files/library/config-does-not-exist.yml"),
))); )));