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 
 22  from buildbot.util import epoch2datetime 
 23   
24 -class ChangePerspective(NewCredPerspective):
25
26 - def __init__(self, master, prefix):
27 self.master = master 28 self.prefix = prefix
29
30 - def attached(self, mind):
31 return self
32 - def detached(self, mind):
33 pass
34
35 - def perspective_addChange(self, changedict):
36 log.msg("perspective_addChange called") 37 38 if 'revlink' in changedict and not changedict['revlink']: 39 changedict['revlink'] = '' 40 if 'repository' in changedict and not changedict['repository']: 41 changedict['repository'] = '' 42 if 'project' in changedict and not changedict['project']: 43 changedict['project'] = '' 44 if 'files' not in changedict or not changedict['files']: 45 changedict['files'] = [] 46 47 # rename arguments to new names. Note that the client still uses the 48 # "old" names (who, when, and isdir), as they are not deprecated yet, 49 # although the master will accept the new names (author, 50 # when_timestamp, and is_dir). After a few revisions have passed, we 51 # can switch the client to use the new names. 52 if 'isdir' in changedict: 53 changedict['is_dir'] = changedict['isdir'] 54 del changedict['isdir'] 55 if 'who' in changedict: 56 changedict['author'] = changedict['who'] 57 del changedict['who'] 58 if 'when' in changedict: 59 when = None 60 if changedict['when'] is not None: 61 when = epoch2datetime(changedict['when']) 62 changedict['when_timestamp'] = when 63 del changedict['when'] 64 65 # turn any bytestring keys into unicode, assuming utf8 but just 66 # replacing unknown characters. Ideally client would send us unicode 67 # in the first place, but older clients do not, so this fallback is 68 # useful. 69 for key in changedict: 70 if type(changedict[key]) == str: 71 changedict[key] = changedict[key].decode('utf8', 'replace') 72 changedict['files'] = list(changedict['files']) 73 for i, file in enumerate(changedict.get('files', [])): 74 if type(file) == str: 75 changedict['files'][i] = file.decode('utf8', 'replace') 76 for i, link in enumerate(changedict.get('links', [])): 77 if type(link) == str: 78 changedict['links'][i] = link.decode('utf8', 'replace') 79 80 files = [] 81 for path in changedict['files']: 82 if self.prefix: 83 if not path.startswith(self.prefix): 84 # this file does not start with the prefix, so ignore it 85 continue 86 path = path[len(self.prefix):] 87 files.append(path) 88 changedict['files'] = files 89 90 if not files: 91 log.msg("No files listed in change... bit strange, but not fatal.") 92 return self.master.addChange(**changedict)
93
94 -class PBChangeSource(base.ChangeSource):
95 compare_attrs = ["user", "passwd", "port", "prefix", "port"] 96
97 - def __init__(self, user="change", passwd="changepw", port=None, 98 prefix=None):
99 100 self.user = user 101 self.passwd = passwd 102 self.port = port 103 self.prefix = prefix 104 self.registration = None
105
106 - def describe(self):
107 # TODO: when the dispatcher is fixed, report the specific port 108 if self.port is not None: 109 portname = self.port 110 else: 111 portname = "all-purpose slaveport" 112 d = "PBChangeSource listener on " + str(portname) 113 if self.prefix is not None: 114 d += " (prefix '%s')" % self.prefix 115 return d
116
117 - def startService(self):
118 base.ChangeSource.startService(self) 119 port = self.port 120 if port is None: 121 port = self.master.slavePortnum 122 self.registration = self.master.pbmanager.register( 123 port, self.user, self.passwd, 124 self.getPerspective)
125
126 - def stopService(self):
127 d = defer.maybeDeferred(base.ChangeSource.stopService, self) 128 def unreg(_): 129 if self.registration: 130 return self.registration.unregister()
131 d.addCallback(unreg) 132 return d
133
134 - def getPerspective(self, mind, username):
135 assert username == self.user 136 return ChangePerspective(self.master, self.prefix)
137