From 0cbeba01eec34a955c0470ab6ee886fb618b1e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 12 Jul 2023 12:03:00 +0100 Subject: [PATCH 1/5] Fix #candidate_devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Imobach González Sosa --- rust/agama-lib/src/storage/client.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rust/agama-lib/src/storage/client.rs b/rust/agama-lib/src/storage/client.rs index c3861983db..4748cb7d63 100644 --- a/rust/agama-lib/src/storage/client.rs +++ b/rust/agama-lib/src/storage/client.rs @@ -53,7 +53,16 @@ impl<'a> StorageClient<'a> { /// Returns the candidate devices for the proposal pub async fn candidate_devices(&self) -> Result, ServiceError> { - Ok(self.proposal_proxy().await?.candidate_devices().await?) + let proxy = self.proposal_proxy().await?; + match proxy.candidate_devices().await { + Ok(devices) => Ok(devices), + Err(zbus::Error::MethodError(name, _, _)) + if name.as_str() == "org.freedesktop.DBus.Error.UnknownObject" => + { + Ok(vec![]) + } + Err(e) => Err(e.into()), + } } /// Runs the probing process From eaae2a991399e0e0ea400041a9ba951a63bfaf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 12 Jul 2023 12:04:09 +0100 Subject: [PATCH 2/5] Load devices --- rust/agama-lib/src/storage/settings.rs | 6 ++++++ rust/agama-lib/src/storage/store.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rust/agama-lib/src/storage/settings.rs b/rust/agama-lib/src/storage/settings.rs index 44a6aecb0b..74afd59384 100644 --- a/rust/agama-lib/src/storage/settings.rs +++ b/rust/agama-lib/src/storage/settings.rs @@ -25,6 +25,12 @@ pub struct Device { pub name: String, } +impl From for Device { + fn from(value: String) -> Self { + Self { name: value } + } +} + impl TryFrom for Device { type Error = SettingsError; diff --git a/rust/agama-lib/src/storage/store.rs b/rust/agama-lib/src/storage/store.rs index d7d50a9bdb..8b4118794d 100644 --- a/rust/agama-lib/src/storage/store.rs +++ b/rust/agama-lib/src/storage/store.rs @@ -17,9 +17,13 @@ impl<'a> StorageStore<'a> { }) } - // TODO: read the settings from the service pub async fn load(&self) -> Result { - Ok(Default::default()) + let names = self.storage_client.candidate_devices().await?; + let devices = names.into_iter().map(|n| n.into()).collect(); + Ok(StorageSettings { + devices, + ..Default::default() + }) } pub async fn store(&self, settings: &StorageSettings) -> Result<(), ServiceError> { From c9d0e64be187acf859e647cab96c9b07aaa35aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 12 Jul 2023 12:54:22 +0100 Subject: [PATCH 3/5] Print new line with text and json formats - Yaml already does it. --- rust/agama-cli/src/printers.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rust/agama-cli/src/printers.rs b/rust/agama-cli/src/printers.rs index 5541439b31..a3cc428ad2 100644 --- a/rust/agama-cli/src/printers.rs +++ b/rust/agama-cli/src/printers.rs @@ -47,8 +47,9 @@ pub struct JsonPrinter { } impl Printer for JsonPrinter { - fn print(self: Box) -> anyhow::Result<()> { - Ok(serde_json::to_writer(self.writer, &self.content)?) + fn print(mut self: Box) -> anyhow::Result<()> { + let json = serde_json::to_string(&self.content)?; + Ok(writeln!(self.writer, "{}", json)?) } } pub struct TextPrinter { @@ -58,7 +59,7 @@ pub struct TextPrinter { impl Printer for TextPrinter { fn print(mut self: Box) -> anyhow::Result<()> { - Ok(write!(self.writer, "{:?}", &self.content)?) + Ok(writeln!(self.writer, "{:?}", &self.content)?) } } From 4e726cc24b9a123e6923d863b9229a4c97b79fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 12 Jul 2023 12:55:14 +0100 Subject: [PATCH 4/5] Only require necessary traits --- rust/agama-cli/src/printers.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/agama-cli/src/printers.rs b/rust/agama-cli/src/printers.rs index a3cc428ad2..aa0078fafb 100644 --- a/rust/agama-cli/src/printers.rs +++ b/rust/agama-cli/src/printers.rs @@ -46,7 +46,7 @@ pub struct JsonPrinter { writer: W, } -impl Printer for JsonPrinter { +impl Printer for JsonPrinter { fn print(mut self: Box) -> anyhow::Result<()> { let json = serde_json::to_string(&self.content)?; Ok(writeln!(self.writer, "{}", json)?) @@ -57,7 +57,7 @@ pub struct TextPrinter { writer: W, } -impl Printer for TextPrinter { +impl Printer for TextPrinter { fn print(mut self: Box) -> anyhow::Result<()> { Ok(writeln!(self.writer, "{:?}", &self.content)?) } @@ -68,7 +68,7 @@ pub struct YamlPrinter { writer: W, } -impl Printer for YamlPrinter { +impl Printer for YamlPrinter { fn print(self: Box) -> anyhow::Result<()> { Ok(serde_yaml::to_writer(self.writer, &self.content)?) } From d35c2946721e5cc7e53d752175e356375f565550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 13 Jul 2023 09:59:29 +0100 Subject: [PATCH 5/5] Changelog --- rust/package/agama-cli.changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/package/agama-cli.changes b/rust/package/agama-cli.changes index 0d412218c2..6d549497e4 100644 --- a/rust/package/agama-cli.changes +++ b/rust/package/agama-cli.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Jul 13 08:56:40 UTC 2023 - José Iván López González + +- Read the storage candidate devices and show them with + "agama config show" (gh#openSUSE/agama#658). + ------------------------------------------------------------------- Fri Jul 7 14:12:03 UTC 2023 - Imobach Gonzalez Sosa