Skip to content

Commit

Permalink
Update RpmBuild
Browse files Browse the repository at this point in the history
* Added doc string documentation
* check for specfile during __init__
* createSummary
   * use log.getText instead of log.readlines, STDERR is needed as well.
   * Check with startswith instead of in in createSummary. '   ' is to
     comming within lines to match as error.
   * Don't add a line multiple times to the log if more the one prefix
     match the line. (Should not happen anyway, was much more likly to
     happen befor with the 'in' compare.)
  • Loading branch information
jiuka committed Jun 5, 2012
1 parent 27d4109 commit a4cc7cc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
47 changes: 41 additions & 6 deletions master/buildbot/steps/package/rpm/rpmbuild.py
Expand Up @@ -20,8 +20,13 @@
import os
from buildbot.steps.shell import ShellCommand
from buildbot.process import buildstep
from buildbot import config

class RpmBuild(ShellCommand):
"""
RpmBuild build step.
"""

name = "rpmbuilder"
haltOnFailure = 1
flunkOnFailure = 1
Expand All @@ -40,6 +45,30 @@ def __init__(self,
autoRelease=False,
vcsRevision=False,
**kwargs):
"""
Create the RpmBuild object.
@type specfile: str
@param specfile: location of the specfile to build
@type topdir: str
@param topdir: define the _topdir rpm parameter
@type builddir: str
@param builddir: define the _builddir rpm parameter
@type rpmdir: str
@param rpmdir: define the _rpmdir rpm parameter
@type sourcedir: str
@param sourcedir: define the _sourcedir rpm parameter
@type specdir: str
@param specdir: define the _specdir rpm parameter
@type srcrpmdir: str
@param srcrpmdir: define the _srcrpmdir rpm parameter
@type dist: str
@param dist: define the dist string.
@type autoRelease: boolean
@param autoRelease: Use auto incrementing release numbers.
@type vcsRevision: boolean
@param vcsRevision: Use vcs version number as revision number.
"""
ShellCommand.__init__(self, **kwargs)
self.rpmbuild = (
'rpmbuild --define "_topdir %s" --define "_builddir %s"'
Expand All @@ -51,6 +80,9 @@ def __init__(self,
self.autoRelease = autoRelease
self.vcsRevision = vcsRevision

if not self.specfile:
config.error("You must specify a specfile")

def start(self):
if self.autoRelease:
relfile = '%s.release' % (
Expand Down Expand Up @@ -80,20 +112,23 @@ def start(self):
self.startCommand(cmd)

def createSummary(self, log):
rpm_prefixes = ['Provides:', 'Requires(rpmlib):', 'Requires:',
rpm_prefixes = ['Provides:', 'Requires(', 'Requires:',
'Checking for unpackaged', 'Wrote:',
'Executing(%', '+ ']
'Executing(%', '+ ', 'Processing files:']
rpm_err_pfx = [' ', 'RPM build errors:', 'error: ']

rpmcmdlog = []
rpmerrors = []

for line in log.readlines():
for line in log.getText().splitlines(True):
for pfx in rpm_prefixes:
if pfx in line:
if line.startswith(pfx):
rpmcmdlog.append(line)
break
for err in rpm_err_pfx:
if err in line:
if line.startswith(err):
rpmerrors.append(line)
break
self.addCompleteLog('RPM Command Log', "".join(rpmcmdlog))
self.addCompleteLog('RPM Errors', "".join(rpmerrors))
if rpmerrors:
self.addCompleteLog('RPM Errors', "".join(rpmerrors))
5 changes: 5 additions & 0 deletions master/buildbot/test/unit/test_steps_package_rpm_rpmbuild.py
Expand Up @@ -18,6 +18,7 @@
from buildbot.test.fake.remotecommand import ExpectShell
from buildbot.test.util import steps
from twisted.trial import unittest
from buildbot import config

class RpmBuild(steps.BuildStepMixin, unittest.TestCase):

Expand All @@ -27,6 +28,10 @@ def setUp(self):
def tearDown(self):
return self.tearDownBuildStep()

def test_no_specfile(self):
self.assertRaises(config.ConfigErrors, lambda :
rpmbuild.RpmBuild())

def test_success(self):
self.setupStep(rpmbuild.RpmBuild(specfile="foo.spec", dist=".el6"))
self.expectCommands(
Expand Down

0 comments on commit a4cc7cc

Please sign in to comment.