Created
March 8, 2020 21:44
-
-
Save narenaryan/5b8a872669168496c93a81c09eda67a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile, ZipInfo | |
| from io import BytesIO | |
| def delete(path): | |
| """ | |
| Param: path -> file in archive | |
| Returns a new zip file after deleting path | |
| """ | |
| new_zip = BytesIO() | |
| with ZipFile('config.zip', 'r') as old_archive: | |
| with ZipFile(new_zip, 'w') as new_archive: | |
| for item in old_archive.filelist: | |
| if item.filename != path: | |
| # Copy everything other than path to be inserted | |
| new_archive.writestr(item, old_archive.read(item.filename)) | |
| return new_zip | |
| new_zip = delete('docker/docker-compose.yaml') | |
| # Flush new zip to disk | |
| with open('config.zip', 'wb') as f: | |
| f.write(new_zip.getbuffer()) | |
| new_zip.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment