AppStream.Metadata

g AppStream.Metadata AppStream.Metadata GObject.Object GObject.Object GObject.Object->AppStream.Metadata

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

file_guess_style (filename)

class

new ()

add_component (cpt)

clear_components ()

clear_releases ()

component_to_metainfo (format)

components_to_catalog (format)

get_architecture ()

get_component ()

get_components ()

get_format_style ()

get_format_version ()

get_locale ()

get_media_baseurl ()

get_origin ()

get_parse_flags ()

get_release_list ()

get_release_lists ()

get_update_existing ()

get_write_header ()

parse_bytes (bytes, format)

parse_data (data, data_len, format)

parse_desktop_data (cid, data, data_len)

parse_file (file, format)

parse_releases_bytes (bytes)

parse_releases_file (file)

releases_to_data (releases)

save_catalog (fname, format)

save_metainfo (fname, format)

set_architecture (arch)

set_format_style (mode)

set_format_version (version)

set_locale (locale)

set_media_baseurl (url)

set_origin (origin)

set_parse_flags (flags)

set_update_existing (update)

set_write_header (wheader)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class AppStream.Metadata(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

AppStream.MetadataClass

classmethod file_guess_style(filename)
Parameters:

filename (str) – a file name

Returns:

An AppStream.FormatStyle, e.g. AppStream.FormatStyle.METAINFO.

Return type:

AppStream.FormatStyle

Guesses the AppStream metadata style (metainfo or catalog) based on the filename.

New in version 0.14.0.

classmethod new()
Returns:

a AppStream.Metadata

Return type:

AppStream.Metadata

Creates a new AppStream.Metadata.

add_component(cpt)
Parameters:

cpt (AppStream.Component) –

Add an AppStream.Component to the list of components. This can be used to add multiple components in order to produce a distro-XML AppStream metadata file.

clear_components()

Remove all previously parsed or manually added components.

clear_releases()

Remove all previously parsed releases entries.

component_to_metainfo(format)
Parameters:

format (AppStream.FormatKind) – The format to use (XML or YAML)

Raises:

GLib.Error

Returns:

A string containing the XML metadata. Free with GLib.free()

Return type:

str

Convert an AppStream.Component to metainfo data. This will always be XML, YAML is no valid format for metainfo files.

The amount of localization included in the metadata depends on how the AppStream.Component was initially loaded and whether it contains data for all locale.

The first AppStream.Component added to the internal list will be transformed. In case no component is present, None is returned.

components_to_catalog(format)
Parameters:

format (AppStream.FormatKind) – The format to serialize the data to (XML or YAML).

Raises:

GLib.Error

Returns:

A string containing the YAML or XML data. Free with GLib.free()

Return type:

str

Serialize all AppStream.Component instances into AppStream catalog metadata. None is returned if there is nothing to serialize.

get_architecture()
Returns:

The architecture of AppStream distro metadata

Return type:

str

get_component()
Returns:

An AppStream.Component or None

Return type:

AppStream.Component or None

Gets the AppStream.Component which has been parsed from the XML. If the AppStream XML contained multiple components, return the last component that has been parsed.

get_components()
Returns:

an AppStream.ComponentBox of all parsed components

Return type:

AppStream.ComponentBox

get_format_style()
Return type:

AppStream.FormatStyle

Get the metadata parsing mode.

get_format_version()
Returns:

The AppStream metadata format version.

Return type:

AppStream.FormatVersion

get_locale()
Returns:

Locale used for metadata parsing.

Return type:

str

Gets the current active locale for parsing metadata, or “ALL” if all locales are read.

get_media_baseurl()
Returns:

The media URL prefix.

Return type:

str

get_origin()
Returns:

The origin of AppStream distro metadata

Return type:

str

get_parse_flags()
Return type:

AppStream.ParseFlags

Get the metadata parse flags.

get_release_list()
Returns:

An AppStream.ReleaseList or None

Return type:

AppStream.ReleaseList or None

Gets the recently parsed AppStream.ReleaseList entry.

get_release_lists()
Returns:

A GLib.PtrArray of all parsed release metadata.

Return type:

[AppStream.ReleaseList]

get_update_existing()
Returns:

Whether existing components should be updates with the parsed data, instead of creating new ones.

Return type:

bool

get_write_header()
Returns:

Whether we will write a header/root node in catalog metadata.

Return type:

bool

parse_bytes(bytes, format)
Parameters:
Raises:

GLib.Error

Returns:

True on success.

Return type:

bool

Parses any AppStream metadata into one or more AppStream.Component instances.

New in version 0.14.0.

parse_data(data, data_len, format)
Parameters:
  • data (str) – Metadata describing one or more software components as string.

  • data_len (int) – Length of data, or -1 if length is unknown and data is None-terminated.

  • format (AppStream.FormatKind) – The format of the data (XML or YAML).

Raises:

GLib.Error

Returns:

True on success.

Return type:

bool

Parses any AppStream metadata into one or more AppStream.Component instances.

parse_desktop_data(cid, data, data_len)
Parameters:
  • cid (str) – The component-id the new AppStream.Component should have.

  • data (str) – Metadata describing one or more software components.

  • data_len (int) – The data length, or -1 if unknown and null-terminated.

Raises:

GLib.Error

Returns:

True if the file was parsed without error.

Return type:

bool

Parses XDG Desktop Entry metadata and adds it to the list of parsed entities.

Please note that not every desktop-entry file will result in a valid component being generated, even if parsing succeeds without error (The desktiop-entry file may be valid but not generate a component on purpose).

parse_file(file, format)
Parameters:
Raises:

GLib.Error

Returns:

True if the file was parsed without error.

Return type:

bool

Parses an AppStream upstream metadata file.

If file does not exist, Gio.IOErrorEnum.NOT_FOUND will be returned. Other GLib.IOErrors and AppStream.MetadataErrors may be returned as appropriate.

parse_releases_bytes(bytes)
Parameters:

bytes (GLib.Bytes) – Metadata describing release notes.

Raises:

GLib.Error

Returns:

True on success.

Return type:

bool

Parses any AppStream release metadata into AppStream.Release objects. You can retrieve the last parsed AppStream.ReleaseList using AppStream.Metadata.get_release_list.

New in version 0.16.0.

parse_releases_file(file)
Parameters:

file (Gio.File) – Gio.File for the release metadata

Raises:

GLib.Error

Returns:

True on success.

Return type:

bool

Parses any AppStream release metadata into AppStream.Release objects using the provided file. You can retrieve the last parsed AppStream.ReleaseList using AppStream.Metadata.get_release_list.

New in version 0.16.0.

releases_to_data(releases)
Parameters:

releases (AppStream.ReleaseList) – the AppStream.ReleaseList to convert.

Raises:

GLib.Error

Returns:

The XML representation or None on error.

Return type:

str

Convert a releases of an AppStream.ReleaseList entity into a release metadata XML representation.

New in version 0.16.0.

save_catalog(fname, format)
Parameters:
Raises:

GLib.Error

Returns:

True if the file was written without error.

Return type:

bool

Serialize all AppStream.Component instances to XML or YAML metadata and save the data to a file. An existing file at the same location will be overridden.

save_metainfo(fname, format)
Parameters:
  • fname (str) – The filename for the new metadata file.

  • format (AppStream.FormatKind) – The format to save this file in. Only XML is supported at time.

Raises:

GLib.Error

Returns:

True if the file was written without error.

Return type:

bool

Serialize AppStream.Component instance to XML and save it to file. An existing file at the same location will be overridden.

set_architecture(arch)
Parameters:

arch (str) – an architecture string.

Set the architecture the components in this metadata belong to.

set_format_style(mode)
Parameters:

mode (AppStream.FormatStyle) – the AppStream.FormatStyle.

Sets the current metadata parsing mode.

set_format_version(version)
Parameters:

version (AppStream.FormatVersion) – the AppStream metadata format version as AppStream.FormatVersion.

Set the current AppStream format version that we should generate data for or be able to read.

set_locale(locale)
Parameters:

locale (str) – the BCP47 locale.

Sets the locale which should be read when processing metadata. All other locales are ignored, which increases parsing speed and reduces memory usage. If you set the locale to “ALL”, all locales will be read.

set_media_baseurl(url)
Parameters:

url (str) – the base URL.

Set the base URL for all media links referenced in the metadata, or None if every component has absolute URLs.

set_origin(origin)
Parameters:

origin (str) – the origin of AppStream distro metadata.

Set the origin of AppStream distro metadata

set_parse_flags(flags)
Parameters:

flags (AppStream.ParseFlags) – the AppStream.ParseFlags.

Sets the current metadata parse flags.

set_update_existing(update)
Parameters:

update (bool) – A boolean value.

If set to True, the parser will not create new components but instead update existing components in the pool with new metadata.

NOTE: Right now, this feature is only implemented for metainfo XML parsing!

set_write_header(wheader)
Parameters:

wheader (bool) – A boolean value.

If set to True, tehe metadata writer will omit writing a DEP-11 header document when in YAML mode, and will not write a root components node when writing XML data. Please keep in mind that this will create an invalid DEP-11 YAML AppStream catalog metadata file, and an invalid XML file. This parameter should only be changed e.g. by the appstream-generator tool.

NOTE: Right now, this feature is only implemented for YAML!