Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Commit

Permalink
Merge bitcoindevkit#22: Add installudevrules command
Browse files Browse the repository at this point in the history
d30bb76 Add installudevrules function (wszdexdrf)

Pull request description:

  Branched after bitcoindevkit#19.
  The test `test_install_udev_rules()` needs to run with superuser privileges.

ACKs for top commit:
  danielabrozzoni:
    ACK d30bb76

Tree-SHA512: 3b659277a68320a94c3d234a96a57a7993779848a6ce079ecc8cf3a77d29510bd01bdf662c1468d45bb623fdb8fc61850decd96f51828dfd6f775194aa8d6757
  • Loading branch information
danielabrozzoni committed Jun 13, 2022
2 parents 78d8043 + d30bb76 commit 050bf79
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde_json::value::Value;
use crate::error::Error;
use crate::types::{
HWIAddress, HWIAddressType, HWIChain, HWIDescriptor, HWIDevice, HWIExtendedPubKey,
HWIKeyPoolElement, HWIPartiallySignedTransaction, HWISignature,
HWIKeyPoolElement, HWIPartiallySignedTransaction, HWISignature, HWIStatus,
};

use pyo3::prelude::*;
Expand Down Expand Up @@ -272,4 +272,25 @@ impl HWIClient {
deserialize_obj!(&output.to_string())
})
}

/// Install the udev rules to the local machine.
/// The rules will be copied from the source to the location.
/// The default source location is "./udev"
/// The default destination location is "/lib/udev/rules.d"
pub fn install_udev_rules(source: Option<&str>, location: Option<&str>) -> Result<(), Error> {
Python::with_gil(|py| {
let libs = HWILib::initialize()?;
let func_args = (
source.unwrap_or("./udev"),
location.unwrap_or("/lib/udev/rules.d/"),
);
let output = libs
.commands
.getattr(py, "install_udev_rules")?
.call1(py, func_args)?;
let output = libs.json_dumps.call1(py, (output,))?;
let status: HWIStatus = deserialize_obj!(&output.to_string())?;
status.into()
})
}
}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,12 @@ mod tests {
)
.unwrap();
}
#[test]
#[serial]
#[ignore]
fn test_install_udev_rules() {
if cfg!(target_os = "linux") {
HWIClient::install_udev_rules(None, None).unwrap()
}
}
}
17 changes: 17 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use pyo3::types::PyModule;
use pyo3::{IntoPy, PyObject};
use serde::{Deserialize, Deserializer};

use crate::error::Error;

#[derive(Deserialize)]
pub struct HWIExtendedPubKey {
pub xpub: ExtendedPubKey,
Expand Down Expand Up @@ -131,3 +133,18 @@ pub struct HWIDevice {
pub needs_passphrase_sent: bool,
pub fingerprint: Fingerprint,
}

#[derive(Deserialize)]
pub struct HWIStatus {
pub success: bool,
}

impl From<HWIStatus> for Result<(), Error> {
fn from(s: HWIStatus) -> Self {
if s.success {
Ok(())
} else {
Err(Error::HWIError("Request returned with failure".to_string()))
}
}
}

0 comments on commit 050bf79

Please sign in to comment.