Package buildbot :: Package changes :: Module pb
[frames] | no frames]

Source Code for Module buildbot.changes.pb

  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  # Copyright Buildbot Team Members 
 15   
 16   
 17  from twisted.python import log 
 18  from twisted.internet import defer 
 19   
 20  from buildbot.pbutil import NewCredPerspective 
 21  from buildbot.changes import base, changes 
 22   
23 -class ChangePerspective(NewCredPerspective):
24
25 - def __init__(self, changemaster, prefix):
26 self.changemaster = changemaster 27 self.prefix = prefix
28
29 - def attached(self, mind):
30 return self
31 - def detached(self, mind):
32 pass
33
34 - def perspective_addChange(self, changedict):
35 log.msg("perspective_addChange called") 36 pathnames = [] 37 for path in changedict['files']: 38 if self.prefix: 39 if not path.startswith(self.prefix): 40 # this file does not start with the prefix, so ignore it 41 continue 42 path = path[len(self.prefix):] 43 pathnames.append(path) 44 45 if pathnames: 46 change = changes.Change(who=changedict['who'], 47 files=pathnames, 48 comments=changedict['comments'], 49 branch=changedict.get('branch'), 50 revision=changedict.get('revision'), 51 revlink=changedict.get('revlink', ''), 52 category=changedict.get('category'), 53 when=changedict.get('when'), 54 properties=changedict.get('properties', {}), 55 repository=changedict.get('repository', '') or '', 56 project=changedict.get('project', '') or '', 57 ) 58 self.changemaster.addChange(change)
59
60 -class PBChangeSource(base.ChangeSource):
61 compare_attrs = ["user", "passwd", "port", "prefix", "port"] 62
63 - def __init__(self, user="change", passwd="changepw", port=None, 64 prefix=None, sep=None):
65 """I listen on a TCP port for Changes from 'buildbot sendchange'. 66 67 I am a ChangeSource which will accept Changes from a remote source. I 68 share a TCP listening port with the buildslaves. 69 70 The 'buildbot sendchange' command, the contrib/svn_buildbot.py tool, 71 and the contrib/bzr_buildbot.py tool know how to send changes to me. 72 73 @type prefix: string (or None) 74 @param prefix: if set, I will ignore any filenames that do not start 75 with this string. Moreover I will remove this string 76 from all filenames before creating the Change object 77 and delivering it to the Schedulers. This is useful 78 for changes coming from version control systems that 79 represent branches as parent directories within the 80 repository (like SVN and Perforce). Use a prefix of 81 'trunk/' or 'project/branches/foobranch/' to only 82 follow one branch and to get correct tree-relative 83 filenames. 84 85 @param sep: DEPRECATED (with an axe). sep= was removed in 86 buildbot-0.7.4 . Instead of using it, you should use 87 prefix= with a trailing directory separator. This 88 docstring (and the better-than-nothing error message 89 which occurs when you use it) will be removed in 0.7.5 . 90 91 @param port: strport to use, or None to use the master's slavePortnum 92 """ 93 94 # sep= was removed in 0.7.4 . This more-helpful-than-nothing error 95 # message will be removed in 0.7.5 . 96 assert sep is None, "prefix= is now a complete string, do not use sep=" 97 98 self.user = user 99 self.passwd = passwd 100 self.port = port 101 self.prefix = prefix 102 self.registration = None
103
104 - def describe(self):
105 # TODO: when the dispatcher is fixed, report the specific port 106 #d = "PB listener on port %d" % self.port 107 d = "PBChangeSource listener on all-purpose slaveport" 108 if self.prefix is not None: 109 d += " (prefix '%s')" % self.prefix 110 return d
111
112 - def startService(self):
113 base.ChangeSource.startService(self) 114 master = self.parent.parent 115 port = self.port 116 if not port: 117 port = master.slavePortnum 118 self.registration = master.pbmanager.register( 119 port, self.user, self.passwd, 120 self.getPerspective)
121
122 - def stopService(self):
123 d = defer.maybeDeferred(base.ChangeSource.stopService, self) 124 def unreg(_): 125 if self.registration: 126 return self.registration.unregister()
127 d.addCallback(unreg) 128 return d
129
130 - def getPerspective(self, mind, username):
131 assert username == self.user 132 return ChangePerspective(self.parent, self.prefix)
133