def index(self, slave=None): if 'numbuilds' in request.GET: count = int(request.GET.getone('numbuilds')) else: count = 25 if 'format' in request.GET: format = request.GET.getone('format') else: format = 'html' if format not in ('html', 'json'): abort(400, detail='Unsupported format: %s' % format) # if slave is not None: # slave = slave[0] if 'slave' in request.GET: slave = request.GET.getall('slave') builds = GetHistoricBuilds(slave=slave, count=count) # Return a rendered template # or, return a json blob if format == "html": c.recent_builds = builds return render("/recent.mako") else: for b in builds: for k,v in b.items(): if isinstance(v, datetime.datetime): v = times.UTC.localize(v) b[k] = times.dt2ts(v) return self.jsonify(builds)
def get_builds_for_day(self, date, branch): """ Returns a list of builds for the given date (a datetime.datetime instance) """ assert date.tzinfo key = self.build_key_for_day(date, branch) starttime = dt2ts(date) endtime = dt2ts(date + oneday) if date - now(self.timezone) < 3*oneday: # Expire soon expire = time.time() + 60 else: # Don't expire expire = 0 return self.cache.get(key, getBuilds, (branch, starttime, endtime), expire=expire)
def get_builds_for_day(self, date, branch): """ Returns a list of builds for the given date (a datetime.datetime instance) """ assert date.tzinfo key = self.build_key_for_day(date, branch) starttime = dt2ts(date) endtime = dt2ts(date + oneday) if date - now(self.timezone) < 3 * oneday: # Expire soon expire = time.time() + 60 else: # Don't expire expire = 0 return self.cache.get(key, getBuilds, (branch, starttime, endtime), expire=expire)
def get_builds_for_date_range(self, starttime, endtime, branch, method=0): """ Returns a list of builds for the given date range. starttime and endtime should be datetime.datetime instances. """ assert starttime.tzinfo assert endtime.tzinfo # Naive version: grab every day individually if method == 0: retval = [] d = starttime while d < endtime: builds = self.get_builds_for_day(d, branch) retval.extend(builds) d += oneday return retval # Less naive version? grab the entire date range if anything isn't # cached if method == 1: d = starttime need_more = False while d < endtime: key = self.build_key_for_day(d, branch) if not self.cache.has_key(key): need_more = True break d += oneday if not need_more: # Fall back to method 0 return self.get_builds_for_date_range(starttime, endtime, branch, method=0) # Do a big query to get everything builds = getBuilds( branch, dt2ts(starttime), dt2ts(endtime), ) retval = builds # And then cache the results by date days = {} for b in builds: date = ts2dt(b['starttime'], self.timezone) date = date.replace(hour=0, minute=0, second=0, microsecond=0) days.setdefault(date, []).append(b) for date, builds in days.iteritems(): if date - now(self.timezone) < 3 * oneday: # Expire soon expire = time.time() + 60 else: # Expire in half an hour expire = time.time() + 1800 key = self.build_key_for_day(date, branch) self.cache.put(key, builds, expire=expire) return retval
def get_builds_for_date_range(self, starttime, endtime, branch, method=0): """ Returns a list of builds for the given date range. starttime and endtime should be datetime.datetime instances. """ assert starttime.tzinfo assert endtime.tzinfo # Naive version: grab every day individually if method == 0: retval = [] d = starttime while d < endtime: builds = self.get_builds_for_day(d, branch) retval.extend(builds) d += oneday return retval # Less naive version? grab the entire date range if anything isn't # cached if method == 1: d = starttime need_more = False while d < endtime: key = self.build_key_for_day(d, branch) if not self.cache.has_key(key): need_more = True break d += oneday if not need_more: # Fall back to method 0 return self.get_builds_for_date_range(starttime, endtime, branch, method=0) # Do a big query to get everything builds = getBuilds(branch, dt2ts(starttime), dt2ts(endtime), ) retval = builds # And then cache the results by date days = {} for b in builds: date = ts2dt(b['starttime'], self.timezone) date = date.replace(hour=0, minute=0, second=0, microsecond=0) days.setdefault(date, []).append(b) for date, builds in days.iteritems(): if date - now(self.timezone) < 3*oneday: # Expire soon expire = time.time() + 60 else: # Expire in half an hour expire = time.time() + 1800 key = self.build_key_for_day(date, branch) self.cache.put(key, builds, expire=expire) return retval