Skip to content

Commit

Permalink
Enable traits to all python modules
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Nov 25, 2024
1 parent 423a0b5 commit 1f96daa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
4 changes: 2 additions & 2 deletions libsysinspect/src/pylang/pvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
sync::Arc,
};

// use super::pylib::pysystem::syscore;
use super::pylib::pysystem::syscore;

pub struct PyVm {
itp: Interpreter,
Expand All @@ -37,7 +37,7 @@ impl PyVm {
.init_stdlib()
.settings(cfg)
.init_hook(Box::new(|vm| {
//vm.add_native_module("syscore".to_owned(), Box::new(syscore::make_module));
vm.add_native_module("syscore".to_owned(), Box::new(syscore::make_module));
}))
.interpreter();

Expand Down
21 changes: 5 additions & 16 deletions libsysinspect/src/pylang/pylib/pysystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use rustpython_vm::pymodule;

#[pymodule]
pub mod syscore {
use crate::{cfg::mmconf::MinionConfig, traits::systraits::SystemTraits, util::dataconv};
use crate::{
traits::{self, systraits::SystemTraits},
util::dataconv,
};
use rustpython_vm::PyResult;
use rustpython_vm::{builtins::PyList, convert::ToPyObject, pyclass, PyObjectRef, PyPayload, VirtualMachine};
use std::path::PathBuf;

#[derive(Debug, Clone)]
struct StrVec(Vec<String>);
Expand All @@ -30,20 +32,7 @@ pub mod syscore {
#[pyclass]
impl MinionTraits {
fn new() -> MinionTraits {
// This sucks big time. It always initialises traits for every script call
let cfg = match MinionConfig::new(PathBuf::from("/etc/sysinspect/sysinspect.conf")) {
Ok(c) => Some(c),
Err(err) => {
log::debug!("Error initialising traits: {err}");
None
}
};

if let Some(cfg) = cfg {
return MinionTraits { traits: Some(SystemTraits::new(cfg)) };
}

MinionTraits { ..Default::default() }
MinionTraits { traits: Some(traits::get_minion_traits(None)) }
}

#[pymethod]
Expand Down

0 comments on commit 1f96daa

Please sign in to comment.