Ticket #26: buildbot-gzip.patch
| File buildbot-gzip.patch, 2.6 kB (added by slinkp, 8 months ago) |
|---|
-
buildbot/status/builder.py
old new 6 6 from twisted.internet import reactor, defer 7 7 from twisted.protocols import basic 8 8 9 import gzip 9 10 import os, shutil, sys, re, urllib, itertools 11 10 12 from cPickle import load, dump 11 13 from cStringIO import StringIO 12 14 … … 40 42 HEADER = interfaces.LOG_CHANNEL_HEADER 41 43 ChunkTypes = ["stdout", "stderr", "header"] 42 44 45 def gzopen(path, *args): 46 """Open a file, gzipped if possible.""" 47 if args: 48 mode = args[0] 49 else: 50 mode = 'r' 51 f = gzip.open(path, *args) 52 if mode.startswith('w'): 53 # we're wiping out any existing file, so, unconditionally gzip it. 54 return f 55 try: 56 # See if the existing file is really gzipped. 57 f.seek(1) 58 f.seek(0) 59 return f 60 except IOError: 61 del f 62 # We have an existing, non-gzipped file. 63 return open(path, *args) 64 65 43 66 class LogFileScanner(basic.NetstringReceiver): 44 67 def __init__(self, chunk_cb, channels=[]): 45 68 self.chunk_cb = chunk_cb … … 50 73 if not self.channels or (channel in self.channels): 51 74 self.chunk_cb((channel, line[1:])) 52 75 76 53 77 class LogFileProducer: 54 78 """What's the plan? 55 79 … … 227 251 # is out of date, and we're overlapping with earlier builds now. 228 252 # Warn about it, but then overwrite the old pickle file 229 253 log.msg("Warning: Overwriting old serialized Build at %s" % fn) 230 self.openfile = open(fn, "w+")254 self.openfile = gzopen(fn, "w+") 231 255 self.runEntries = [] 232 256 self.watchers = [] 233 257 self.finishedWatchers = [] … … 260 284 # don't close it! 261 285 return self.openfile 262 286 # otherwise they get their own read-only handle 263 return open(self.getFilename(), "r")287 return gzopen(self.getFilename(), "r") 264 288 265 289 def getText(self): 266 290 # this produces one ginormous string … … 441 465 pickled LogFile (inside the pickled Build) won't be modified.""" 442 466 self.filename = logfilename 443 467 if not os.path.exists(self.getFilename()): 444 self.openfile = open(self.getFilename(), "w")468 self.openfile = gzopen(self.getFilename(), "w") 445 469 self.finished = False 446 470 for channel,text in self.entries: 447 471 self.addEntry(channel, text)
![[Buildbot Logo]](/trac/chrome/site/header-text-transparent.png)