优化插件验证逻辑和代码结构

This commit is contained in:
shenjack 2024-03-13 01:24:32 +08:00
parent 0843826435
commit 8cd8d93a28
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 7 additions and 8 deletions

View File

@ -51,8 +51,7 @@ pub fn verify_plugins() {
return;
}
let plugin_path = plugin_path.unwrap();
for entry in std::fs::read_dir(plugin_path).unwrap() {
if let Ok(entry) = entry {
for entry in std::fs::read_dir(plugin_path).unwrap().flatten() {
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "py" && !PyStatus::verify_file(&path) {
@ -60,7 +59,6 @@ pub fn verify_plugins() {
}
}
}
}
if need_reload_files.is_empty() {
return;

View File

@ -1,6 +1,7 @@
pub mod call;
pub mod class;
use std::path::Path;
use std::time::SystemTime;
use std::{collections::HashMap, path::PathBuf};
@ -222,7 +223,7 @@ pub fn get_change_time(path: &PathBuf) -> Option<SystemTime> {
path.metadata().ok()?.modified().ok()
}
pub fn py_module_from_code(content: &str, path: &PathBuf) -> PyResult<Py<PyAny>> {
pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyAny>> {
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
let module: PyResult<Py<PyAny>> = PyModule::from_code(
py,