Compare commits
14 Commits
a1ff9a4074
...
main
Author | SHA1 | Date | |
---|---|---|---|
cf44d13fe1 | |||
59f4ff7552 | |||
d8b71d8f04 | |||
c2f7bf7a9e | |||
987d6df4c8 | |||
a3cdd0e543 | |||
cb905667f7 | |||
c6672f3ba6 | |||
3accc96550 | |||
84434f887c | |||
0749646060 | |||
cd544e71e3 | |||
681b3a96b7 | |||
c6f08d3365 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
crates/alhp_api/target
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
|
1599
Cargo.lock
generated
1599
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -4,5 +4,6 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
alhp_api = {path = "crates/alhp_api"}
|
||||
|
||||
alhp_api = {git="https://gitea.puchstein.bayern/mpuchstein/ALHP_API_RS", version="0.1.2"}
|
||||
alpm = "4.0.2"
|
||||
serde_json = "1.0.140"
|
||||
|
96
crates/alhp_api/Cargo.lock
generated
96
crates/alhp_api/Cargo.lock
generated
@@ -1,96 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "alhp_api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.140"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
@@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "alhp_api"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["mpuchstein"]
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
reqwest = { version = "0.12.15" , features = ["blocking"] }
|
@@ -1,83 +0,0 @@
|
||||
use std::fmt;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use reqwest::blocking::Client;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PackageStatus{
|
||||
Latest,
|
||||
Failed,
|
||||
Built,
|
||||
Skipped,
|
||||
Delayed,
|
||||
Building,
|
||||
Signing,
|
||||
Unknown,
|
||||
Queued,
|
||||
}
|
||||
|
||||
impl fmt::Display for PackageStatus {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", serde_json::to_string(self).unwrap().trim_matches('"'))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Package {
|
||||
pkgbase: String,
|
||||
repo: String,
|
||||
split_packages: Vec<String>,
|
||||
status: PackageStatus,
|
||||
lto: String,
|
||||
debug_symbols: String,
|
||||
arch_version: String,
|
||||
repo_version: String,
|
||||
build_date: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PackageResponse {
|
||||
pub total: usize,
|
||||
pub offset: usize,
|
||||
pub limit: usize,
|
||||
pub packages: Vec<Package>
|
||||
}
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
pub struct PackageRequest {
|
||||
pub status: Vec<PackageStatus>,
|
||||
pub pkgbase: Option<String>,
|
||||
pub exact: bool,
|
||||
pub repo: Option<String>,
|
||||
pub offset: usize,
|
||||
pub limit: usize,
|
||||
}
|
||||
|
||||
impl PackageRequest {
|
||||
fn query_string(&self) -> String {
|
||||
let mut params = Vec::new();
|
||||
for status in &self.status {
|
||||
params.push(format!("status={}", status));
|
||||
}
|
||||
if let Some(pkgbase) = &self.pkgbase {
|
||||
params.push(format!("pkgbase={}", pkgbase));
|
||||
}
|
||||
if self.exact {
|
||||
params.push("exact".to_string());
|
||||
}
|
||||
if let Some(repo) = &self.repo {
|
||||
params.push(format!("repo={}", repo));
|
||||
}
|
||||
params.push(format!("offset={}", self.offset));
|
||||
params.push(format!("limit={}", self.limit));
|
||||
params.join("&")
|
||||
}
|
||||
pub fn response(&self) -> Result<PackageResponse, reqwest::Error> {
|
||||
let client = Client::new();
|
||||
let query_string = self.query_string();
|
||||
let url = format!("https://api.alhp.dev/packages?{}", query_string);
|
||||
println!("{}", url);
|
||||
let response = client.get(url).send()?.text()?;
|
||||
let response: PackageResponse = serde_json::from_str(&response).unwrap();
|
||||
Ok(response)
|
||||
}
|
||||
}
|
68
src/main.rs
68
src/main.rs
@@ -1,31 +1,55 @@
|
||||
use alhp_api;
|
||||
use std::process::Command;
|
||||
use alhp_api::{PackageRequest, PackageStatus};
|
||||
use alhp_api::general::{GeneralRequest, GeneralResponse};
|
||||
use alhp_api::packages::{Package, PackageRequest, PackageStatus};
|
||||
use alpm::Alpm;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn pacman_query_installed_packages() -> Vec<String> {
|
||||
match Command::new("pacman").arg("-Qqn").output() {
|
||||
Ok(packages) => String::from_utf8_lossy(&packages.stdout)
|
||||
.lines()
|
||||
.map(|s| s.to_string())
|
||||
.collect(),
|
||||
_ => {
|
||||
panic!("pacman query failed");
|
||||
}
|
||||
}
|
||||
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 pkgs = local_db.pkgs();
|
||||
pkgs
|
||||
.into_iter()
|
||||
.map(|pkg| pkg.name().to_owned())
|
||||
.collect::<HashSet<String>>()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let installed_packages = pacman_query_installed_packages();
|
||||
println!("installed packages: {:?}", installed_packages);
|
||||
let status = vec!();
|
||||
let pkg = PackageRequest{
|
||||
status,
|
||||
pkgbase: Some("go".to_string()),
|
||||
exact: true,
|
||||
repo: Some("extra-x86-64-v3".to_string()),
|
||||
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,
|
||||
exact: false,
|
||||
// repo: Some("extra-x86-64-v3".to_string()),
|
||||
repo: None,
|
||||
offset: 0,
|
||||
limit: 0,
|
||||
};
|
||||
let pkg = pkg.response().unwrap();
|
||||
println!("pkg: {:?}", pkg);
|
||||
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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user