def update_archive(self, archive): self.__super_update_archive(archive) # only do this if the gzip module was imported globally, and # gzip'ing was enabled via mm_cfg.GZIP_ARCHIVE_TXT_FILES. See # above. if gzip: archz = None archt = None txtfile = os.path.join(self.basedir, '%s.txt' % archive) gzipfile = os.path.join(self.basedir, '%s.txt.gz' % archive) oldgzip = os.path.join(self.basedir, '%s.old.txt.gz' % archive) try: # open the plain text file archt = open(txtfile) except IOError: return try: os.rename(gzipfile, oldgzip) archz = gzip.open(oldgzip) except (IOError, RuntimeError, os.error): pass try: ou = os.umask(2) newz = gzip.open(gzipfile, 'w') finally: # XXX why is this a finally? os.umask(ou) if archz: newz.write(archz.read()) archz.close() os.unlink(oldgzip) # XXX do we really need all this in a try/except? try: newz.write(archt.read()) newz.close() archt.close() except IOError: pass os.unlink(txtfile)