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