1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 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   
 27      _line_re = re.compile(r'^.*State Changed: (.*)$') 
 28   
  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   
100          d.addCallback(removeDone) 
101          d.addErrback(self.failed) 
 102   
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   
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   
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