human
Complete this python program:
def generate_zipfiles(gallery_dir):
assistant
#Here is the Python program you requested.

    """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