[Buildbot-commits] [Buildbot] #371: ShellCommand argument "logfiles" does not properly work for HTML log files
    Buildbot 
    nobody at buildbot.net
       
    Thu Mar 31 13:43:55 UTC 2011
    
    
  
#371: ShellCommand argument "logfiles" does not properly work for HTML log files
------------------------+--------------------
Reporter:  cli          |       Owner:
    Type:  enhancement  |      Status:  new
Priority:  major        |   Milestone:  0.8.+
 Version:  0.7.9        |  Resolution:
Keywords:               |
------------------------+--------------------
Comment (by lantictac):
 Here's the hack we're using locally here. Be warned it's ugly as hell and
 not ready for prime time but it does the job for us. Far more prefereable
 would be a MIME type associated with the log file.
 In logs.py...
 {{{
 # /builders/$builder/builds/$buildnum/steps/$stepname/logs/$logname
 class TextLog(Resource):
     # a new instance of this Resource is created for each client who views
     # it, so we can afford to track the request in the Resource.
     implements(IHTMLLog)
     asText = False
     asHTML = False
     subscribed = False
     def __init__(self, original):
         Resource.__init__(self)
         self.original = original
         # WPW: Awful, awful hack to detect HTML contents
         if original.getText().startswith('<html'):      # Original is a
 status.builder.LogFile instance
             self.asHTML = True;
     def getChild(self, path, req):
         if path == "text":
             self.asText = True
             return self
         elif path == "html":
             self.asHTML = True
             return self
         return HtmlResource.getChild(self, path, req)
     def content(self, entries):
         html_entries = []
         text_data = ''
         for type, entry in entries:
             if type >= len(builder.ChunkTypes) or type < 0:
                 # non-std channel, don't display
                 continue
             is_header = type == builder.HEADER
             if not self.asText and not self.asHTML:
                 # jinja only works with unicode, or pure ascii, so assume
 utf-8 in logs
                 if not isinstance(entry, unicode):
                     entry = unicode(entry, 'utf-8', 'replace')
                 html_entries.append(dict(type = builder.ChunkTypes[type],
                                          text = entry,
                                          is_header = is_header))
             elif not is_header:
                 text_data += entry
         if self.asText or self.asHTML:
             return text_data
         else:
             return self.template.module.chunks(html_entries)
     def render_HEAD(self, req):
         self._setContentType(req)
         # vague approximation, ignores markup
         req.setHeader("content-length", self.original.length)
         return ''
     def render_GET(self, req):
         self._setContentType(req)
         self.req = req
         if not self.asText and not self.asHTML:
             self.template =
 req.site.buildbot_service.templates.get_template("logs.html")
             data = self.template.module.page_header(
                     title = "Log File contents",
                     texturl = req.childLink("text"),
                     path_to_root = path_to_root(req))
             data = data.encode('utf-8')
             req.write(data)
         self.original.subscribeConsumer(ChunkConsumer(req, self))
         return server.NOT_DONE_YET
     def _setContentType(self, req):
         if self.asText:
             req.setHeader("content-type", "text/plain; charset=utf-8")
         else:
             req.setHeader("content-type", "text/html; charset=utf-8")
     def finished(self):
         if not self.req:
             return
         try:
             if not self.asText and not self.asHTML:
                 data = self.template.module.page_footer()
                 data = data.encode('utf-8')
                 self.req.write(data)
             self.req.finish()
         except pb.DeadReferenceError:
             pass
         # break the cycle, the Request's .notifications list includes the
         # Deferred (from req.notifyFinish) that's pointing at us.
         self.req = None
         # release template
         self.template = None
 components.registerAdapter(TextLog, interfaces.IStatusLog, IHTMLLog)
 }}}
-- 
Ticket URL: <http://trac.buildbot.net/ticket/371#comment:5>
Buildbot <http://buildbot.net/>
Buildbot: build/test automation
    
    
More information about the Commits
mailing list