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

Function refresh_db

salt/modules/aptpkg.py:350–447  ·  view source on GitHub ↗

Updates the APT database to latest packages based upon repositories Returns a dict, with the keys being package databases and the values being the result of the update attempt. Values can be one of the following: - ``True``: Database updated successfully - ``False``: Problem u

(cache_valid_time=0, failhard=False, **kwargs)

Source from the content-addressed store, hash-verified

348
349
350def refresh_db(cache_valid_time=0, failhard=False, **kwargs):
351 """
352 Updates the APT database to latest packages based upon repositories
353
354 Returns a dict, with the keys being package databases and the values being
355 the result of the update attempt. Values can be one of the following:
356
357 - ``True``: Database updated successfully
358 - ``False``: Problem updating database
359 - ``None``: Database already up-to-date
360
361 cache_valid_time
362
363 .. versionadded:: 2016.11.0
364
365 Skip refreshing the package database if refresh has already occurred within
366 <value> seconds
367
368 failhard
369
370 If False, return results of Err lines as ``False`` for the package database that
371 encountered the error.
372 If True, raise an error with a list of the package databases that encountered
373 errors.
374
375 CLI Example:
376
377 .. code-block:: bash
378
379 salt '*' pkg.refresh_db
380 """
381 # Remove rtag file to keep multiple refreshes from happening in pkg states
382 salt.utils.pkg.clear_rtag(__opts__)
383 failhard = salt.utils.data.is_true(failhard)
384 ret = {}
385 error_repos = list()
386
387 if cache_valid_time:
388 try:
389 latest_update = os.stat(APT_LISTS_PATH).st_mtime
390 now = time.time()
391 log.debug(
392 "now: %s, last update time: %s, expire after: %s seconds",
393 now,
394 latest_update,
395 cache_valid_time,
396 )
397 if latest_update + cache_valid_time > now:
398 return ret
399 except TypeError as exp:
400 log.warning(
401 "expected integer for cache_valid_time parameter, failed with: %s", exp
402 )
403 except OSError as exp:
404 log.warning("could not stat cache directory due to: %s", exp)
405
406 call = _call_apt(
407 ["apt-get", "-q", "update"],

Callers 7

latest_versionFunction · 0.70
installFunction · 0.70
upgradeFunction · 0.70
list_upgradesFunction · 0.70
del_repoFunction · 0.70
mod_repoFunction · 0.70
showFunction · 0.70

Calls 8

_call_aptFunction · 0.85
timeMethod · 0.80
debugMethod · 0.80
warningMethod · 0.80
listFunction · 0.70
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected