fumitoh / modelx

Use Python like a spreadsheet!
https://modelx.io
GNU Lesser General Public License v3.0
96 stars 21 forks source link

Zip archiving the folder #33

Open fumitoh opened 4 years ago

fumitoh commented 4 years ago

One more thing as we are talking about model saving. Have you thought about zip archiving the folder? It will save space and make it more convenient to send the model around. We save the model on OneDrive cloud and it ends up syncing a hundered files instead of 1. Using zip archive will be the same as what Excel does with its files. I can also implement this myself.

Originally posted by @alebaran in https://github.com/fumitoh/modelx/issues/32#issuecomment-644176978

fumitoh commented 4 years ago

Good idea. Looks easy to implement and practical.

alebaran commented 4 years ago
import shutil
save_name = 'my_model'
# write model
mx.write_model(model, save_name)
# zip
shutil.make_archive(save_name, 'zip', save_name)
shutil.rmtree(save_name)
# unzip
shutil.unpack_archive(save_name + '.zip', extract_dir='temp')
# read model
model = mx.read_model('temp')
shutil.rmtree('temp')
fumitoh commented 4 years ago

Thanks for the code.

fumitoh commented 4 years ago

https://docs.modelx.io/en/latest/releases/relnotes_v0_8_0.html

alebaran commented 4 years ago

Thank you for the quick release, very helpful. One question: do you intentionally zip archive without any compression?

fumitoh commented 4 years ago

I wasn’t paying attention to compression. But I did try to write directly to the zip file using zipfile and in-memory files to avoid writing files to the disk.

alexeybaran commented 4 years ago

ZipFile() seems to have compression parameter, which is defaulted to no compression. Here is one of the options making it compress: compression=zipfile.ZIP_DEFLATED