update addLogObserver example to use 0.7.5 buildbot.steps.* names
[buildbot.git] / buildbot / steps / python.py
blob1d7de9f77ea54a5cd03f21fe318e16d5192d2210
2 from buildbot.status.builder import SUCCESS, FAILURE, WARNINGS
3 from buildbot.steps.shell import ShellCommand
5 try:
6 import cStringIO
7 StringIO = cStringIO.StringIO
8 except ImportError:
9 from StringIO import StringIO
12 class BuildEPYDoc(ShellCommand):
13 name = "epydoc"
14 command = ["make", "epydocs"]
15 description = ["building", "epydocs"]
16 descriptionDone = ["epydoc"]
18 def createSummary(self, log):
19 import_errors = 0
20 warnings = 0
21 errors = 0
23 for line in StringIO(log.getText()):
24 if line.startswith("Error importing "):
25 import_errors += 1
26 if line.find("Warning: ") != -1:
27 warnings += 1
28 if line.find("Error: ") != -1:
29 errors += 1
31 self.descriptionDone = self.descriptionDone[:]
32 if import_errors:
33 self.descriptionDone.append("ierr=%d" % import_errors)
34 if warnings:
35 self.descriptionDone.append("warn=%d" % warnings)
36 if errors:
37 self.descriptionDone.append("err=%d" % errors)
39 self.import_errors = import_errors
40 self.warnings = warnings
41 self.errors = errors
43 def evaluateCommand(self, cmd):
44 if cmd.rc != 0:
45 return FAILURE
46 if self.warnings or self.errors:
47 return WARNINGS
48 return SUCCESS
51 class PyFlakes(ShellCommand):
52 name = "pyflakes"
53 command = ["make", "pyflakes"]
54 description = ["running", "pyflakes"]
55 descriptionDone = ["pyflakes"]
56 flunkOnFailure = False
57 flunkingIssues = ["undefined"] # any pyflakes lines like this cause FAILURE
59 MESSAGES = ("unused", "undefined", "redefs", "import*", "misc")
61 def createSummary(self, log):
62 counts = {}
63 summaries = {}
64 for m in self.MESSAGES:
65 counts[m] = 0
66 summaries[m] = []
68 first = True
69 for line in StringIO(log.getText()).readlines():
70 # the first few lines might contain echoed commands from a 'make
71 # pyflakes' step, so don't count these as warnings. Stop ignoring
72 # the initial lines as soon as we see one with a colon.
73 if first:
74 if line.find(":") != -1:
75 # there's the colon, this is the first real line
76 first = False
77 # fall through and parse the line
78 else:
79 # skip this line, keep skipping non-colon lines
80 continue
81 if line.find("imported but unused") != -1:
82 m = "unused"
83 elif line.find("*' used; unable to detect undefined names") != -1:
84 m = "import*"
85 elif line.find("undefined name") != -1:
86 m = "undefined"
87 elif line.find("redefinition of unused") != -1:
88 m = "redefs"
89 else:
90 m = "misc"
91 summaries[m].append(line)
92 counts[m] += 1
94 self.descriptionDone = self.descriptionDone[:]
95 for m in self.MESSAGES:
96 if counts[m]:
97 self.descriptionDone.append("%s=%d" % (m, counts[m]))
98 self.addCompleteLog(m, "".join(summaries[m]))
99 self.setProperty("pyflakes-%s" % m, counts[m])
100 self.setProperty("pyflakes-total", sum(counts.values()))
103 def evaluateCommand(self, cmd):
104 if cmd.rc != 0:
105 return FAILURE
106 for m in self.flunkingIssues:
107 if self.getProperty("pyflakes-%s" % m):
108 return FAILURE
109 if self.getProperty("pyflakes-total"):
110 return WARNINGS
111 return SUCCESS