8 releases

0.3.2 Jan 31, 2023
0.3.1 Jan 31, 2023
0.2.2 Jan 30, 2023
0.1.1 Dec 12, 2022

#1 in #eight

28 downloads per month

MIT license

16KB
340 lines

8dparser

Dpkg info parser

Usage

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

Dependencies

~2–2.8MB
~52K SLoC