def _add_files()

in tools/bundletool/bundletool.py [0:0]


  def _add_files(self, src, dest, executable, contents_only, out_zip):
    """Adds a file or a directory of files to the ZIP archive.

    Args:
      src: The path to the file or directory that should be added.
      dest: The path inside the archive where the files should be stored. If
          `src` is a single file, then `dest` should include the filename that
          the file should have within the archive. If `src` is a directory, it
          represents the directory into which the files underneath `src` will
          be recursively added.
      executable: A Boolean value indicating whether or not the file(s) should
          be made executable. If a file is already executable, it will remain
          executable, regardless of this value.
      contents_only: A Boolean value indicating whether only the files in `src`
          or `src` itself should be added to the bundle (if `src` is a
          directory).
      out_zip: The `ZipFile` into which the files should be added.
    """
    if os.path.isdir(src):
      for root, _, files in os.walk(src):
        relpath = os.path.relpath(root, src)
        if contents_only:
          relpath = os.path.dirname(relpath)
        for filename in files:
          fsrc = os.path.join(root, filename)
          fdest = os.path.normpath(os.path.join(dest, relpath, filename))
          fexec = executable or os.access(fsrc, os.X_OK)
          with open(fsrc, 'rb') as f:
            self._write_entry(fdest, f.read(), fexec, out_zip)
    elif os.path.isfile(src):
      fexec = executable or os.access(src, os.X_OK)
      with open(src, 'rb') as f:
        self._write_entry(dest, f.read(), fexec, out_zip)