Package buildbot :: Package steps :: Package package :: Package deb :: Module pbuilder
[frames] | no frames]

Source Code for Module buildbot.steps.package.deb.pbuilder

  1  # This program 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 pbuilder 
 18  """ 
 19   
 20  import re 
 21  import stat 
 22  import time 
 23   
 24  from twisted.python import log 
 25   
 26  from buildbot.steps.shell import WarningCountingShellCommand 
 27  from buildbot.process import buildstep 
 28  from buildbot.process.buildstep import FAILURE 
 29  from buildbot import config 
 30   
31 -class DebPbuilder(WarningCountingShellCommand):
32 """Build a debian package with pbuilder inside of a chroot.""" 33 name = "pbuilder" 34 35 haltOnFailure = 1 36 flunkOnFailure = 1 37 description = ["pdebuilding"] 38 descriptionDone = ["pdebuild"] 39 40 warningPattern = ".*(warning[: ]|\sW: ).*" 41 42 architecture = None 43 distribution = 'stable' 44 basetgz = "/var/cache/pbuilder/%(distribution)s-%(architecture)s-buildbot.tgz" 45 mirror = "http://cdn.debian.net/debian/" 46 extrapackages = [] 47 keyring = None 48 components = None 49 50 maxAge = 60*60*24*7 51 pbuilder = '/usr/sbin/pbuilder' 52 baseOption = '--basetgz' 53
54 - def __init__(self, 55 architecture=None, 56 distribution=None, 57 basetgz=None, 58 mirror=None, 59 extrapackages=None, 60 keyring=None, 61 components=None, 62 **kwargs):
63 """ 64 Creates the DebPbuilder object. 65 66 @type architecture: str 67 @param architecture: the name of the architecture to build 68 @type distribution: str 69 @param distribution: the man of the distribution to use 70 @type basetgz: str 71 @param basetgz: the path or path template of the basetgz 72 @type mirror: str 73 @param mirror: the mirror for building basetgz 74 @type extrapackages: list 75 @param extrapackages: adds packages specified to buildroot 76 @type keyring: str 77 @param keyring: keyring file to use for verification 78 @type components: str 79 @param components: components to use for chroot creation 80 @type kwargs: dict 81 @param kwargs: All further keyword arguments. 82 """ 83 WarningCountingShellCommand.__init__(self, **kwargs) 84 85 if architecture: 86 self.architecture = architecture 87 if distribution: 88 self.distribution = distribution 89 if mirror: 90 self.mirror = mirror 91 if extrapackages: 92 self.extrapackages = extrapackages 93 if keyring: 94 self.keyring = keyring 95 if components: 96 self.components = components 97 98 if self.architecture: 99 kwargs['architecture'] = self.architecture 100 else: 101 kwargs['architecture'] = 'local' 102 kwargs['distribution'] = self.distribution 103 104 if basetgz: 105 self.basetgz = basetgz % kwargs 106 else: 107 self.basetgz = self.basetgz % kwargs 108 109 if not self.distribution: 110 config.error("You must specify a distribution.") 111 112 self.command = ['pdebuild', '--buildresult', '.', '--pbuilder', self.pbuilder] 113 if self.architecture: 114 self.command += ['--architecture', self.architecture] 115 self.command += ['--', '--buildresult', '.', self.baseOption, self.basetgz] 116 if self.extrapackages: 117 self.command += ['--extrapackages', " ".join(self.extrapackages)] 118 119 self.suppressions.append((None, re.compile("\.pbuilderrc does not exist"), None, None))
120 121 # Check for Basetgz
122 - def start(self):
123 cmd = buildstep.RemoteCommand('stat', {'file': self.basetgz}) 124 d = self.runCommand(cmd) 125 d.addCallback(lambda res: self.checkBasetgz(cmd)) 126 d.addErrback(self.failed) 127 return d
128
129 - def checkBasetgz(self, cmd):
130 if cmd.rc != 0: 131 log.msg("basetgz not found, initializing it.") 132 133 command = ['sudo', self.pbuilder, '--create', self.baseOption, 134 self.basetgz, '--distribution', self.distribution, 135 '--mirror', self.mirror] 136 if self.architecture: 137 command += ['--architecture', self.architecture] 138 if self.extrapackages: 139 command += ['--extrapackages', " ".join(self.extrapackages)] 140 if self.keyring: 141 command += ['--debootstrapopts', "--keyring=%s" % self.keyring] 142 if self.components: 143 command += ['--components', self.components] 144 145 cmd = buildstep.RemoteShellCommand(self.getWorkdir(), command) 146 147 stdio_log = stdio_log = self.addLog("pbuilder") 148 cmd.useLog(stdio_log, True, "stdio") 149 d = self.runCommand(cmd) 150 self.step_status.setText(["PBuilder create."]) 151 d.addCallback(lambda res: self.startBuild(cmd)) 152 return d 153 s = cmd.updates["stat"][-1] 154 if stat.S_ISREG(s[stat.ST_MODE]): 155 log.msg("%s found." % self.basetgz) 156 age = time.time() - s[stat.ST_MTIME] 157 if age >= self.maxAge: 158 log.msg("basetgz outdated, updating") 159 command = ['sudo', self.pbuilder, '--update', 160 self.baseOption, self.basetgz] 161 162 cmd = buildstep.RemoteShellCommand(self.getWorkdir(), command) 163 stdio_log = stdio_log = self.addLog("pbuilder") 164 cmd.useLog(stdio_log, True, "stdio") 165 d = self.runCommand(cmd) 166 self.step_status.setText(["PBuilder update."]) 167 d.addCallback(lambda res: self.startBuild(cmd)) 168 return d 169 return self.startBuild(cmd) 170 else: 171 log.msg("%s is not a file." % self.basetgz) 172 self.finished(FAILURE)
173
174 - def startBuild(self, dummy):
176
177 - def commandComplete(self, cmd):
178 out = cmd.logs['stdio'].getText() 179 m = re.search(r"dpkg-genchanges >\.\./(.+\.changes)", out) 180 if m: 181 self.setProperty("deb-changes", m.group(1), "DebPbuilder")
182
183 -class DebCowbuilder(DebPbuilder):
184 """Build a debian package with cowbuilder inside of a chroot.""" 185 name = "cowbuilder" 186 187 description = ["pdebuilding"] 188 descriptionDone = ["pdebuild"] 189 190 basetgz = "/var/cache/pbuilder/%(distribution)s-%(architecture)s-buildbot.cow/" 191 192 pbuilder = '/usr/sbin/cowbuilder' 193 baseOption = '--basepath'
194
195 -class UbuPbuilder(DebPbuilder):
196 """Build a Ubuntu package with pbuilder inside of a chroot.""" 197 distribution = None 198 mirror = "http://archive.ubuntu.com/ubuntu/" 199 200 components = "main universe"
201
202 -class UbuCowbuilder(DebCowbuilder):
203 """Build a Ubuntu package with cowbuilder inside of a chroot.""" 204 distribution = None 205 mirror = "http://archive.ubuntu.com/ubuntu/" 206 207 components = "main universe"
208