def Fetch(self, build_numbers): """Downloads and returns build details. If a build has corrupt data, it is not included in the result. If you strictly need all the builds requested, be sure to check the result length. Args: build_numbers: An iterable of build numbers to download. Yields: Build objects, in the order requested. Some may be missing. Raises: ValueError: A build number is invalid. """ if not build_numbers: return for build_number in build_numbers: if build_number < 0: raise ValueError('Invalid build number: %d' % build_number) build_query = urllib.urlencode( [('select', build_number) for build_number in build_numbers]) url = 'json/builders/%s/builds/?%s' % ( urllib.quote(self._builder_name), build_query) url = network.BuildUrl(self._master_name, url) try: builds = network.FetchData(url).values() except (ValueError, urlfetch.ResponseTooLargeError): # The JSON decode failed, or the data was too large. # Try downloading the builds individually instead. builds = [] for build_number in build_numbers: url = 'json/builders/%s/builds/%d' % ( urllib.quote(self._builder_name), build_number) url = network.BuildUrl(self._master_name, url) try: builds.append(network.FetchData(url)) except (ValueError, urlfetch.ResponseTooLargeError): logging.warning('Unable to fetch %s build %d', self._master_name, build_number) continue for build_data in builds: if 'error' in build_data: continue yield build.Build(build_data, self._url)
def __init__(self, master_name, name, data): self._master_name = master_name self._name = name self._url = network.BuildUrl(master_name, 'builders/%s' % urllib.quote(self.name)) self._builds = builds.Builds(master_name, name, self._url) self.Update(data)
def Update(self, data=None): if not data: data = network.FetchData( network.BuildUrl(self.master_name, 'json/builders/%s' % urllib.quote(self.name))) self._state = data['state'] self._pending_build_count = data['pendingBuilds'] self._current_builds = frozenset(data['currentBuilds']) self._cached_builds = frozenset(data['cachedBuilds']) self._slaves = frozenset(data['slaves'])
def Slaves(master_name): slave_data = network.FetchData(network.BuildUrl(master_name, 'json/slaves')) return sorted( Slave(master_name, slave_name, slave_info) for slave_name, slave_info in slave_data.iteritems())
def Builders(master_name): builder_data = network.FetchData( network.BuildUrl(master_name, 'json/builders')) return sorted( Builder(master_name, builder_name, builder_info) for builder_name, builder_info in builder_data.iteritems())