code: def merge_index(local_index, remote_index):
      """Merge the `remote_index` into `local_index`.
  
      The merging process is only applied over the checkpoints in `local_index`
      marked as ``remote``.
      """
  
      non_remotes_in_local = [
          c
          for c in local_index["checkpoints"]
          if c["source"] != "remote"
      ]
      remotes_in_local = {
          c["id"]: c
          for c in local_index["checkpoints"]
          if c["source"] == "remote"
      }
  
      to_add = []
      seen_ids = set()
      for checkpoint in remote_index["checkpoints"]:
          seen_ids.add(checkpoint["id"])
          local = remotes_in_local.get(checkpoint["id"])
          if local:
              # Checkpoint is in local index. Overwrite all the fields.
              local.update(**checkpoint)
          elif not local:
              # Checkpoint not found, it's an addition. Transform into our schema
              # before appending to `to_add`. (The remote index schema is exactly
              # the same except for the ``source`` and ``status`` keys.)
              checkpoint["source"] = "remote"
              checkpoint["status"] = "NOT_DOWNLOADED"
              to_add.append(checkpoint)
  
      # Out of the removed checkpoints, only keep those with status
      # ``DOWNLOADED`` and turn them into local checkpoints.
      missing_ids = set(remotes_in_local.keys()) - seen_ids
      already_downloaded = [
          c
          for c in remotes_in_local.values()
          if c["id"] in missing_ids and c["status"] == "DOWNLOADED"
      ]
      for checkpoint in already_downloaded:
          checkpoint["status"] = "LOCAL"
          checkpoint["source"] = "local"
  
      new_remotes = (
          [
              c
              for c in remotes_in_local.values()
              if not c["id"] in missing_ids  # Checkpoints to remove.
          ]
          + to_add
          + already_downloaded
      )
  
      if len(to_add):
          click.echo(
              "{} new remote checkpoints added.".format(len(to_add))
          )
      if len(missing_ids):
          if len(already_downloaded):
              click.echo(
                  "{} remote checkpoints transformed to local.".format(
                      len(already_downloaded)
                  )
              )
          click.echo(
              "{} remote checkpoints removed.".format(
                  len(missing_ids) - len(already_downloaded)
              )
          )
      if not len(to_add) and not len(missing_ids):
          click.echo("No changes in remote index.")
  
      local_index["checkpoints"] = non_remotes_in_local + new_remotes
  
      return local_index
  
imports: import click
  import json
  import os
  import shutil
  import six
  import requests
  import tarfile
  import tempfile
  import tensorflow
  import uuid
  from datetime import datetime
  from luminoth import __version__
  from luminoth.utils.config import get_config
  from luminoth.utils.homedir import get_luminoth_home
label_desc: Use image node_id 5 for calling a global function with example usage: merge_index(local_index, remote_index) and returns: local_index