#parser #changelog #debian

debian-changelog

Parser for Debian changelog files

15 releases

0.1.14 Sep 13, 2024
0.1.13 Sep 4, 2024
0.1.12 Jul 30, 2024
0.1.11 Mar 9, 2024
0.1.6 Sep 27, 2023

#5 in #debian

Download history 802/week @ 2024-06-18 1107/week @ 2024-06-25 697/week @ 2024-07-02 848/week @ 2024-07-09 621/week @ 2024-07-16 1367/week @ 2024-07-23 1784/week @ 2024-07-30 2416/week @ 2024-08-06 1453/week @ 2024-08-13 1928/week @ 2024-08-20 2702/week @ 2024-08-27 2044/week @ 2024-09-03 1469/week @ 2024-09-10 992/week @ 2024-09-17 2209/week @ 2024-09-24 788/week @ 2024-10-01

6,322 downloads per month
Used in 11 crates (9 directly)

Apache-2.0

130KB
3.5K SLoC

Debian Changelog parser

This crate provides a parser for debian/changelog files, as described in the Debian policy, section 4.4.

The parser builds a CST. It is lossless - i.e. preserves formatting, and allows editing and partial parsing.

Example:


use std::io::Read;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let file = std::fs::File::open("/usr/share/doc/rustc/changelog.Debian.gz")?;
    let mut gz = flate2::read::GzDecoder::new(file);
    let mut contents = String::new();
    gz.read_to_string(&mut contents)?;
    let changelog: debian_changelog::ChangeLog = contents.parse()?;
    for entry in changelog.entries() {
        println!(
            "{}: {}",
            entry.package().unwrap(),
            entry.version().unwrap().to_string()
        );
    }
    Ok(())
}

Or to update an existing changelog file:


use std::io::Read;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let file = std::fs::File::open("debian/changelog")?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;
    let changelog: debian_changelog::ChangeLog = contents.parse()?;
    changelog.auto_add_change(
        &["* Make a change"],
        (
            "Jelmer Vernooij".to_string(),
            "jelmer@debian.org".to_string(),
        ),
        None,
        None,
    );
    std::fs::write("debian/changelog", changelog.to_string())?;
    Ok(())
}

Dependencies

~5.5–8MB
~130K SLoC