少し前に、仮想ディレクトリ、ファイルを作成し、必要に応じてそれらを圧縮するための小さな python ライブラリ ( https://github.com/kajic/vdir ) を実装しました。README から (仮想ディレクトリは最後に圧縮されています):
from vdir import VDir
vd = VDir()
# Write to file
vd.open("path/to/some/file").write("your data")
# Create directory, go inside it, and write to some other file
vd.mkdir("foo")
vd.cd("foo")
vd.open("bar").write("something else") # writes to /foo/bar
# Read from file
vd.open("bar").read()
# Get the current path
vd.pwd()
# Copy directory and all its contents
vd.cp("/foo", "/foo_copy")
# Move the copied directory somewhere else
vd.mv("/foo_copy", "/foo_moved")
# Create a file, then remove it
vd.open("unnecessary").write("foo")
vd.rm("unnecessary")
# Walk over all directories and files in the virtual directory
vd.cd("/")
for base, dirnames, dirs, filenames, files in vd.walk():
pass
# Recursively list directory contents
vd.ls()
# Create a zip from the virtual directory
zip = vd.compress()
# Get zip data
zip.read()
私は楽しみのためにそれをやっただけで、広範囲にテストしていませんが、とにかくあなたに役立つかもしれません.