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]
alhp_api = {path = "crates/alhp_api"}
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)]
pub struct Package {
pkgbase: String,
repo: String,
split_packages: Vec<String>,
status: PackageStatus,
skip_reason: Option<String>,
lto: String,
debug_symbols: String,
arch_version: String,
repo_version: String,
build_date: Option<String>,
peak_mem: Option<String>,
pub pkgbase: String,
pub repo: String,
pub split_packages: Vec<String>,
pub status: PackageStatus,
pub skip_reason: Option<String>,
pub lto: String,
pub debug_symbols: String,
pub arch_version: String,
pub repo_version: String,
pub build_date: Option<String>,
pub peak_mem: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]

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());
}