3
ܓi9 @ s> d dl Z d dlZd dlmZ G dd dZG dd deZdS ) N)sos_get_command_outputc @ s e Zd ZdZdZdZdZdZdZdZ dZ
d ddZedd Z
edd Zd!ddZd
d Zd"ddZdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )#PackageManagerau Encapsulates a package manager. If you provide a query_command to the
constructor it should print each package on the system in the following
format::
package name|package.version
You may also subclass this class and provide a _generate_pkg_list method to
build the list of packages and versions.
:cvar query_command: The command to use for querying packages
:vartype query_command: ``str`` or ``None``
:cvar verify_command: The command to use for verifying packages
:vartype verify_command: ``str`` or ``None``
:cvar verify_filter: Optional filter to use for controlling package
verification
:vartype verify_filter: ``str or ``None``
:cvar files_command: The command to use for getting file lists for packages
:vartype files_command: ``str`` or ``None``
:cvar chroot: Perform a chroot when executing `files_command`
:vartype chroot: ``bool``
:cvar remote_exec: If package manager is on a remote system (e.g. for
sos collect), use this to execute commands
:vartype remote_exec: ``SoSTransport.run_command()``
Nc C s d | _ g | _|| _|r|| _d S )N) _packagesfilesremote_execchroot)selfr r r /usr/lib/python3.6/__init__.py__init__8 s
zPackageManager.__init__c C s | j d kr| j | j S )N)r _generate_pkg_list)r r r r
packages@ s
zPackageManager.packagesc C s | j jj jdddd S )Npackage )maxsplitr ) __class____name__lowersplit)r r r r
manager_nameF s zPackageManager.manager_name Fc C sB | j r| j |||||}nt||||d}|d dkr>|d S dS )a
Runs a package manager command, either via sos_get_command_output() if
local, or via a SoSTransport's run_command() if this needs to be run
remotely, as in the case of remote nodes for use during `sos collect`.
:param command: The command to execute
:type command: ``str``
:param timeout: Timeout for command to run, in seconds
:type timeout: ``int``
:param need_root: Does the command require root privileges?
:type need_root: ``bool``
:param env: Environment variables to set
:type env: ``dict`` with keys being env vars to define
:param use_shell: If running remotely, does the command require
obtaining a shell?
:type use_shell: ``bool``
:param chroot: If necessary, chroot command execution to here
:type chroot: ``None`` or ``str``
:returns: The output of the command
:rtype: ``str``
)r envZstatusr output )r r )r ZcommandtimeoutZ need_rootr Z use_shellr retr r r
exec_cmdJ s zPackageManager.exec_cmdc C s t j| jj |S )z
Get a list of packages that match name.
:param name: The name of the package
:type name: ``str``
:returns: List of all packages matching `name`
:rtype: ``list``
)fnmatchfilterr
keys)r namer r r
all_pkgs_by_names s
zPackageManager.all_pkgs_by_namer c s t j|| fdd| jD S )aL
Get a list of packages that match regex_name.
:param regex_name: The regex to use for matching package names against
:type regex_name: ``str``
:param flags: Flags for the `re` module when matching `regex_name`
:returns: All packages matching `regex_name`
:rtype: ``list``
c s g | ]} j |r|qS r )match).0pkg)regr r