1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 from buildbot import config
26
30
35
37 log.msg("perspective_addChange called")
38
39 if 'revlink' in changedict and not changedict['revlink']:
40 changedict['revlink'] = ''
41 if 'repository' in changedict and not changedict['repository']:
42 changedict['repository'] = ''
43 if 'project' in changedict and not changedict['project']:
44 changedict['project'] = ''
45 if 'files' not in changedict or not changedict['files']:
46 changedict['files'] = []
47
48
49
50
51
52
53 if 'isdir' in changedict:
54 changedict['is_dir'] = changedict['isdir']
55 del changedict['isdir']
56 if 'who' in changedict:
57 changedict['author'] = changedict['who']
58 del changedict['who']
59 if 'when' in changedict:
60 when = None
61 if changedict['when'] is not None:
62 when = epoch2datetime(changedict['when'])
63 changedict['when_timestamp'] = when
64 del changedict['when']
65
66
67
68
69
70 for key in changedict:
71 if type(changedict[key]) == str:
72 changedict[key] = changedict[key].decode('utf8', 'replace')
73 changedict['files'] = list(changedict['files'])
74 for i, file in enumerate(changedict.get('files', [])):
75 if type(file) == str:
76 changedict['files'][i] = file.decode('utf8', 'replace')
77
78 files = []
79 for path in changedict['files']:
80 if self.prefix:
81 if not path.startswith(self.prefix):
82
83 continue
84 path = path[len(self.prefix):]
85 files.append(path)
86 changedict['files'] = files
87
88 if not files:
89 log.msg("No files listed in change... bit strange, but not fatal.")
90 d = self.master.addChange(**changedict)
91
92
93 d.addCallback(lambda _ : None)
94 return d
95
96 -class PBChangeSource(config.ReconfigurableServiceMixin, base.ChangeSource):
97 compare_attrs = ["user", "passwd", "port", "prefix", "port"]
98
99 - def __init__(self, user="change", passwd="changepw", port=None,
100 prefix=None):
101
102 self.user = user
103 self.passwd = passwd
104 self.port = port
105 self.prefix = prefix
106 self.registration = None
107 self.registered_port = None
108
110 portname = self.registered_port
111 d = "PBChangeSource listener on " + str(portname)
112 if self.prefix is not None:
113 d += " (prefix '%s')" % self.prefix
114 return d
115
116 @defer.deferredGenerator
118
119 port = self.port
120 if port is None:
121 port = new_config.slavePortnum
122
123
124 if port != self.registered_port:
125 wfd = defer.waitForDeferred(
126 self._unregister())
127 yield wfd
128 wfd.getResult()
129 self._register(port)
130
131 wfd = defer.waitForDeferred(
132 config.ReconfigurableServiceMixin.reconfigService(self,
133 new_config))
134 yield wfd
135 wfd.getResult()
136
141
143 if not port:
144 log.msg("PBChangeSource has no port to listen on")
145 return
146 self.registered_port = port
147 self.registration = self.master.pbmanager.register(
148 port, self.user, self.passwd,
149 self.getPerspective)
150
152 self.registered_port = None
153 if self.registration:
154 return self.registration.unregister()
155 else:
156 return defer.succeed(None)
157
161