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

Function autoremove

salt/modules/aptpkg.py:943–995  ·  view source on GitHub ↗

.. versionadded:: 2015.5.0 Remove packages not required by another package using ``apt-get autoremove``. list_only : False Only retrieve the list of packages to be auto-removed, do not actually perform the auto-removal. purge : False Also remove packag

(list_only=False, purge=False)

Source from the content-addressed store, hash-verified

941
942
943def autoremove(list_only=False, purge=False):
944 """
945 .. versionadded:: 2015.5.0
946
947 Remove packages not required by another package using ``apt-get
948 autoremove``.
949
950 list_only : False
951 Only retrieve the list of packages to be auto-removed, do not actually
952 perform the auto-removal.
953
954 purge : False
955 Also remove package config data when autoremoving packages.
956
957 .. versionadded:: 2015.8.0
958
959 CLI Example:
960
961 .. code-block:: bash
962
963 salt '*' pkg.autoremove
964 salt '*' pkg.autoremove list_only=True
965 salt '*' pkg.autoremove purge=True
966 """
967 cmd = []
968 if list_only:
969 ret = []
970 cmd.extend(["apt-get", "--assume-no"])
971 if purge:
972 cmd.append("--purge")
973 cmd.append("autoremove")
974 out = _call_apt(cmd, ignore_retcode=True)["stdout"]
975 found = False
976 for line in out.splitlines():
977 if found is True:
978 if line.startswith(" "):
979 ret.extend(line.split())
980 else:
981 found = False
982 elif "The following packages will be REMOVED:" in line:
983 found = True
984 ret.sort()
985 return ret
986 else:
987 old = list_pkgs()
988 cmd.extend(["apt-get", "--assume-yes"])
989 if purge:
990 cmd.append("--purge")
991 cmd.append("autoremove")
992 _call_apt(cmd, ignore_retcode=True)
993 __context__.pop("pkg.list_pkgs", None)
994 new = list_pkgs()
995 return salt.utils.data.compare_dicts(old, new)
996
997
998def remove(name=None, pkgs=None, **kwargs):

Callers

nothing calls this directly

Calls 5

_call_aptFunction · 0.85
list_pkgsFunction · 0.70
extendMethod · 0.45
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected