code: def generate_zipfiles(gallery_dir):
      """
      Collects all Python source files and Jupyter notebooks in
      gallery_dir and makes zipfiles of them
  
      Parameters
      ----------
      gallery_dir : string
          path of the gallery to collect downloadable sources
  
      Return
      ------
      download_rst: string
          RestructuredText to include download buttons to the generated files
      """
  
      listdir = list_downloadable_sources(gallery_dir)
      for directory in sorted(os.listdir(gallery_dir)):
          if os.path.isdir(os.path.join(gallery_dir, directory)):
              target_dir = os.path.join(gallery_dir, directory)
              listdir.extend(list_downloadable_sources(target_dir))
  
      py_zipfile = python_zip(listdir, gallery_dir)
      jy_zipfile = python_zip(listdir, gallery_dir, ".ipynb")
  
      def rst_path(filepath):
          return filepath.replace(os.sep, "/")
  
      dw_rst = CODE_ZIP_DOWNLOAD.format(
          os.path.basename(py_zipfile),
          rst_path(py_zipfile),
          os.path.basename(jy_zipfile),
          rst_path(jy_zipfile),
      )
      return dw_rst
  
imports: from __future__ import absolute_import, division, print_function
  import os
  import zipfile
label_desc: Use image node_id 3 for calling a global function with example usage: generate_zipfiles(gallery_dir) and returns: dw_rst, filepath