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

Source Code for Module buildbot.changes.pb

  1  # -*- test-case-name: buildbot.test.test_changes -*- 
  2   
  3  from twisted.python import log 
  4   
  5  from buildbot.pbutil import NewCredPerspective 
  6  from buildbot.changes import base, changes 
  7   
8 -class ChangePerspective(NewCredPerspective):
9
10 - def __init__(self, changemaster, prefix):
11 self.changemaster = changemaster 12 self.prefix = prefix
13
14 - def attached(self, mind):
15 return self
16 - def detached(self, mind):
17 pass
18
19 - def perspective_addChange(self, changedict):
20 log.msg("perspective_addChange called") 21 pathnames = [] 22 prefixpaths = None 23 for path in changedict['files']: 24 if self.prefix: 25 if not path.startswith(self.prefix): 26 # this file does not start with the prefix, so ignore it 27 continue 28 path = path[len(self.prefix):] 29 pathnames.append(path) 30 31 if pathnames: 32 change = changes.Change(changedict['who'], 33 pathnames, 34 changedict['comments'], 35 branch=changedict.get('branch'), 36 revision=changedict.get('revision'), 37 category=changedict.get('category'), 38 when=changedict.get('when'), 39 ) 40 self.changemaster.addChange(change)
41
42 -class PBChangeSource(base.ChangeSource):
43 compare_attrs = ["user", "passwd", "port", "prefix"] 44
45 - def __init__(self, user="change", passwd="changepw", port=None, 46 prefix=None, sep=None):
47 """I listen on a TCP port for Changes from 'buildbot sendchange'. 48 49 I am a ChangeSource which will accept Changes from a remote source. I 50 share a TCP listening port with the buildslaves. 51 52 The 'buildbot sendchange' command, the contrib/svn_buildbot.py tool, 53 and the contrib/bzr_buildbot.py tool know how to send changes to me. 54 55 @type prefix: string (or None) 56 @param prefix: if set, I will ignore any filenames that do not start 57 with this string. Moreover I will remove this string 58 from all filenames before creating the Change object 59 and delivering it to the Schedulers. This is useful 60 for changes coming from version control systems that 61 represent branches as parent directories within the 62 repository (like SVN and Perforce). Use a prefix of 63 'trunk/' or 'project/branches/foobranch/' to only 64 follow one branch and to get correct tree-relative 65 filenames. 66 67 @param sep: DEPRECATED (with an axe). sep= was removed in 68 buildbot-0.7.4 . Instead of using it, you should use 69 prefix= with a trailing directory separator. This 70 docstring (and the better-than-nothing error message 71 which occurs when you use it) will be removed in 0.7.5 . 72 """ 73 74 # sep= was removed in 0.7.4 . This more-helpful-than-nothing error 75 # message will be removed in 0.7.5 . 76 assert sep is None, "prefix= is now a complete string, do not use sep=" 77 # TODO: current limitations 78 assert user == "change" 79 assert passwd == "changepw" 80 assert port == None 81 self.user = user 82 self.passwd = passwd 83 self.port = port 84 self.prefix = prefix
85
86 - def describe(self):
87 # TODO: when the dispatcher is fixed, report the specific port 88 #d = "PB listener on port %d" % self.port 89 d = "PBChangeSource listener on all-purpose slaveport" 90 if self.prefix is not None: 91 d += " (prefix '%s')" % self.prefix 92 return d
93
94 - def startService(self):
95 base.ChangeSource.startService(self) 96 # our parent is the ChangeMaster object 97 # find the master's Dispatch object and register our username 98 # TODO: the passwd should be registered here too 99 master = self.parent.parent 100 master.dispatcher.register(self.user, self)
101
102 - def stopService(self):
103 base.ChangeSource.stopService(self) 104 # unregister our username 105 master = self.parent.parent 106 master.dispatcher.unregister(self.user)
107
108 - def getPerspective(self):
109 return ChangePerspective(self.parent, self.prefix)
110