MCPcopy Create free account
hub / github.com/saltstack/salt / list_pkgs

Function list_pkgs

salt/modules/aptpkg.py:1349–1433  ·  view source on GitHub ↗

List the packages currently installed in a dict:: {' ': ' '} removed If ``True``, then only packages which have been removed (but not purged) will be returned. purge_desired If ``True``, then only packages which have been marked to

(
    versions_as_list=False, removed=False, purge_desired=False, **kwargs
)

Source from the content-addressed store, hash-verified

1347
1348
1349def list_pkgs(
1350 versions_as_list=False, removed=False, purge_desired=False, **kwargs
1351): # pylint: disable=W0613
1352 """
1353 List the packages currently installed in a dict::
1354
1355 {'<package_name>': '<version>'}
1356
1357 removed
1358 If ``True``, then only packages which have been removed (but not
1359 purged) will be returned.
1360
1361 purge_desired
1362 If ``True``, then only packages which have been marked to be purged,
1363 but can&#x27;t be purged due to their status as dependencies for other
1364 installed packages, will be returned. Note that these packages will
1365 appear in installed
1366
1367 .. versionchanged:: 2014.1.1
1368
1369 Packages in this state now correctly show up in the output of this
1370 function.
1371
1372 CLI Example:
1373
1374 .. code-block:: bash
1375
1376 salt '*' pkg.list_pkgs
1377 salt '*' pkg.list_pkgs versions_as_list=True
1378 """
1379 versions_as_list = salt.utils.data.is_true(versions_as_list)
1380 removed = salt.utils.data.is_true(removed)
1381 purge_desired = salt.utils.data.is_true(purge_desired)
1382
1383 if "pkg.list_pkgs" in __context__ and kwargs.get("use_context", True):
1384 return _list_pkgs_from_context(versions_as_list, removed, purge_desired)
1385
1386 ret = {"installed": {}, "removed": {}, "purge_desired": {}}
1387 cmd = [
1388 "dpkg-query",
1389 "--showformat",
1390 "${Status} ${Package} ${Version} ${Architecture}\n",
1391 "-W",
1392 ]
1393
1394 out = __salt__["cmd.run_stdout"](cmd, output_loglevel="trace", python_shell=False)
1395 # Typical lines of output:
1396 # install ok installed zsh 4.3.17-1ubuntu1 amd64
1397 # deinstall ok config-files mc 3:4.8.1-2ubuntu1 amd64
1398 for line in out.splitlines():
1399 cols = line.split()
1400 try:
1401 linetype, status, name, version_num, arch = (
1402 cols[x] for x in (0, 2, 3, 4, 5)
1403 )
1404 except (ValueError, IndexError):
1405 continue
1406 if __grains__.get("cpuarch", "") == "x86_64":

Callers 5

latest_versionFunction · 0.70
installFunction · 0.70
_uninstallFunction · 0.70
autoremoveFunction · 0.70
upgradeFunction · 0.70

Calls 3

_list_pkgs_from_contextFunction · 0.70
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected