[Buildbot-devel] best way to override the createSummary() function in different custom steps
jeff at licquia.org
Tue Feb 19 17:36:12 UTC 2013
On 02/19/2013 02:28 AM, shiny knight wrote:
> I wrote a sub class of ShellCommand, called "MyShell" and I wrote my own createSummary.
> Now I realized that I have some steps that require more specific data, and that perform some other tasks, so I have 2 subclasses of this custom ShellCommand class, called "MySubShell1" and "MySubShell2". Each one has it's own createSummary, to handle the specific needs of that step.
> Now from my understanding, when I call the createSummary in either MySubShell, it will override the one on the parent class. This means that createSummary in either MySubShell will override the function in MyShell.
> Much of the code is very similar, so I was wondering which would be the correct way to handle this situation.
> I use all 3 classes in the same builder, but each one gotta return me a different set of information, so I cannot just use 1 createSummary on the parent class (unless I use a bunch of IF cases, to specify which case I am handing), and as is now, I have 3 classes with 3 createSummary, which share 70% of the same code, and seems to me a big waste of code.
> Any suggestion about how to tackle the problem? Should I just leave it with the 3 createSummary() or there is a more efficient way?
There are a few strategies you can use:
- You can refactor createSummary() for the three classes such that the
shared code is in a separate, unrelated function, which you then call at
the appropriate time.
- You can call MyShell.createSummary(self, ...) from the child class
The right answer will depend on the details of how createSummary() works
for your custom classes.
More information about the devel