Package buildslave :: Package commands :: Module bzr
[frames] | no frames]

Source Code for Module buildslave.commands.bzr

  1  import os 
  2   
  3  from twisted.python import log 
  4  from twisted.internet import defer 
  5   
  6  from buildslave.commands.base import SourceBaseCommand 
  7  from buildslave import runprocess 
  8  from buildslave.commands import utils 
  9   
 10   
11 -class Bzr(SourceBaseCommand):
12 """bzr-specific VC operation. In addition to the arguments 13 handled by SourceBaseCommand, this command reads the following keys: 14 15 ['repourl'] (required): the Bzr repository string 16 ['forceSharedRepo']: force this to a shared repo 17 """ 18 19 header = "bzr operation" 20
21 - def setup(self, args):
22 SourceBaseCommand.setup(self, args) 23 self.repourl = args['repourl'] 24 self.sourcedata = "%s\n" % self.repourl 25 self.revision = self.args.get('revision') 26 self.forceSharedRepo = args.get('forceSharedRepo')
27
28 - def sourcedirIsUpdateable(self):
29 # checking out a specific revision requires a full 'bzr checkout' 30 return (not self.revision and 31 not self.sourcedirIsPatched() and 32 os.path.isdir(os.path.join(self.builder.basedir, 33 self.srcdir, ".bzr")))
34
35 - def start(self):
36 def cont(res): 37 # Continue with start() method in superclass. 38 return SourceBaseCommand.start(self)
39 40 if self.forceSharedRepo: 41 d = self.doForceSharedRepo(); 42 d.addCallback(cont) 43 return d 44 else: 45 return cont(None)
46
47 - def doVCUpdate(self):
48 bzr = self.getCommand('bzr') 49 assert not self.revision 50 # update: possible for mode in ('copy', 'update') 51 srcdir = os.path.join(self.builder.basedir, self.srcdir) 52 command = [bzr, 'update'] 53 c = runprocess.RunProcess(self.builder, command, srcdir, 54 sendRC=False, timeout=self.timeout, 55 maxTime=self.maxTime, usePTY=False) 56 self.command = c 57 return c.start()
58
59 - def doVCFull(self):
60 bzr = self.getCommand('bzr') 61 62 # checkout or export 63 d = self.builder.basedir 64 if self.mode == "export": 65 # exporting in bzr requires a separate directory 66 return self.doVCExport() 67 # originally I added --lightweight here, but then 'bzr revno' is 68 # wrong. The revno reported in 'bzr version-info' is correct, 69 # however. Maybe this is a bzr bug? 70 # 71 # In addition, you cannot perform a 'bzr update' on a repo pulled 72 # from an HTTP repository that used 'bzr checkout --lightweight'. You 73 # get a "ERROR: Cannot lock: transport is read only" when you try. 74 # 75 # So I won't bother using --lightweight for now. 76 77 command = [bzr, 'checkout'] 78 if self.revision: 79 command.append('--revision') 80 command.append(str(self.revision)) 81 command.append(self.repourl) 82 command.append(self.srcdir) 83 84 c = runprocess.RunProcess(self.builder, command, d, 85 sendRC=False, timeout=self.timeout, 86 maxTime=self.maxTime, usePTY=False) 87 self.command = c 88 d = c.start() 89 return d
90
91 - def doVCExport(self):
92 bzr = self.getCommand('bzr') 93 tmpdir = os.path.join(self.builder.basedir, "export-temp") 94 srcdir = os.path.join(self.builder.basedir, self.srcdir) 95 command = [bzr, 'checkout', '--lightweight'] 96 if self.revision: 97 command.append('--revision') 98 command.append(str(self.revision)) 99 command.append(self.repourl) 100 command.append(tmpdir) 101 c = runprocess.RunProcess(self.builder, command, self.builder.basedir, 102 sendRC=False, timeout=self.timeout, 103 maxTime=self.maxTime, usePTY=False) 104 self.command = c 105 d = c.start() 106 def _export(res): 107 command = [bzr, 'export', srcdir] 108 c = runprocess.RunProcess(self.builder, command, tmpdir, 109 sendRC=False, timeout=self.timeout, 110 maxTime=self.maxTime, usePTY=False) 111 self.command = c 112 return c.start()
113 d.addCallback(_export) 114 return d 115
116 - def doForceSharedRepo(self):
117 bzr = self.getCommand('bzr') 118 119 # Don't send stderr. When there is no shared repo, this might confuse 120 # users, as they will see a bzr error message. But having no shared 121 # repo is not an error, just an indication that we need to make one. 122 c = runprocess.RunProcess(self.builder, [bzr, 'info', '.'], 123 self.builder.basedir, 124 sendStderr=False, sendRC=False, usePTY=False) 125 d = c.start() 126 def afterCheckSharedRepo(res): 127 if type(res) is int and res != 0: 128 log.msg("No shared repo found, creating it") 129 # bzr info fails, try to create shared repo. 130 c = runprocess.RunProcess(self.builder, [bzr, 'init-repo', '.'], 131 self.builder.basedir, 132 sendRC=False, usePTY=False) 133 self.command = c 134 return c.start() 135 else: 136 return defer.succeed(res)
137 d.addCallback(afterCheckSharedRepo) 138 return d 139
140 - def get_revision_number(self, out):
141 # it feels like 'bzr revno' sometimes gives different results than 142 # the 'revno:' line from 'bzr version-info', and the one from 143 # version-info is more likely to be correct. 144 for line in out.split("\n"): 145 colon = line.find(":") 146 if colon != -1: 147 key, value = line[:colon], line[colon+2:] 148 if key == "revno": 149 return int(value) 150 raise ValueError("unable to find revno: in bzr output: '%s'" % out)
151
152 - def parseGotRevision(self):
153 bzr = self.getCommand('bzr') 154 command = [bzr, "version-info"] 155 c = runprocess.RunProcess(self.builder, command, 156 os.path.join(self.builder.basedir, self.srcdir), 157 environ=self.env, 158 sendStdout=False, sendStderr=False, sendRC=False, 159 keepStdout=True, usePTY=False) 160 d = c.start() 161 def _parse(res): 162 try: 163 return self.get_revision_number(c.stdout) 164 except ValueError: 165 msg =("Bzr.parseGotRevision unable to parse output " 166 "of bzr version-info: '%s'" % c.stdout.strip()) 167 log.msg(msg) 168 self.sendStatus({'header': msg + "\n"}) 169 return None
170 d.addCallback(_parse) 171 return d 172