00001 # status_history.py 00002 00003 class StatusHistory(): 00004 def __init__(self, max_length=10): 00005 self.max_length = max_length 00006 self.buffer = [] 00007 def add(self, status): 00008 self.buffer.append(status) 00009 if len(self.buffer) > self.max_length: 00010 self.buffer = self.buffer[1:self.max_length+1] 00011 def all(self, proc): 00012 for status in self.buffer: 00013 if not proc(status): 00014 return False 00015 return True 00016 def latest(self): 00017 if len(self.buffer) > 0: 00018 return self.buffer[-1] 00019 else: 00020 return None 00021 def length(self): 00022 return len(self.buffer) 00023 def new(self, status, attr): 00024 if len(self.buffer) == 0: 00025 return getattr(status, attr) 00026 else: 00027 return getattr(status, attr) and not getattr(self.latest(), attr)