meta_package_manager.base - Package manager definition

exception meta_package_manager.base.CLIError(code, output, error)[source]

Bases: Exception

An error occurred when running package manager CLI.

The exception internally keeps the result of CLI execution.

class meta_package_manager.base.PackageManager[source]

Bases: object

Base class from which all package manager definitions must inherits.

platforms = frozenset({})
requirement = None
cli_search_path = []
global_args = []
raise_on_cli_error = False
ignore_auto_updates = True
id = 'packagemanager'
name = 'PackageManager'
cli_name = 'packagemanager'
virtual = True
cli_path

Fully qualified path to the package manager CLI.

Automaticaly search the location of the CLI in the system.

Returns None if CLI is not found or is not a file.

get_version()[source]

Invoke the manager and extract its own reported version.

It does matter if this method return unsanitized and crappy string. The version() method below will clean and normalized it.

version

Parsed and normalized package manager’s own version.

Returns an instance of TokenizedString.

supported

Is the package manager supported on that platform?

executable

Is the package manager CLI can be executed by the current user?

fresh

Does the package manager match the version requirement?

available

Is the package manager available and ready-to-use on the system?

Returns True only if the main CLI:

1 - is supported on the current platform, 2 - was found on the system, 3 - is executable, and 4 - match the version requirement.

run(*args, dry_run=False)[source]

Run a shell command, return the output and keep error message.

Removes ANSI escape codes, and returns ready-to-use strings.

run_cli(*args, dry_run=False)[source]

Like the run method above, but execute the binary pointed to by the cli_path property set in the current instance.

sync()[source]

Refresh local manager metadata from remote repository.

cleanup()[source]

Remove left-overs and unused packages.

property installed

List packages currently installed on the system.

Returns a dict indexed by package IDs. Each item is a dict with package ID, name and version.

search(query, extended, exact)[source]

Search packages whose ID contain exact or partial query.

Returns a dict indexed by package IDs. Each item is a dict with package ID, name, version and a boolean indicating if the match is exact or partial.

property outdated

List currently installed packages having a new version available.

Returns a dict indexed by package IDs. Each item is a dict with package ID, name, current installed version and latest upgradeable version.

upgrade_cli(package_id=None)[source]

Return a bash-compatible full-CLI to upgrade a package.

upgrade(package_id=None, dry_run=False)[source]

Perform the upgrade of the provided package to latest version.

upgrade_all_cli()[source]

Return a bash-compatible full-CLI to upgrade all packages.

upgrade_all(dry_run=False)[source]

Perform a full upgrade of all outdated packages to latest versions.

If the manager doesn’t implements a full upgrade one-liner, then fall-back to calling single-package upgrade one by one.

static render_cli(cmd, cli_format='plain')[source]

Return a formatted CLI in the requested format.

  • plain returns a simple string

  • fragments returns a list of strings

  • bitbar returns a CLI with parameters formatted into the bitbar

dialect.