Crates.io | eight-deep-parser |
lib.rs | eight-deep-parser |
version | 0.3.2 |
source | src |
created_at | 2022-12-12 08:43:21.536037 |
updated_at | 2023-01-31 13:12:31.477727 |
description | Dpkg info parser |
homepage | https://github.com/AOSC-Dev/8dparser |
repository | https://github.com/AOSC-Dev/8dparser |
max_upload_size | |
id | 734862 |
size | 16,739 |
Dpkg info parser
Add line to dependencies
in cargo.toml
:
eight-deep-parser = "0.1"
And try to parse one package:
use std::process::Command;
use eight_deep_parser::{parse_multi, parse_one, Item};
fn main() {
let command = Command::new("dpkg")
.arg("-s")
.arg("plasma-workspace")
.output()
.unwrap();
let stdout = command.stdout;
let r = parse_one(std::str::from_utf8(&stdout).unwrap()).unwrap();
assert_eq!(
r.get("Package").unwrap(),
&Item::OneLine("plasma-workspace".to_string())
);
}
And try to parse multi package:
use std::{fs, io::Read, process::Command};
use eight_deep_parser::{parse_multi, Item};
fn main() {
let dir = fs::read_dir("/var/lib/apt/lists").unwrap();
for i in dir.flatten() {
if !i.file_name().to_str().unwrap().ends_with("_Packages") {
continue;
}
let mut f = std::fs::File::open(i.path()).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();
let r = parse_multi(std::str::from_utf8(&buf).unwrap());
assert!(r.is_ok())
}
}