ALMA Cycle 9 corrupted zip fix

If you encounter a bug like this:

"XML (syntax or validity) error" because you hit issue C1_032, the fix is really easy:

import zipfile
import os

# not strictly necessary, but important if you want to avoid filling your directory with files
os.mkdir('recovery')
os.chdir('recovery')

# replace with your AOT file name
with zipfile.ZipFile('../corrupted.aot', 'r') as aot:
    # this will extract all the files into the current directory
    aot.extractall()
    files = aot.filelist

with zipfile.ZipFile('../recovered.aot', 'w') as aot:
    for fh in files:
        aot.write(fh.filename)

At least, this worked on the one case where I got bitten.

This fix is based on Erik Rosolowsky's ALMA proposal tools

Comments