Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a Python script that I've put together. It's had minimal testing so far. I've done basic testing in Python 2.6. But I prefer the idea of Python in general because it should abort with an exception if any error occurs, whereas a bash script may not.</p> <p>This first checks that the input file is valid and not already uncompressed. Then it copies the input file to a "backup" file with ".bak" extension. Then it uncompresses the original file, overwriting it.</p> <p>I'm sure there are things I've overlooked. Please feel free to give feedback.</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) checkZipFile.testzip() # Second, check that it's not already uncompressed isCompressed = False for fileObject in checkZipFile.infolist(): if fileObject.compress_type != zipfile.ZIP_STORED: isCompressed = True if isCompressed == False: 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> <p>This is in a <a href="http://bitbucket.org/cmcqueen1975/odf_uncompress" rel="nofollow noreferrer">Mercurial repository in BitBucket</a>.</p>
 

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