code: def _guess_exec(script_file):
      try:
          is_exec = os.stat(script_file).st_mode & stat.S_IEXEC
      except OSError as e:
          from errno import ENOENT
  
          if e.errno == ENOENT and op.islink(script_file):
              # broken symlink
              # does not exist; there's nothing to detect at all
              return {"type": None, "template": None, "state": "absent"}
          else:
              raise e
  
      # on some FS the executable bit might not be all that reliable
      # but a procedure might nevertheless be supported.
      # go by extension with "known" interpreters first, and only then
      # try to execute something that looks executable
      if script_file.endswith(".sh"):
          return {
              "type": "bash_script",
              "template": "bash {script} {ds} {args}",
              "state": "executable",
          }
      elif script_file.endswith(".py"):
          ex = quote_cmdlinearg(sys.executable)
          return {
              "type": "python_script",
              "template": "%s {script} {ds} {args}" % ex,
              "state": "executable",
          }
      elif is_exec and not os.path.isdir(script_file):
          return {
              "type": "executable",
              "template": "{script} {ds} {args}",
              "state": "executable",
          }
      else:
          return {"type": None, "template": None, "state": None}
  
imports: import logging
  import os
  import os.path
  import stat
  import sys
  from argparse import REMAINDER
  from glob import iglob
  import datalad.support.ansi_colors
  from datalad import cfg
  from datalad.core.local.run import Run
  from datalad.distribution.dataset import Dataset, EnsureDataset, datasetmethod, require_dataset
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.results import get_status_dict
  from datalad.support.constraints import EnsureNone
  from datalad.support.exceptions import InsufficientArgumentsError, NoDatasetFound
  from datalad.support.param import Parameter
  from datalad.utils import ensure_list, guard_for_format, join_cmdline, quote_cmdlinearg, split_cmdline
label_desc: Use image node_id 4 for calling a global function with example usage: _guess_exec(script_file) and returns: dict, dict, dict, dict, dict