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

Function latest_version

salt/modules/aptpkg.py:202–325  ·  view source on GitHub ↗

.. versionchanged:: 3007.0 Return the latest version of the named package available for upgrade or installation. If more than one package name is specified, a dict of name/version pairs is returned. If the latest version of a given package is already installed, an empty st

(*names, **kwargs)

Source from the content-addressed store, hash-verified

200
201
202def latest_version(*names, **kwargs):
203 # pylint: disable=W0640
204 """
205 .. versionchanged:: 3007.0
206
207 Return the latest version of the named package available for upgrade or
208 installation. If more than one package name is specified, a dict of
209 name/version pairs is returned.
210
211 If the latest version of a given package is already installed, an empty
212 string will be returned for that package.
213
214 A specific repo can be requested using the ``fromrepo`` keyword argument.
215
216 cache_valid_time
217
218 .. versionadded:: 2016.11.0
219
220 Skip refreshing the package database if refresh has already occurred within
221 <value> seconds
222
223 CLI Example:
224
225 .. code-block:: bash
226
227 salt '*' pkg.latest_version <package name>
228 salt '*' pkg.latest_version <package name> fromrepo=unstable
229 salt '*' pkg.latest_version <package1> <package2> <package3> ...
230 """
231 refresh = salt.utils.data.is_true(kwargs.pop("refresh", True))
232 show_installed = salt.utils.data.is_true(kwargs.pop("show_installed", False))
233 if "repo" in kwargs:
234 raise SaltInvocationError(
235 "The 'repo' argument is invalid, use 'fromrepo' instead"
236 )
237 fromrepo = kwargs.pop("fromrepo", None)
238 cache_valid_time = kwargs.pop("cache_valid_time", 0)
239 names = list(names)
240
241 if not names:
242 return ""
243 ret = {name: "" for name in names} # Initialize the dict with empty strings
244 pkgs = list_pkgs(versions_as_list=True)
245 repo = ["-o", f"APT::Default-Release={fromrepo}"] if fromrepo else None
246
247 # Refresh before looking for the latest version available
248 if refresh:
249 refresh_db(cache_valid_time)
250
251 cmd = ["apt-cache", "-q", "policy"]
252 cmd.extend(names)
253 if repo is not None:
254 cmd.extend(repo)
255 out = _call_apt(cmd, scope=False)
256
257 short_names = [nom.split(":", maxsplit=1)[0] for nom in names]
258
259 candidates = {}

Callers 2

installFunction · 0.70
upgrade_availableFunction · 0.70

Calls 11

SaltInvocationErrorClass · 0.90
_call_aptFunction · 0.85
listFunction · 0.70
list_pkgsFunction · 0.70
refresh_dbFunction · 0.70
filterFunction · 0.50
popMethod · 0.45
extendMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected