Advertisement
Guest User

Untitled

a guest
Apr 28th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. # New subclass of ShellCommand which allows the slave to supply either a html or straight-text log file (or a combination).
  3. # Adds it as an HTML log if and only if the extension of the log file is html, otherwise adds as text.
  4. #   I had this defined in my own configuration file, but perhaps it belongs in the same file as ShellCommand? (steps/shell.py)
  5. #
  6.  
  7. class HTMLOutputShellCommand(ShellCommand):
  8.  
  9.     def setupLogfiles(self, cmd, logfiles):
  10.         for logname,remotefilename in logfiles.items():
  11.             if self.lazylogfiles:
  12.                 # Ask RemoteCommand to watch a logfile, but only add
  13.                 # it when/if we see any data.
  14.                 #
  15.                 # The dummy default argument local_logname is a work-around for
  16.                 # Python name binding; default values are bound by value, but
  17.                 # captured variables in the body are bound by name.
  18.                 callback = lambda cmd_arg, local_logname=logname: self.addHTMLOrTextLog(local_logname)
  19.                 cmd.useLogDelayed(logname, callback, True)
  20.             else:
  21.                 # tell the BuildStepStatus to add a LogFile
  22.                 newlog = self.addHTMLOrTextLog(logname, remotefilename)
  23.                 # and tell the RemoteCommand to feed it
  24.                 cmd.useLog(newlog, True)
  25.  
  26.     def addHTMLOrTextLog(self, logname):
  27.  
  28.             remotefilename = self.logfiles[logname]
  29.             if ( remotefilename.lower().endswith( ".html" ) ):
  30.                 html = ""  # addHTMLLog requires html arg, but in this case, the actual contents are being added from the slave later.
  31.                 newlog = self.addHTMLLog(logname, html)
  32.             else:
  33.                 # tell the BuildStepStatus to add a LogFile
  34.                 newlog = self.addLog(logname)
  35.             return newlog
  36.  
  37. #
  38. # BuildStep.addHTMLLog needs to return the log that it creates.
  39. #
  40.  
  41. diff -r D:\buildbot\buildbot-0.8.8-original\buildbot/process/buildstep.py D:\buildbot\buildbot-0.8.8-py2.7.egg-HTMLHack\buildbot/process/buildstep.py
  42. 752c752
  43. <         self.step_status.addHTMLLog(name, html)
  44. ---
  45. >         loog = self.step_status.addHTMLLog(name, html)
  46. 753a754
  47. >         return loog
  48.  
  49. #
  50. # BuildStepStatus.addHTMLLog needs to return the log that it creates.
  51. #
  52.  
  53. diff -r D:\buildbot\buildbot-0.8.8-original\buildbot/status/buildstep.py D:\buildbot\buildbot-0.8.8-py2.7.egg-HTMLHack\buildbot/status/buildstep.py
  54. 250a251
  55. >         return log
  56.  
  57. #
  58. # HTMLLogFile needs to implement the ILogFile interface, which is also implemented by the LogFile class, but HTMLLogFile
  59. #  does not derive from LogFile.  Without these, I was getting a crash in RemoteCommand.remoteComplete when it called
  60. #  addHeader on the HTMLLogFile, which did not implement addHeader.
  61. #
  62. # I don't actually want the stderr or header to appear in the HTML output which is viewable from the waterfall, which is
  63. #   why I only implemented addStdout, and not addStderr or addHeader.
  64. #
  65.  
  66. diff -r D:\buildbot\buildbot-0.8.8-original\buildbot/status/logfile.py D:\buildbot\buildbot-0.8.8-py2.7.egg-HTMLHack\buildbot/status/logfile.py
  67. 639c639
  68. <     implements(interfaces.IStatusLog)
  69. ---
  70. >     implements(interfaces.IStatusLog, interfaces.ILogFile)
  71. 681a682,690
  72. >
  73. >     def addStdout(self, text):
  74. >         self.html += text
  75. >         pass
  76. >     def addStderr(self, text):
  77. >         pass
  78. >     def addHeader(self, text):
  79. >         pass
  80.  
  81. #
  82. # Patch to add html support in ShellCommand.
  83. #
  84.  
  85. 876,891c877,902
  86. <     def setupLogfiles(self, cmd, logfiles):
  87. <         for logname,remotefilename in logfiles.items():
  88. <             if self.lazylogfiles:
  89. <                 # Ask RemoteCommand to watch a logfile, but only add
  90. <                 # it when/if we see any data.
  91. <                 #
  92. <                 # The dummy default argument local_logname is a work-around for
  93. <                 # Python name binding; default values are bound by value, but
  94. <                 # captured variables in the body are bound by name.
  95. <                 callback = lambda cmd_arg, local_logname=logname: self.addLog(local_logname)
  96. <                 cmd.useLogDelayed(logname, callback, True)
  97. <             else:
  98. <                 # tell the BuildStepStatus to add a LogFile
  99. <                 newlog = self.addLog(logname)
  100. <                 # and tell the RemoteCommand to feed it
  101. <                 cmd.useLog(newlog, True)
  102. ---
  103. >     def setupLogfiles(self, cmd, logfiles):
  104. >         for logname,remotefilename in logfiles.items():
  105. >             if self.lazylogfiles:
  106. >                 # Ask RemoteCommand to watch a logfile, but only add
  107. >                 # it when/if we see any data.
  108. >                 #
  109. >                 # The dummy default argument local_logname is a work-around for
  110. >                 # Python name binding; default values are bound by value, but
  111. >                 # captured variables in the body are bound by name.
  112. >                 callback = lambda cmd_arg, local_logname=logname: self.addHTMLOrTextLog(local_logname)
  113. >                 cmd.useLogDelayed(logname, callback, True)
  114. >             else:
  115. >                 # tell the BuildStepStatus to add a LogFile
  116. >                 newlog = self.addHTMLOrTextLog(logname, remotefilename)
  117. >                 # and tell the RemoteCommand to feed it
  118. >                 cmd.useLog(newlog, True)
  119. >
  120. >     def addHTMLOrTextLog(self, logname):
  121. >             remotefilename = self.logfiles[logname]
  122. >             if ( remotefilename.lower().endswith( ".html" ) ):
  123. >                 html = ""  # addHTMLLog requires html arg, but in this case, the actual contents are being added from the slave later.
  124. >                 newlog = self.addHTMLLog(logname, html)
  125. >             else:
  126. >                 # tell the BuildStepStatus to add a LogFile
  127. >                 newlog = self.addLog(logname)
  128. >             return newlog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement