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 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20import pprint 21 22 23class FakeWorkerForBuilder(object): 24 25 """ 26 Simulates a WorkerForBuilder, but just records the updates from sendUpdate 27 in its updates attribute. Call show() to get a pretty-printed string 28 showing the updates. Set debug to True to show updates as they happen. 29 """ 30 debug = False 31 32 def __init__(self, basedir="/workerbuilder/basedir"): 33 self.updates = [] 34 self.basedir = basedir 35 self.unicode_encoding = 'utf-8' 36 37 def sendUpdate(self, data): 38 if self.debug: 39 print("FakeWorkerForBuilder.sendUpdate", data) 40 self.updates.append(data) 41 42 def show(self): 43 return pprint.pformat(self.updates) 44 45 # Returns a Deferred 46 def protocol_update_upload_file_close(self, writer): 47 return writer.callRemote("close") 48 49 # Returns a Deferred 50 def protocol_update_upload_file_utime(self, writer, access_time, modified_time): 51 return writer.callRemote("utime", (access_time, modified_time)) 52 53 # Returns a Deferred 54 def protocol_update_upload_file_write(self, writer, data): 55 return writer.callRemote('write', data) 56 57 # Returns a Deferred 58 def protocol_update_upload_directory(self, writer): 59 return writer.callRemote("unpack") 60 61 # Returns a Deferred 62 def protocol_update_upload_directory_write(self, writer, data): 63 return writer.callRemote('write', data) 64 65 # Returns a Deferred 66 def protocol_update_read_file_close(self, reader): 67 return reader.callRemote('close') 68 69 # Returns a Deferred 70 def protocol_update_read_file(self, reader, length): 71 return reader.callRemote('read', length) 72