Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions rust/agama-cli/src/printers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ pub struct JsonPrinter<T, W> {
writer: W,
}

impl<T: Serialize + Debug, W: Write> Printer<T, W> for JsonPrinter<T, W> {
fn print(self: Box<Self>) -> anyhow::Result<()> {
Ok(serde_json::to_writer(self.writer, &self.content)?)
impl<T: Serialize, W: Write> Printer<T, W> for JsonPrinter<T, W> {
fn print(mut self: Box<Self>) -> anyhow::Result<()> {
let json = serde_json::to_string(&self.content)?;
Ok(writeln!(self.writer, "{}", json)?)
}
}
pub struct TextPrinter<T, W> {
content: T,
writer: W,
}

impl<T: Serialize + Debug, W: Write> Printer<T, W> for TextPrinter<T, W> {
impl<T: Debug, W: Write> Printer<T, W> for TextPrinter<T, W> {
fn print(mut self: Box<Self>) -> anyhow::Result<()> {
Ok(write!(self.writer, "{:?}", &self.content)?)
Ok(writeln!(self.writer, "{:?}", &self.content)?)
}
}

Expand All @@ -67,7 +68,7 @@ pub struct YamlPrinter<T, W> {
writer: W,
}

impl<T: Serialize + Debug, W: Write> Printer<T, W> for YamlPrinter<T, W> {
impl<T: Serialize, W: Write> Printer<T, W> for YamlPrinter<T, W> {
fn print(self: Box<Self>) -> anyhow::Result<()> {
Ok(serde_yaml::to_writer(self.writer, &self.content)?)
}
Expand Down
11 changes: 10 additions & 1 deletion rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ impl<'a> StorageClient<'a> {

/// Returns the candidate devices for the proposal
pub async fn candidate_devices(&self) -> Result<Vec<String>, 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
Expand Down
6 changes: 6 additions & 0 deletions rust/agama-lib/src/storage/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub struct Device {
pub name: String,
}

impl From<String> for Device {
fn from(value: String) -> Self {
Self { name: value }
}
}

impl TryFrom<SettingObject> for Device {
type Error = SettingsError;

Expand Down
8 changes: 6 additions & 2 deletions rust/agama-lib/src/storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ impl<'a> StorageStore<'a> {
})
}

// TODO: read the settings from the service
pub async fn load(&self) -> Result<StorageSettings, ServiceError> {
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> {
Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama-cli.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Jul 13 08:56:40 UTC 2023 - José Iván López González <jlopez@suse.com>

- 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 <igonzalezsosa@suse.com>

Expand Down