(archive, new_archive, interpreter=None)
Copy an application archive, modifying the shebang line.
Copy an application archive, modifying the shebang line.
Copy an application archive modifying the shebang line .
def _copy_archive(archive, new_archive, interpreter=None):
    """Copy an application archive, modifying the shebang line."""
    with _maybe_open(archive, 'rb') as src:
        # Skip the shebang line from the source.
        # Read 2 bytes of the source and check if they are #!.
        first_2 = src.read(2)
        if first_2 == b'#!':
            # Discard the initial 2 bytes and the rest of the shebang line.
            first_2 = b''
            src.readline()

        with _maybe_open(new_archive, 'wb') as dst:
            _write_file_prefix(dst, interpreter)
            # If there was no shebang, "first_2" contains the first 2 bytes
            # of the source file, so write them before copying the rest
            # of the file.
            dst.write(first_2)
            shutil.copyfileobj(src, dst)

    if interpreter and isinstance(new_archive, str):
        os.chmod(new_archive, os.stat(new_archive).st_mode | stat.S_IEXEC)
def _copy_archive ( archive , new_archive , interpreter = None ) : with _maybe_open ( archive , 'rb' ) as src : # Skip the shebang line from the source. # Read 2 bytes of the source and check if they are #!. first_2 = src . read ( 2 ) if first_2 == b'#!' : # Discard the initial 2 bytes and the rest of the shebang line. first_2 = b'' src . readline ( ) with _maybe_open ( new_archive , 'wb' ) as dst : _write_file_prefix ( dst , interpreter ) # If there was no shebang, "first_2" contains the first 2 bytes # of the source file, so write them before copying the rest # of the file. dst . write ( first_2 ) shutil . copyfileobj ( src , dst ) if interpreter and isinstance ( new_archive , str ) : os . chmod ( new_archive , os . stat ( new_archive ) . st_mode | stat . S_IEXEC )