def zip_dir(path, stream, include_dir=True, fnct_sort=None):
 path = os.path.normpath(path)
 len_prefix = (len(os.path.dirname(path)) if include_dir else len(path))
 if len_prefix:
  len_prefix += 1
 with zipfile.ZipFile(stream, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=True) as zipf:
  for (dirpath, dirnames, filenames) in os.walk(path):
   filenames = sorted(filenames, key=fnct_sort)
   for fname in filenames:
    (bname, ext) = os.path.splitext(fname)
    ext = (ext or bname)
    if (ext not in ['.pyc', '.pyo', '.swp', '.DS_Store']):
     path = os.path.normpath(os.path.join(dirpath, fname))
     if os.path.isfile(path):
      zipf.write(path, path[len_prefix:])

def zip_dir ( path , stream , include_dir = True , fnct_sort = None ) : path = os . path . normpath ( path ) len_prefix = ( len ( os . path . dirname ( path ) ) if include_dir else len ( path ) ) if len_prefix : len_prefix += 1 with zipfile . ZipFile ( stream , 'w' , compression = zipfile . ZIP_DEFLATED , allowZip64 = True ) as zipf : for ( dirpath , dirnames , filenames ) in os . walk ( path ) : filenames = sorted ( filenames , key = fnct_sort ) for fname in filenames : ( bname , ext ) = os . path . splitext ( fname ) ext = ( ext or bname ) if ( ext not in [ '.pyc' , '.pyo' , '.swp' , '.DS_Store' ] ) : path = os . path . normpath ( os . path . join ( dirpath , fname ) ) if os . path . isfile ( path ) : zipf . write ( path , path [ len_prefix : ] )
zip a directory tree into a bytesio object .