Skip to content

Commit

Permalink
(fixes buildbot#599) make bz2 module optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Jul 20, 2009
1 parent 7d71ae0 commit 497aa6c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions buildbot/status/builder.py
Expand Up @@ -12,7 +12,11 @@
import gc
from cPickle import load, dump
from cStringIO import StringIO
from bz2 import BZ2File

try: # bz2 is not available on py23
from bz2 import BZ2File
except ImportError:
BZ2File = None

# sibling imports
from buildbot import interfaces, util, sourcestamp
Expand Down Expand Up @@ -282,10 +286,11 @@ def getFile(self):
return self.openfile
# otherwise they get their own read-only handle
# try a compressed log first
try:
return BZ2File(self.getFilename() + ".bz2", "r")
except IOError:
pass
if BZ2File is not None:
try:
return BZ2File(self.getFilename() + ".bz2", "r")
except IOError:
pass
return open(self.getFilename(), "r")

def getText(self):
Expand Down Expand Up @@ -444,6 +449,10 @@ def finish(self):


def compressLog(self):
# bail out if there's no compression support
if BZ2File is None:
return

compressed = self.getFilename() + ".bz2.tmp"
d = threads.deferToThread(self._compressLog, compressed)
d.addCallback(self._renameCompressedLog, compressed)
Expand Down

0 comments on commit 497aa6c

Please sign in to comment.