parsing packages, and find_package_in_repositories done ( i gotta commit more often lmao)
parent
f2e78523ea
commit
fed7106c20
@ -1,14 +1,20 @@
|
||||
mf-version = 100
|
||||
gaypk-version = 100
|
||||
name = "example-package"
|
||||
version = 100
|
||||
key = ""
|
||||
[files]
|
||||
"/opt/etc" = { match = "etc/*", tracked = false }
|
||||
"/opt/etc/enby/manuals" = { path = "manual.gmi", name = "example-package.gmi"}
|
||||
"/opt/bin" = { file = "example-package.x86-64.elf", name = "example-package", bin = "x86-64-elf"}
|
||||
version = "1.0.0"
|
||||
revision = 0
|
||||
pubkey = ""
|
||||
scripts=["*.gpksh"]
|
||||
exclude=["scripts", "*.gpksh"]
|
||||
[dependencies]
|
||||
|
||||
# GayPK doesn't care about this stuff
|
||||
[locale.en_US]
|
||||
name = "Example Package"
|
||||
description = "Example Package for testing GayPackage format."
|
||||
[locale.tp_XW]
|
||||
name = ""
|
||||
description = ""
|
||||
description = ""
|
||||
[launcher]
|
||||
category = "system"
|
||||
launch = "terminal"
|
||||
binary = "/opt/bin/example-package"
|
@ -1 +0,0 @@
|
||||
Hello world!
|
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env fish
|
||||
# shellcheck disable=SC2034
|
||||
OVERWRITE=false
|
||||
cat etc-file.txt >> /opt/etc/etc-file.txt
|
@ -0,0 +1 @@
|
||||
Hello world! (from GayPK)
|
@ -1,33 +1,19 @@
|
||||
use toml::map::Map;
|
||||
use toml::value::Table;
|
||||
use toml::value::{Array, Table};
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
/// Represents a Package.toml file.
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct PackageData {
|
||||
manifest_verison: u64,
|
||||
name: String,
|
||||
version: u64,
|
||||
key: String,
|
||||
files: Map<String, PackageFile>,
|
||||
#[serde(rename(deserialize = "gaypk-version"))]
|
||||
pub gaypk_version: u64,
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub revision: u64,
|
||||
pub pubkey: String,
|
||||
pub scripts: Array,
|
||||
pub exclude: Array,
|
||||
pub dependencies: Table
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
pub struct PackageFile {
|
||||
match_: Option<String>,
|
||||
tracked: Option<bool>,
|
||||
file: String,
|
||||
folder: Option<bool>,
|
||||
name: Option<String>,
|
||||
bin: Option<String>
|
||||
}
|
||||
impl Default for PackageFile {
|
||||
fn default() -> Self {
|
||||
PackageFile {
|
||||
match_: None,
|
||||
tracked: Some(true),
|
||||
file: "".to_string(),
|
||||
folder: Some(false),
|
||||
name: None,
|
||||
bin: None
|
||||
}
|
||||
}
|
||||
pub fn read_package(data: String) -> PackageData {
|
||||
toml::from_str(data.as_str()).expect("Parse failed!")
|
||||
}
|
@ -1,23 +1,32 @@
|
||||
use std::error::Error;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::path::Path;
|
||||
use futures::executor::block_on;
|
||||
use reqwest::StatusCode;
|
||||
use toml::toml;
|
||||
|
||||
pub async fn find_package_in_repositories(package: String, installed: Option<u64>) -> Vec<String> {
|
||||
pub fn find_package_in_repositories(package: &str, installed: Option<u64>) -> Option<Vec<String>> {
|
||||
let mut hits: Vec<String> = vec!();
|
||||
let client = reqwest::Client::new();
|
||||
let repo_file = File::open("/var/gaypack/repositories.list").expect("Failed to open repository list");
|
||||
let mut candidates: HashMap<u64, String> = HashMap::new();
|
||||
for repository in std::io::BufReader::new(repo_file).lines() {
|
||||
let repository = repository.expect("Unexpected error"); // i find this line kinda funny for some reason
|
||||
let resp = client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send().await.unwrap();
|
||||
let resp = block_on(client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send()).expect("GET request failed");
|
||||
let status = resp.status();
|
||||
let text = block_on(resp.text()).expect("Failed to receive packet body");
|
||||
if installed.is_some() {
|
||||
let package_data: crate::package::PackageData = toml::from_str(resp.text().await.expect("Failed to read text").as_str()).expect("Failed to parse toml");
|
||||
candidates.insert(installed.unwrap(), "installed".to_string());
|
||||
}
|
||||
if resp.status() == StatusCode::from_u16(200).unwrap() {
|
||||
hits.push(repository);
|
||||
let package_data = &crate::package::read_package(text);
|
||||
dbg!(package_data);
|
||||
if status == StatusCode::from_u16(200).unwrap() {
|
||||
candidates.insert(package_data.revision, repository);
|
||||
}
|
||||
};
|
||||
return hits;
|
||||
let mut sorted: Vec<_> = candidates.iter().collect();
|
||||
sorted.sort_by_key(|entry| entry.0);
|
||||
for (_, repository) in sorted.iter() {
|
||||
hits.push(repository.as_str().to_string());
|
||||
}
|
||||
return Some(hits);
|
||||
}
|
Loading…
Reference in New Issue