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

Function _uninstall

salt/modules/aptpkg.py:886–940  ·  view source on GitHub ↗

remove and purge do identical things but with different apt-get commands, this function performs the common logic.

(action="remove", name=None, pkgs=None, **kwargs)

Source from the content-addressed store, hash-verified

884
885
886def _uninstall(action="remove", name=None, pkgs=None, **kwargs):
887 """
888 remove and purge do identical things but with different apt-get commands,
889 this function performs the common logic.
890 """
891 try:
892 pkg_params = __salt__["pkg_resource.parse_targets"](name, pkgs)[0]
893 except MinionError as exc:
894 raise CommandExecutionError(exc)
895
896 old = list_pkgs()
897 old_removed = list_pkgs(removed=True)
898 targets = [
899 _pkg for _pkg in salt.utils.pkg.match_wildcard(old, pkg_params) if _pkg in old
900 ]
901 if action == "purge":
902 targets.extend(
903 [
904 _pkg
905 for _pkg in salt.utils.pkg.match_wildcard(old_removed, pkg_params)
906 if _pkg in old_removed
907 ]
908 )
909 if not targets:
910 return {}
911 cmd = ["apt-get", "-q", "-y", action]
912 cmd.extend(targets)
913 env = _parse_env(kwargs.get("env"))
914 env.update(DPKG_ENV_VARS.copy())
915 out = _call_apt(cmd, env=env)
916 if out["retcode"] != 0 and out["stderr"]:
917 errors = [out["stderr"]]
918 else:
919 errors = []
920
921 __context__.pop("pkg.list_pkgs", None)
922 new = list_pkgs()
923 new_removed = list_pkgs(removed=True)
924
925 changes = salt.utils.data.compare_dicts(old, new)
926 if action == "purge":
927 ret = {
928 "removed": salt.utils.data.compare_dicts(old_removed, new_removed),
929 "installed": changes,
930 }
931 else:
932 ret = changes
933
934 if errors:
935 raise CommandExecutionError(
936 "Problem encountered removing package(s)",
937 info={"errors": errors, "changes": ret},
938 )
939
940 return ret
941
942
943def autoremove(list_only=False, purge=False):

Callers 2

removeFunction · 0.70
purgeFunction · 0.70

Calls 9

_parse_envFunction · 0.90
_call_aptFunction · 0.85
list_pkgsFunction · 0.70
extendMethod · 0.45
getMethod · 0.45
updateMethod · 0.45
copyMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected