portage.xml.metadata module

Provides an easy-to-use python interface to Gentoo’s metadata.xml file.

Example usage:
>>> from portage.xml.metadata import MetaDataXML
>>> pkg_md = MetaDataXML('/var/db/repos/gentoo/app-misc/gourmet/metadata.xml')
>>> pkg_md
<MetaDataXML '/var/db/repos/gentoo/app-misc/gourmet/metadata.xml'>
>>> pkg_md.herds()
['no-herd']
>>> for maint in pkg_md.maintainers():
...     print "{0} ({1})".format(maint.email, maint.name)
...
nixphoeni@gentoo.org (Joe Sapp)
>>> for flag in pkg_md.use():
...     print flag.name, "->", flag.description
...
rtf -> Enable export to RTF
gnome-print -> Enable printing support using gnome-print
>>> upstream = pkg_md.upstream()
>>> upstream
[<_Upstream {'docs': [], 'remoteid': [], 'maintainer':
 [<_Maintainer 'Thomas_Hinkle@alumni.brown.edu'>], 'bugtracker': [],
 'changelog': []}>]
>>> upstream[0].maintainer[0].name
'Thomas Mills Hinkle'
class portage.xml.metadata.MetaDataXML(metadata_xml_path, herds)

Bases: object

Access metadata.xml

_get_herd_email(herd)

Get a herd’s email address.

Parameters

herd (str) – herd whose email you want

Return type

str or None

Returns

email address or None if herd is not in herds.xml

Raises

IOError – if $PORTDIR/metadata/herds.xml can not be read

descriptions()

Return a list of text nodes for <longdescription>.

Return type

list

Returns

package description in string format

Todo

Support the lang attribute

format_maintainer_string()

Format string containing maintainers and herds (emails if possible). Used by emerge to display maintainer information. Entries are sorted according to the rules stated on the bug wranglers page.

Return type

String

Returns

a string containing maintainers and herds

format_upstream_string()

Format string containing upstream maintainers and bugtrackers. Used by emerge to display upstream information.

Return type

String

Returns

a string containing upstream maintainers and bugtrackers

herds(include_email=False)

Return a list of text nodes for <herd>.

Parameters

include_email (bool) – if True, also look up the herd’s email

Return type

tuple

Returns

if include_email is False, return a list of strings; if include_email is True, return a list of tuples containing:

[(‘herd1’, ‘herd1@gentoo.org’), (‘no-herd’, None);

maintainers()

Get maintainers’ name, email and description.

Return type

list

Returns

a sequence of _Maintainer objects in document order.

upstream()

Get upstream contact information.

Return type

list

Returns

a sequence of _Upstream objects in document order.

use()

Get names and descriptions for USE flags defined in metadata.

Return type

list

Returns

a sequence of _Useflag objects in document order.

class portage.xml.metadata._Maintainer(node)

Bases: object

An object for representing one maintainer.

@ivar email: Maintainer’s email address. Used for both Gentoo and upstream. :type name: str or None @ivar name: Maintainer’s name. Used for both Gentoo and upstream. :type description: str or None @ivar description: Description of what a maintainer does. Gentoo only. :type maint_type: str or None @ivar maint_type: GLEP67 maintainer type (project or person). Gentoo only. :type restrict: str or None @ivar restrict: e.g. &gt;=portage-2.2 means only maintains versions

of Portage greater than 2.2. Should be DEPEND string with < and > converted to &lt; and &gt; respectively.

@ivar status: If set, either ‘active’ or ‘inactive’. Upstream only.

class portage.xml.metadata._MetadataTreeBuilder

Bases: xml.etree.ElementTree.TreeBuilder

Implements doctype() as required to avoid deprecation warnings with Python >=2.7.

close()
comment(text, /)
data(data, /)
doctype(name, pubid, system)
end(tag, /)
pi(target, text=None, /)
start(tag, attrs, /)
class portage.xml.metadata._Upstream(node)

Bases: object

An object for representing one package’s upstream.

@ivar maintainers: _Maintainer objects for each upstream maintainer :type changelogs: list @ivar changelogs: URLs to upstream’s ChangeLog file in str format :type docs: list @ivar docs: Sequence of tuples containing URLs to upstream documentation

in the first slot and ‘lang’ attribute in the second, e.g., [(‘http…/docs/en/tut.html’, None), (‘http…/doc/fr/tut.html’, ‘fr’)]

@ivar bugtrackers: URLs to upstream’s bugtracker. May also contain an email

address if prepended with ‘mailto:’

@ivar remoteids: Sequence of tuples containing the project’s hosting site

name in the first slot and the project’s ID name or number for that site in the second, e.g., [(‘sourceforge’, ‘systemrescuecd’)]

upstream_bugtrackers()

Retrieve upstream bugtracker location from xml node.

upstream_changelogs()

Retrieve upstream changelog location from xml node.

upstream_documentation()

Retrieve upstream documentation location from xml node.

upstream_maintainers()

Retrieve upstream maintainer information from xml node.

upstream_remoteids()

Retrieve upstream remote ID from xml node.

class portage.xml.metadata._Useflag(node)

Bases: object

An object for representing one USE flag.

Todo

Is there any way to have a keyword option to leave in <pkg> and <cat> for later processing?

@ivar name: USE flag :type restrict: str or None @ivar restrict: e.g. &gt;=portage-2.2 means flag is only available in

versions greater than 2.2

@ivar description: description of the USE flag

portage.xml.metadata._cmp_lang(a, b)
portage.xml.metadata.parse_metadata_use(xml_tree)

Records are wrapped in XML as per GLEP 56 returns a dict with keys constisting of USE flag names and values containing their respective descriptions