code: def get_rsync_version():
      # This does intentionally not query the version of rsync itself, but
      # that of the debian package it's installed with. Reason is in gh-7320,
      # which results in the need to detect a patched-by-ubuntu version of rsync
      # and therefore the package version, not the result of `rsync --version`.
      from datalad.utils import (
          get_linux_distribution,
          on_linux,
      )
  
      if on_linux:
          dist = get_linux_distribution()[0]
          if dist in ["debian", "ubuntu"]:
              out = _runner.run(
                  ["apt-cache", "policy", "rsync"],
                  protocol=StdOutErrCapture,
              )
              for line in out["stdout"].splitlines():
                  parts = line.split()
                  if parts[0] == "Installed:":
                      ver = LooseVersion(parts[1])
                      break
          # If we have a debian package version, use this as rsync version.
          # Otherwise report what `rsync --version` itself has to say.
          if ver:
              return ver
      out = _runner.run(
          ["rsync", "--version"], protocol=StdOutErrCapture
      )
      # Expected first line:
      # rsync version x protocol version y
      return LooseVersion(out["stdout"].splitlines()[0].split()[2])
  
imports: import os.path
  import re
  import sys
  from itertools import chain
  from os import linesep
  from looseversion import LooseVersion
  from datalad.config import get_git_version
  from datalad.log import lgr
  from .exceptions import CapturedException, CommandError
  from datalad.cmd import GitWitlessRunner, StdOutErrCapture, WitlessRunner
  from datalad.support.exceptions import MissingExternalDependency, OutdatedExternalDependency
label_desc: Use image node_id 8 for calling a global function with example usage: get_rsync_version() and returns: LooseVersion, ver