brennivin.zipfileutils module¶
Utilities for working with zip files.
Members¶
- class brennivin.zipfileutils.ZipFile¶
zipfile.ZipFile with a context manager (2.6 does not have a context manager. Use if your code needs a ZipFile context manager and must run under 2.6.
- brennivin.zipfileutils.compare_zip_files(z1, z2)¶
Compares the contents of two zip files (file paths and crcs).
Returns: None if they are the same. Raises FileComparisonError: If the files are different. Message contains a string summarizing the difference.
- brennivin.zipfileutils.is_inside_zipfile(filepath)¶
Iterates up a directory tree checking at each level if the path exists. If a subpath exists and points to a zipfile, return true
Parameters: filepath – Fully qualified path to a file
- brennivin.zipfileutils.write_dir(rootpath, zfile, include=ALL, exclude=NONE, subdir=None)¶
Zip all files under rootpath to a zip stream. See zip_dir() for arguments.
- brennivin.zipfileutils.write_files(fullpaths, zfile, include=ALL, exclude=NONE, subdir=None, rootpath=None)¶
Zip files to a zip stream. See zip_dir() for arguments.
Parameters: - fullpaths – Absolute paths to files to zip.
- subdir – See zip_dir(). Only valid if rootpath is also specified.
- rootpath – If provided, paths in the archive will be relative to this. Ie, passing in a branch’s root and the absolute paths to files in the branch would make the paths in the archive be relative to the branch root.
- brennivin.zipfileutils.zip_dir(rootdir, outfile, include=ALL, exclude=NONE, subdir=None)¶
Zip all files under the root directory to a zip file at outfile.
Parameters: - outfile – Path to zipfile, or ZipFile stream.
- include – Include only files that this function returns True for.
- exclude – Include no files that this function returns True for.
- subdir – If provided, nest the rootdir under this folder in the archive. For example, zipping the directory spam with the files /spam/eggs/ham.txt and subdir of foo would yield the archive file foo/eggs/ham.txt.