jupyterlab_dosbox/utils.py
def make_zipfile(filenames, prefix_directory = ""):
    """
    This accepts either a list of strings, in which case the files will be
    added to an in-memory zipfile from those named files, or a set of
    dictionary entries, where the dictionary keys are the filenames and the
    values are the contents of those files.
    """
    # First we need to figure out the full set of directories, because
    # for our purposes we need to make sure that all of the directories
    # have been created.
    if isinstance(filenames, list):
        filenames = {_: None for _ in filenames}
    dirnames = set()
    for fn in filenames:
        dirnames.add(os.path.dirname(fn))
    base = os.path.commonpath(list(dirnames))
    # This breaks if everything is under a subdirectory
    #dirnames = set(os.path.relpath(_, base) for _ in dirnames if len(_) > 0)
    if '.' in dirnames: dirnames.remove('.')
    if '' in dirnames: dirnames.remove('')
    b = io.BytesIO()
    with zipfile.ZipFile(b, "w") as f:
        for d in sorted(dirnames):
            f.writestr(os.path.join(d, ""), "")
        for fn, content in filenames.items():
            if content is None:
                f.write(fn, arcname=os.path.join(prefix_directory, fn))
            else:
                f.writestr(fn, content)
    b.seek(0)
    return b.read()

    This accepts either a list of strings, in which case the files will be
    added to an in-memory zipfile from those named files, or a set of
    dictionary entries, where the dictionary keys are the filenames and the
    values are the contents of those files.
    
This accepts either a list of strings, in which case the files will be
added to an in-memory zipfile from those named files, or a set of
dictionary entries, where the dictionary keys are the filenames and the
values are the contents of those files.
This accepts either a list of strings in which case the files will be added to an in - memory zipfile from those named files or a set of dictionary entries where the dictionary keys are the filenames and the values are the contents of those files .
def make_zipfile(filenames, prefix_directory = ""):
    if isinstance(filenames, list):
        filenames = {_: None for _ in filenames}
    dirnames = set()
    for fn in filenames:
        dirnames.add(os.path.dirname(fn))
    base = os.path.commonpath(list(dirnames))
    if '.' in dirnames: dirnames.remove('.')
    if '' in dirnames: dirnames.remove('')
    b = io.BytesIO()
    with zipfile.ZipFile(b, "w") as f:
        for d in sorted(dirnames):
            f.writestr(os.path.join(d, ""), "")
        for fn, content in filenames.items():
            if content is None:
                f.write(fn, arcname=os.path.join(prefix_directory, fn))
            else:
                f.writestr(fn, content)
    b.seek(0)
    return b.read()
def make_zipfile ( filenames , prefix_directory = "" ) : if isinstance ( filenames , list ) : filenames = { _ : None for _ in filenames } dirnames = set ( ) for fn in filenames : dirnames . add ( os . path . dirname ( fn ) ) base = os . path . commonpath ( list ( dirnames ) ) if '.' in dirnames : dirnames . remove ( '.' ) if '' in dirnames : dirnames . remove ( '' ) b = io . BytesIO ( ) with zipfile . ZipFile ( b , "w" ) as f : for d in sorted ( dirnames ) : f . writestr ( os . path . join ( d , "" ) , "" ) for fn , content in filenames . items ( ) : if content is None : f . write ( fn , arcname = os . path . join ( prefix_directory , fn ) ) else : f . writestr ( fn , content ) b . seek ( 0 ) return b . read ( )
This accepts either a list of strings, in which case the files will be
added to an in-memory zipfile from those named files, or a set of
dictionary entries, where the dictionary keys are the filenames and the
values are the contents of those files.
This accepts either a list of strings in which case the files will be added to an in - memory zipfile from those named files or a set of dictionary entries where the dictionary keys are the filenames and the values are the contents of those files .
"""
    This accepts either a list of strings, in which case the files will be
    added to an in-memory zipfile from those named files, or a set of
    dictionary entries, where the dictionary keys are the filenames and the
    values are the contents of those files.
    """ # First we need to figure out the full set of directories, because # for our purposes we need to make sure that all of the directories # have been created. # This breaks if everything is under a subdirectory #dirnames = set(os.path.relpath(_, base) for _ in dirnames if len(_) > 0)
filenames
prefix_directory