6 releases

0.2.2 Jan 16, 2022
0.2.1 Jul 14, 2021
0.2.0 Sep 4, 2020
0.1.2 Aug 13, 2020

#845 in Hardware support

Download history 44/week @ 2024-03-14 29/week @ 2024-03-21 33/week @ 2024-03-28 43/week @ 2024-04-04 37/week @ 2024-04-11 20/week @ 2024-04-18 10/week @ 2024-04-25 2/week @ 2024-05-02 13/week @ 2024-05-09 17/week @ 2024-05-16 12/week @ 2024-05-23 19/week @ 2024-05-30 33/week @ 2024-06-06 33/week @ 2024-06-13 25/week @ 2024-06-20 11/week @ 2024-06-27

106 downloads per month

MIT license

185KB
3.5K SLoC

appstream

Appstream files parser using Rust & xmltree

Specifications: https://www.freedesktop.org/software/appstream/docs/

How to use

use appstream::{Collection, Component, ParseError};

fn main() -> Result<(), ParseError> {
    let collection = Collection::from_path("/var/lib/flatpak/appstream/flathub/x86_64/active/appstream.xml".into())?;
    // Find a specific application by id
    println!("{:#?}", collection.find_by_id("org.gnome.design.Contrast".into()));

    // Find the list of gedit plugins
    collection.components.iter()
        .filter(|c| c.extends.contains(&"org.gnome.gedit".into()))
        .collect::<Vec<&Component>>();
        
    Ok(())
}

lib.rs:

Appstream

AppStream is a cross-distro effort for enhancing the metadata available about software components in the Linux and free-software ecosystem. One of the project's goals is to make building software-center applications possible, and make interaction with the package sources of a distribution smarter. AppStream provides specifications for meta-information which is shipped by upstream projects and can be consumed by other software. The meta-information includes data which is interesting to display in software centers and is mainly useful for end-users, as well as descriptions about the public interfaces a software component provides, which is mainly useful for developers, 3rd-party software installers and for automatically installing missing components on a distribution, for example missing firmware or mimetype-handlers.

Specifications: https://www.freedesktop.org/software/appstream/docs/

This crate aimes to provide an easy and sane Rust parser of Appstream using xmltree

Examples

use appstream::{Component, ParseError};
use appstream::builders::{ComponentBuilder, ReleaseBuilder};
use appstream::TranslatableString;
use appstream::enums::{Provide, ProjectUrl};
use url::Url;
use chrono::{Utc, TimeZone};
use std::convert::TryFrom;

fn main() -> Result<(), ParseError> {

    let xml = r"<?xml version='1.0' encoding='UTF-8'?>
                    <component>
                        <id>com.example.foobar</id>
                        <name>Foo Bar</name>
                        <summary>A foo-ish bar</summary>
                        <url type='homepage'>http://www.example.org</url>
                        <metadata_license>CC0-1.0</metadata_license>
                        
                        <provides>
                          <library>libfoobar.so.2</library>
                          <font>foo.ttf</font>
                          <binary>foobar</binary>
                        </provides>
                        <releases>
                          <release version='1.2' date='2015-02-16'/>
                        </releases>
                        <developer_name>FooBar Team</developer_name>
                    </component>";
    let element = xmltree::Element::parse(xml.as_bytes())?;
    let c1 = Component::try_from(&element)?;

    let c2 = ComponentBuilder::default()
        .id("com.example.foobar".into())
        .name(TranslatableString::with_default("Foo Bar"))
        .metadata_license("CC0-1.0".into())
        .summary(TranslatableString::with_default("A foo-ish bar"))
        .url(ProjectUrl::Homepage(
            Url::parse("http://www.example.org")?,
        ))
        .developer_name(TranslatableString::with_default("FooBar Team"))
        .provide(Provide::Library("libfoobar.so.2".into()))
        .provide(Provide::Font("foo.ttf".into()))
        .provide(Provide::Binary("foobar".into()))
        .release(
            ReleaseBuilder::new("1.2")
                .date(Utc.ymd(2015, 2, 16).and_hms_milli(0, 0, 0, 0))
                .build(),
        )
        .build();

    assert_eq!(c1, c2);
    
    Ok(())
}

The library can parse a collection of components as well

use appstream::{Collection, Component, ParseError};

fn main() -> Result<(), ParseError> {
    let collection = Collection::from_path("/var/lib/flatpak/appstream/flathub/x86_64/active/appstream.xml".into())?;
    #[cfg(feature="gzip")]
    let collection = Collection::from_gzipped("/var/lib/flatpak/appstream/flathub/x86_64/active/appstream.xml.gz".into())?;
    // Find a specific application by id
    println!("{:#?}", collection.find_by_id("org.gnome.design.Contrast".into()));

    // Find the list of gedit plugins
    collection.components.iter()
        .filter(|c| c.extends.contains(&"org.gnome.gedit".into()))
        .collect::<Vec<&Component>>();

    Ok(())
}

Dependencies

~5MB
~123K SLoC