minimum working

This commit is contained in:
2025-03-24 23:20:19 +01:00
parent cd544e71e3
commit 84434f887c
3 changed files with 47 additions and 24 deletions

View File

@@ -6,3 +6,5 @@ edition = "2024"
[dependencies] [dependencies]
alhp_api = {path = "crates/alhp_api"} alhp_api = {path = "crates/alhp_api"}
alpm = "4.0.2" alpm = "4.0.2"
log = "0.4.27"
serde_json = "1.0.140"

View File

@@ -46,17 +46,17 @@ pub mod packages {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Package { pub struct Package {
pkgbase: String, pub pkgbase: String,
repo: String, pub repo: String,
split_packages: Vec<String>, pub split_packages: Vec<String>,
status: PackageStatus, pub status: PackageStatus,
skip_reason: Option<String>, pub skip_reason: Option<String>,
lto: String, pub lto: String,
debug_symbols: String, pub debug_symbols: String,
arch_version: String, pub arch_version: String,
repo_version: String, pub repo_version: String,
build_date: Option<String>, pub build_date: Option<String>,
peak_mem: Option<String>, pub peak_mem: Option<String>,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]

View File

@@ -1,21 +1,28 @@
use alhp_api; use alhp_api;
use alhp_api::general::GeneralRequest; use alhp_api::general::{GeneralRequest, GeneralResponse};
use alhp_api::packages::{PackageRequest, PackageStatus}; use alhp_api::packages::{Package, PackageRequest, PackageStatus};
use alpm::Alpm; use alpm::Alpm;
use std::collections::HashSet;
fn query_installed_packages() { fn query_installed_packages() -> HashSet<String> {
let alpm = match Alpm::new("/", "/var/lib/pacman") { let alpm = match Alpm::new("/", "/var/lib/pacman") {
Ok(alpm) => alpm, Ok(alpm) => alpm,
Err(_) => panic!("Error establishing ALPM handle."), Err(_) => panic!("Error establishing ALPM handle."),
}; };
let local_db = alpm.localdb(); let local_db = alpm.localdb();
let server = local_db.servers(); let pkgs = local_db.pkgs();
for s in server { pkgs
println!("{}", s); .into_iter()
} .map(|pkg| pkg.name().to_owned())
.collect::<HashSet<String>>()
} }
fn main() { fn get_stats() -> GeneralResponse {
let stats = GeneralRequest {};
stats.response().unwrap()
}
fn get_queued_building() -> Vec<Package> {
let pkg = PackageRequest { let pkg = PackageRequest {
status: vec![PackageStatus::Building, PackageStatus::Queued], status: vec![PackageStatus::Building, PackageStatus::Queued],
pkgbase: None, pkgbase: None,
@@ -26,9 +33,23 @@ fn main() {
limit: 0, limit: 0,
}; };
let pkg = pkg.response().unwrap(); let pkg = pkg.response().unwrap();
println!("{:#?}", pkg); pkg.packages
let stats = GeneralRequest {}; }
let stats = stats.response().unwrap();
println!("{:#?}", stats); fn match_local_alhp() -> Vec<String> {
query_installed_packages(); let local = query_installed_packages();
let remote = get_queued_building();
let mut matched = Vec::<String>::new();
for pkg in remote {
if local.contains(&pkg.pkgbase) {
matched.push(pkg.pkgbase.clone())
}
}
matched
}
fn main() {
println!("{}", serde_json::to_string_pretty(&get_stats()).unwrap());
println!("{}", serde_json::to_string_pretty(&get_queued_building()).unwrap());
println!("{}", serde_json::to_string_pretty(&match_local_alhp()).unwrap());
} }