google-group-archiver_50.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. def update_archive(self, archive):
  2. self.__super_update_archive(archive)
  3. # only do this if the gzip module was imported globally, and
  4. # gzip'ing was enabled via mm_cfg.GZIP_ARCHIVE_TXT_FILES. See
  5. # above.
  6. if gzip:
  7. archz = None
  8. archt = None
  9. txtfile = os.path.join(self.basedir, '%s.txt' % archive)
  10. gzipfile = os.path.join(self.basedir, '%s.txt.gz' % archive)
  11. oldgzip = os.path.join(self.basedir, '%s.old.txt.gz' % archive)
  12. try:
  13. # open the plain text file
  14. archt = open(txtfile)
  15. except IOError:
  16. return
  17. try:
  18. os.rename(gzipfile, oldgzip)
  19. archz = gzip.open(oldgzip)
  20. except (IOError, RuntimeError, os.error):
  21. pass
  22. try:
  23. ou = os.umask(2)
  24. newz = gzip.open(gzipfile, 'w')
  25. finally:
  26. # XXX why is this a finally?
  27. os.umask(ou)
  28. if archz:
  29. newz.write(archz.read())
  30. archz.close()
  31. os.unlink(oldgzip)
  32. # XXX do we really need all this in a try/except?
  33. try:
  34. newz.write(archt.read())
  35. newz.close()
  36. archt.close()
  37. except IOError:
  38. pass
  39. os.unlink(txtfile)