def unzip_into(path, outpath, verbose=False):
    """
    Unzip zipfile at path into outpath.
    :param path: path to zipfile
    :type path: str
    :param outpath: path to extract to
    :type outpath: str
    """
    if not os.path.exists(outpath):
        os.makedirs(outpath)
    if verbose:
        print('Unzipping into %s ...' % outpath)
        
    with zipfile.ZipFile(path) as zipfp:
        toplevel_directory = None
        namelist = zipfp.namelist()
        
        # find toplevel directory name
        for name in namelist:
            if os.path.dirname(os.path.normpath(name)) == "":
                # is toplevel
                toplevel_directory = name
                break
        
        for name in namelist:
            data = zipfp.read(name)
            name = name.split(toplevel_directory, 1)[-1]  # strip the top-level directory
            if name == '':  # skip top-level directory
                continue

            fname = os.path.join(outpath, name)
            if fname.endswith('/'):  # A directory
                if not os.path.exists(fname):
                    os.makedirs(fname)
            else:
                fp = open(fname, 'wb')
                try:
                    fp.write(data)
                finally:
                    fp.close()

    Unzip zipfile at path into outpath.
    :param path: path to zipfile
    :type path: str
    :param outpath: path to extract to
    :type outpath: str
    
getstash.py