Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've modified the python program in <a href="https://stackoverflow.com/questions/975167/uncompress-openoffice-files-for-better-storage-in-version-control/990748#990748">Craig McQueen's answer</a> just a bit. Changes include:</p> <ul> <li><p>Actually checking the return of testZip (according to the docs, it appears that the original program will happily proceed with a corrupt zip file past the checkzip step).</p></li> <li><p>Rewrite the for-loop to check for already-uncompressed files to be a single if-statement.</p></li> </ul> <p>Here is the new program:</p> <pre class="lang-python prettyprint-override"><code>#!/usr/bin/python # Note, written for Python 2.6 import sys import shutil import zipfile # Get a single command-line argument containing filename commandlineFileName = sys.argv[1] backupFileName = commandlineFileName + ".bak" inFileName = backupFileName outFileName = commandlineFileName checkFilename = commandlineFileName # Check input file # First, check it is valid (not corrupted) checkZipFile = zipfile.ZipFile(checkFilename) if checkZipFile.testzip() is not None: raise Exception("Zip file is corrupted") # Second, check that it's not already uncompressed if all(f.compress_type==zipfile.ZIP_STORED for f in checkZipFile.infolist()): raise Exception("File is already uncompressed") checkZipFile.close() # Copy to "backup" file and use that as the input shutil.copy(commandlineFileName, backupFileName) inputZipFile = zipfile.ZipFile(inFileName) outputZipFile = zipfile.ZipFile(outFileName, "w", zipfile.ZIP_STORED) # Copy each input file's data to output, making sure it's uncompressed for fileObject in inputZipFile.infolist(): fileData = inputZipFile.read(fileObject) outFileObject = fileObject outFileObject.compress_type = zipfile.ZIP_STORED outputZipFile.writestr(outFileObject, fileData) outputZipFile.close() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload