Package buildbot :: Package steps :: Package package :: Package rpm :: Module mock
[frames] | no frames]

Source Code for Module buildbot.steps.package.rpm.mock

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Portions Copyright Buildbot Team Members 
 15  # Portions Copyright Marius Rieder <marius.rieder@durchmesser.ch> 
 16  """ 
 17  Steps and objects related to mock building. 
 18  """ 
 19   
 20  import re 
 21   
 22  from buildbot.steps.shell import ShellCommand 
 23  from buildbot.process import buildstep 
 24  from buildbot import config 
 25   
26 -class MockStateObserver(buildstep.LogLineObserver):
27 _line_re = re.compile(r'^.*State Changed: (.*)$') 28
29 - def outLineReceived(self, line):
30 m = self._line_re.search(line.strip()) 31 if m: 32 state = m.group(1) 33 if not state == 'end': 34 self.step.descriptionSuffix = ["[%s]"%m.group(1)] 35 else: 36 self.step.descriptionSuffix = None 37 self.step.step_status.setText(self.step.describe(False))
38
39 -class Mock(ShellCommand):
40 """Add the mock logfiles and clean them if they already exist. Add support 41 for the root and resultdir parameter of mock.""" 42 43 name = "mock" 44 45 haltOnFailure = 1 46 flunkOnFailure = 1 47 48 mock_logfiles = ['build.log', 'root.log', 'state.log'] 49 50 root = None 51 resultdir = None 52
53 - def __init__(self, 54 root=None, 55 resultdir=None, 56 **kwargs):
57 """ 58 Creates the Mock object. 59 60 @type root: str 61 @param root: the name of the mock buildroot 62 @type resultdir: str 63 @param resultdir: the path of the result dir 64 @type kwargs: dict 65 @param kwargs: All further keyword arguments. 66 """ 67 ShellCommand.__init__(self, **kwargs) 68 if root: 69 self.root = root 70 if resultdir: 71 self.resultdir = resultdir 72 73 if not self.root: 74 config.error("You must specify a mock root") 75 76 77 self.command = ['mock', '--root', self.root] 78 if self.resultdir: 79 self.command += ['--resultdir', self.resultdir]
80
81 - def start(self):
82 """ 83 Try to remove the old mock logs first. 84 """ 85 if self.resultdir: 86 for lname in self.mock_logfiles: 87 self.logfiles[lname] = self.build.path_module.join(self.resultdir, 88 lname) 89 else: 90 for lname in self.mock_logfiles: 91 self.logfiles[lname] = lname 92 self.addLogObserver('state.log', MockStateObserver()) 93 94 cmd = buildstep.RemoteCommand('rmdir', {'dir': 95 map(lambda l: self.build.path_module.join('build', self.logfiles[l]), 96 self.mock_logfiles)}) 97 d = self.runCommand(cmd) 98 def removeDone(cmd): 99 ShellCommand.start(self)
100 d.addCallback(removeDone) 101 d.addErrback(self.failed)
102
103 -class MockBuildSRPM(Mock):
104 """Build a srpm within a mock. Requires a spec file and a sources dir.""" 105 106 name = "mockbuildsrpm" 107 108 description = ["mock buildsrpm"] 109 descriptionDone = ["mock buildsrpm"] 110 111 spec = None 112 sources = '.' 113
114 - def __init__(self, 115 spec=None, 116 sources=None, 117 **kwargs):
118 """ 119 Creates the MockBuildSRPM object. 120 121 @type spec: str 122 @param spec: the path of the specfiles. 123 @type sources: str 124 @param sources: the path of the sources dir. 125 @type kwargs: dict 126 @param kwargs: All further keyword arguments. 127 """ 128 Mock.__init__(self, **kwargs) 129 if spec: 130 self.spec = spec 131 if sources: 132 self.sources = sources 133 134 if not self.spec: 135 config.error("You must specify a spec file") 136 if not self.sources: 137 config.error("You must specify a sources dir") 138 139 self.command += ['--buildsrpm', '--spec', self.spec, 140 '--sources', self.sources]
141
142 - def commandComplete(self, cmd):
143 out = cmd.logs['build.log'].getText() 144 m = re.search(r"Wrote: .*/([^/]*.src.rpm)", out) 145 if m: 146 self.setProperty("srpm", m.group(1), 'MockBuildSRPM')
147
148 -class MockRebuild(Mock):
149 """Rebuild a srpm within a mock. Requires a srpm file.""" 150 151 name = "mock" 152 153 description = ["mock rebuilding srpm"] 154 descriptionDone = ["mock rebuild srpm"] 155 156 srpm = None 157
158 - def __init__(self, srpm=None, **kwargs):
159 """ 160 Creates the MockRebuildRPM object. 161 162 @type srpm: str 163 @param srpm: the path of the srpm file. 164 @type kwargs: dict 165 @param kwargs: All further keyword arguments. 166 """ 167 Mock.__init__(self, **kwargs) 168 if srpm: 169 self.srpm = srpm 170 171 if not self.srpm: 172 config.error("You must specify a srpm") 173 174 self.command += ['--rebuild', self.srpm]
175