minimum working

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

View File

@@ -1,21 +1,28 @@
use alhp_api;
use alhp_api::general::GeneralRequest;
use alhp_api::packages::{PackageRequest, PackageStatus};
use alhp_api::general::{GeneralRequest, GeneralResponse};
use alhp_api::packages::{Package, PackageRequest, PackageStatus};
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") {
Ok(alpm) => alpm,
Err(_) => panic!("Error establishing ALPM handle."),
};
let local_db = alpm.localdb();
let server = local_db.servers();
for s in server {
println!("{}", s);
}
let pkgs = local_db.pkgs();
pkgs
.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 {
status: vec![PackageStatus::Building, PackageStatus::Queued],
pkgbase: None,
@@ -26,9 +33,23 @@ fn main() {
limit: 0,
};
let pkg = pkg.response().unwrap();
println!("{:#?}", pkg);
let stats = GeneralRequest {};
let stats = stats.response().unwrap();
println!("{:#?}", stats);
query_installed_packages();
pkg.packages
}
fn match_local_alhp() -> Vec<String> {
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());
}