Created
May 14, 2011 23:21
-
-
Save monokrome/972749 to your computer and use it in GitHub Desktop.
A zip file which happens to let content overlay it's files. Use with a dash of StringIO for grand results.
This file contains 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
import zipfile | |
class OverlayZipFile(zipfile.ZipFile): | |
""" Adds a method for overlaying a zip file with a given directory, or another | |
zip file. """ | |
def overlay(self, content): | |
""" Overlays content over the zip file represented by 'self'. | |
Receives a zip file, and write's it's entire content over the zip file which | |
is represented by 'self' - overwriting any files in the current zip with the | |
any files of the same name which are within the provided content zip file. | |
""" | |
for filename in content.namelist(): | |
self.writestr(filename, content.read(filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment