| 250 | | class Compile(ShellCommand): |
| | 250 | class WarningCountingShellCommand(ShellCommand): |
| | 251 | warnCount = 0 |
| | 252 | |
| | 253 | def __init__(self, workdir, |
| | 254 | description=None, descriptionDone=None, |
| | 255 | command=None, |
| | 256 | **kwargs): |
| | 257 | # See if we've been given a regular expression to use to match |
| | 258 | # warngins. If not, use a default that assumes any line with "warning" |
| | 259 | # present is a warning. This may lead to false positives in some cases. |
| | 260 | if kwargs.has_key('warningPattern'): |
| | 261 | warningPattern = kwargs['warningPattern'] |
| | 262 | del kwargs['warningPattern'] |
| | 263 | else: |
| | 264 | warningPattern = '.*warning[: ].*' |
| | 265 | |
| | 266 | # Now compile a regular expression from whichever warning pattern we're |
| | 267 | # using |
| | 268 | if "" != warningPattern: |
| | 269 | self.warningRegExp = re.compile(warningPattern) |
| | 270 | else: |
| | 271 | self.warningRegExp = None |
| | 272 | |
| | 273 | # And upcall to let the base class do its work |
| | 274 | ShellCommand.__init__(self, workdir, |
| | 275 | description, descriptionDone, |
| | 276 | command, |
| | 277 | **kwargs) |
| | 278 | |
| | 279 | def createSummary(self, log): |
| | 280 | self.warnCount = 0 |
| | 281 | |
| | 282 | # Check if each line in the output from this command matched out |
| | 283 | # warnings regular expressions. If did, bump the warnings count and |
| | 284 | # add the line to the collection of lines with warnings |
| | 285 | if None != self.warningRegExp: |
| | 286 | warnings = [] |
| | 287 | for line in log.getText().split("\n"): |
| | 288 | if self.warningRegExp.match(line): |
| | 289 | warnings.append(line) |
| | 290 | self.warnCount += 1 |
| | 291 | |
| | 292 | # If there were any warnings, make the log if lines with warngins |
| | 293 | # available |
| | 294 | if self.warnCount: |
| | 295 | self.addCompleteLog("warnings", "".join(warnings)) |
| | 296 | |
| | 297 | def evaluateCommand(self, cmd): |
| | 298 | if cmd.rc != 0: |
| | 299 | return FAILURE |
| | 300 | if self.warnCount: |
| | 301 | return WARNINGS |
| | 302 | return SUCCESS |
| | 303 | |
| | 304 | |
| | 305 | class Compile(WarningCountingShellCommand): |