debian.debtags module

Facilities to work with debtags - tags for Debian packages

class debian.debtags.DB

Bases: object

In-memory database mapping packages to tags and tags to packages.

card(tag: str) int

Return the cardinality of a tag

choose_packages(package_iter: Iterable[str]) DB

Return a collection with only the packages in package_iter, sharing tagsets with this one

choose_packages_copy(package_iter: Iterable[str]) DB

Return a collection with only the packages in package_iter, with a copy of the tagsets of this one

copy() DB

Return a copy of this collection, with the tagsets copied as well.

correlations() Iterator[Tuple[str, str, float]]

Generate the list of correlation as a tuple (hastag, hasalsotag, score).

Every tuple will indicate that the tag ‘hastag’ tends to also have ‘hasalsotag’ with a score of ‘score’.

discriminance(tag: str) int

Return the discriminance index if the tag.

Th discriminance index of the tag is defined as the minimum number of packages that would be eliminated by selecting only those tagged with this tag or only those not tagged with this tag.

dump() None
dump_reverse() None
facet_collection() DB

Return a copy of this collection, but replaces the tag names with only their facets.

filter_packages(package_filter: Callable[[str], bool]) DB

Return a collection with only those packages that match a filter, sharing tagsets with this one. The filter will match on the package.

filter_packages_copy(filter_data: Callable[[str], bool]) DB

Return a collection with only those packages that match a filter, with a copy of the tagsets of this one. The filter will match on the package.

filter_packages_tags(package_tag_filter: Callable[[Tuple[str, Set[str]]], bool]) DB

Return a collection with only those packages that match a filter, sharing tagsets with this one. The filter will match on (package, tags).

filter_packages_tags_copy(package_tag_filter: Callable[[Tuple[str, Set[str]]], bool]) DB

Return a collection with only those packages that match a filter, with a copy of the tagsets of this one. The filter will match on (package, tags).

filter_tags(tag_filter: Callable[[str], bool]) DB

Return a collection with only those tags that match a filter, sharing package sets with this one. The filter will match on the tag.

filter_tags_copy(tag_filter: Callable[[str], bool]) DB

Return a collection with only those tags that match a filter, with a copy of the package sets of this one. The filter will match on the tag.

has_package(pkg: str) bool

Check if the collection contains the given package

has_tag(tag: str) bool

Check if the collection contains packages tagged with tag

ideal_tagset(tags: List[str]) Set[str]

Return an ideal selection of the top tags in a list of tags.

Return the tagset made of the highest number of tags taken in consecutive sequence from the beginning of the given vector, that would intersect with the tagset of a comfortable amount of packages.

Comfortable is defined in terms of how far it is from 7.

insert(pkg: str, tags: Set[str]) None
iter_packages() Iterable[str]

Iterate over the packages

iter_packages_tags() Iterable[Tuple[str, Set[str]]]

Iterate over 2-tuples of (pkg, tags)

iter_tags() Iterable[str]

Iterate over the tags

iter_tags_packages() Iterable[Tuple[str, Set[str]]]

Iterate over 2-tuples of (tag, pkgs)

package_count() int

Return the number of packages

packages_of_tag(tag: str) Set[str]

Return the package set of a tag

packages_of_tags(tags: Iterable[str]) Set[str]

Return the set of packages that have all the tags in tags

qread(file: IO[bytes]) None

Quickly read the data from a pickled file

qwrite(file: IO[bytes]) None

Quickly write the data to a pickled file

read(input_data: Iterator[str], tag_filter: Callable[[str], bool] | None = None) None

Read the database from a file.

Example::

# Read the system Debtags database db.read(open(“/var/lib/debtags/package-tags”, “r”))

reverse() DB

Return the reverse collection, sharing tagsets with this one

reverse_copy() DB

Return the reverse collection, with a copy of the tagsets of this one.

tag_count() int

Return the number of tags

tags_of_package(pkg: str) Set[str]

Return the tag set of a package

tags_of_packages(pkgs: Iterable[str]) Set[str]

Return the set of tags that have all the packages in pkgs

debian.debtags.output(db: Dict[str, Set[str]]) None

Write the tag database

debian.debtags.parse_tags(input_data: Iterator[str]) Iterator[Tuple[Set[str], Set[str]]]
debian.debtags.read_tag_database(input_data: Iterator[str]) Dict[str, Set[str]]

Read the tag database, returning a pkg->tags dictionary

debian.debtags.read_tag_database_both_ways(input_data: Iterator[str], tag_filter: Callable[[str], bool] | None = None) Tuple[Dict[str, Set[str]], Dict[str, Set[str]]]

Read the tag database, returning a pkg->tags and a tag->pkgs dictionary

debian.debtags.read_tag_database_reversed(input_data: Iterator[str]) Dict[str, Set[str]]

Read the tag database, returning a tag->pkgs dictionary

debian.debtags.relevance_index_function(full, sub)
debian.debtags.reverse(db: Dict[str, Set[str]]) Dict[str, Set[str]]

Reverse a tag database, from package -> tags to tag->packages