MCPcopy
hub / github.com/saltstack/salt / fetch_remotes

Method fetch_remotes

salt/utils/gitfs.py:3432–3520  ·  view source on GitHub ↗

Fetch all remotes and return a boolean to let the calling function know whether or not any remotes were updated in the process of fetching

(self, remotes=None)

Source from the content-addressed store, hash-verified

3430 return cleared, errors
3431
3432 def fetch_remotes(self, remotes=None):
3433 """
3434 Fetch all remotes and return a boolean to let the calling function know
3435 whether or not any remotes were updated in the process of fetching
3436 """
3437 if remotes is None:
3438 remotes = []
3439 elif isinstance(remotes, str):
3440 remotes = remotes.split(",")
3441 elif not isinstance(remotes, list):
3442 log.error(
3443 "Invalid 'remotes' argument (%s) for fetch_remotes. "
3444 "Must be a list of strings",
3445 remotes,
3446 )
3447 remotes = []
3448
3449 changed = False
3450 for repo in self.remotes:
3451 name = getattr(repo, "name", None)
3452 if not remotes or (repo.id, name) in remotes or name in remotes:
3453 try:
3454 # Find and place fetch_request file for all the other branches for this repo
3455 repo_work_hash = os.path.split(repo.get_salt_working_dir())[0]
3456 branches = [
3457 os.path.relpath(path, repo_work_hash)
3458 for (path, subdirs, files) in os.walk(repo_work_hash)
3459 if not subdirs
3460 ]
3461
3462 for branch in branches:
3463 # Don't place fetch request in current branch being updated
3464 if branch == repo.get_cache_basename():
3465 continue
3466 branch_salt_dir = salt.utils.path.join(repo_work_hash, branch)
3467 fetch_path = salt.utils.path.join(
3468 branch_salt_dir, "fetch_request"
3469 )
3470 if os.path.isdir(branch_salt_dir):
3471 try:
3472 with salt.utils.files.fopen(fetch_path, "w"):
3473 pass
3474 except OSError as exc: # pylint: disable=broad-except
3475 log.error(
3476 "Failed to make fetch request: %s %s",
3477 fetch_path,
3478 exc,
3479 exc_info=True,
3480 )
3481 else:
3482 log.error("Failed to make fetch request: %s", fetch_path)
3483 for branch in os.listdir(repo_work_hash):
3484 # Don't place fetch request in current branch being updated
3485 if branch == repo.get_cache_basename():
3486 continue
3487 branch_salt_dir = salt.utils.path.join(repo_work_hash, branch)
3488 fetch_path = salt.utils.path.join(
3489 branch_salt_dir, "fetch_request"

Callers 15

updateMethod · 0.95
handle_git_pillarMethod · 0.80
update_git_reposFunction · 0.80
ext_pillarFunction · 0.80
ext_pillarMethod · 0.80
_test_remote_mapFunction · 0.80
_test_lockFunction · 0.80
_test_fetch_requestFunction · 0.80
_test_remote_mapFunction · 0.80
_test_lockFunction · 0.80
_test_gitfs_simpleFunction · 0.80
_test_gitfs_simple_baseFunction · 0.80

Calls 5

get_salt_working_dirMethod · 0.80
get_cache_basenameMethod · 0.80
errorMethod · 0.45
relpathMethod · 0.45
fetchMethod · 0.45

Tested by 12

_test_remote_mapFunction · 0.64
_test_lockFunction · 0.64
_test_fetch_requestFunction · 0.64
_test_remote_mapFunction · 0.64
_test_lockFunction · 0.64
_test_gitfs_simpleFunction · 0.64
_test_gitfs_simple_baseFunction · 0.64
_test_gitfs_minionFunction · 0.64
_test_nameFunction · 0.64
_test_remote_mapFunction · 0.64
_test_lockFunction · 0.64