pkgcore.util.parserestrict module

Functions that turn a string into a restriction or raise ParseError.

__all__ = (“parse_match”, “ParseError”,)

@var parse_funcs: dict of the functions that are available.

exception pkgcore.util.parserestrict.ParseError[source]

Bases: ValueError

Raised if parsing a restriction expression failed.

pkgcore.util.parserestrict.collect_ops(text)[source]
pkgcore.util.parserestrict.comma_separated_containment(attr, values_kls=<class 'frozenset'>, token_kls=<class 'str'>)[source]

Helper for parsing comma-separated strings to a ContainmentMatch.

Parameters:

attr – name of the attribute.

Returns:

a parse function: takes a string of comma-separated values, returns a packages.PackageRestriction matching packages that have any of those values in the attribute passed to this function.

pkgcore.util.parserestrict.convert_glob(token)[source]
pkgcore.util.parserestrict.parse_globbed_version(text, orig_text)[source]

Support parsing globbed targets with limited version restrictions.

For example, ‘>=*/alsa--1.1.7’ would match all packages named ‘alsa-’ that are version 1.1.7 or greater.

pkgcore.util.parserestrict.parse_match(text)[source]

generate appropriate restriction for text

Parsing basically breaks it down into chunks split by /, with each chunk allowing for prefix/postfix globbing- note that a postfixed glob on package token is treated as package attribute matching, not as necessarily a version match.

If only one chunk is found, it’s treated as a package chunk. Finally, it supports a nonstandard variation of atom syntax where the category can be dropped.

Examples:

  • *: match all

  • dev-*/*: category must start with ‘dev-’

  • dev-*: package must start with ‘dev-’

  • *-apps/portage*: category must end in ‘-apps’, package must start with ‘portage’

  • >=portage-2.1: atom syntax, package ‘portage’, version greater then or equal to ‘2.1’

  • dev-qt/*:5: all Qt 5 libs

  • boost:0/1.60: all packages named boost with a slot/subslot of 0/1.60.0

Parameters:

text (string) – string to attempt to parse

Returns:

pkgcore.restrictions.packages derivative

pkgcore.util.parserestrict.parse_pv(repo, text)[source]

Return a CPV instance from either a cpv or a pv string.

If a pv is passed it needs to match a single cpv in repo.

pkgcore.util.parserestrict.valid_globbing(string, pos=0, endpos=9223372036854775807)

Matches zero or more characters at the beginning of the string.