Ticket #26: buildbot-gzip2.patch
| File buildbot-gzip2.patch, 3.7 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 46 47 class PossiblyGzippedFile(object): 48 49 """Wraps a file, gzipped if possible, conforming a little more closely 50 to the standard python file interface than gzip.GzipFile does. 51 """ 52 53 def __init__(self, path, *args): 54 self.__gzipped = True 55 if args: 56 mode = args[0] 57 else: 58 mode = 'r' 59 self.__mode = mode 60 f = gzip.open(path, *args) 61 if mode.startswith('w'): 62 # we're wiping out any existing file, so, unconditionally gzip it. 63 self.__file = f 64 return 65 try: 66 # See if the existing file is really gzipped. 67 f.seek(1) 68 f.seek(0) 69 self.__file = f 70 return 71 except IOError: 72 del f 73 # We have an existing, non-gzipped file. 74 self.__file = open(path, *args) 75 self.__gzipped = False 76 77 def seek(self, offset, whence=0): 78 # XXX written against python 2.4. 79 # I don't have 2.5 handy; does its gzip module support the 80 # whence argument? 81 if self.__gzipped: 82 if whence == 2: 83 offset += self.__file.size 84 elif whence == 1: 85 offset += self.__file.tell() 86 self.__file.seek(max(0, offset)) 87 else: 88 self.__file.seek(offset, whence) 89 90 def __getattr__(self, attr): 91 if attr in self.__dict__: 92 return self.__dict__[attr] 93 else: 94 return getattr(self.__file, attr) 95 96 97 def gzopen(path, *args): 98 return PossiblyGzippedFile(path, *args) 99 100 43 101 class LogFileScanner(basic.NetstringReceiver): 44 102 def __init__(self, chunk_cb, channels=[]): 45 103 self.chunk_cb = chunk_cb … … 50 108 if not self.channels or (channel in self.channels): 51 109 self.chunk_cb((channel, line[1:])) 52 110 111 53 112 class LogFileProducer: 54 113 """What's the plan? 55 114 … … 227 286 # is out of date, and we're overlapping with earlier builds now. 228 287 # Warn about it, but then overwrite the old pickle file 229 288 log.msg("Warning: Overwriting old serialized Build at %s" % fn) 230 self.openfile = open(fn, "w+")289 self.openfile = gzopen(fn, "w+") 231 290 self.runEntries = [] 232 291 self.watchers = [] 233 292 self.finishedWatchers = [] … … 260 319 # don't close it! 261 320 return self.openfile 262 321 # otherwise they get their own read-only handle 263 return open(self.getFilename(), "r")322 return gzopen(self.getFilename(), "r") 264 323 265 324 def getText(self): 266 325 # this produces one ginormous string … … 441 500 pickled LogFile (inside the pickled Build) won't be modified.""" 442 501 self.filename = logfilename 443 502 if not os.path.exists(self.getFilename()): 444 self.openfile = open(self.getFilename(), "w")503 self.openfile = gzopen(self.getFilename(), "w") 445 504 self.finished = False 446 505 for channel,text in self.entries: 447 506 self.addEntry(channel, text)
![[Buildbot Logo]](/trac/chrome/site/header-text-transparent.png)