head 1.9; access; symbols; locks georg:1.9; strict; comment @# @; 1.9 date 2002.07.01.11.03.06; author georg; state Exp; branches; next 1.8; 1.8 date 2002.07.01.10.41.27; author georg; state Exp; branches; next 1.7; 1.7 date 2002.06.28.23.57.50; author georg; state Exp; branches; next 1.6; 1.6 date 2002.06.28.23.49.30; author georg; state Exp; branches; next 1.5; 1.5 date 2002.06.28.23.29.56; author georg; state Exp; branches; next 1.4; 1.4 date 2002.06.28.21.19.12; author georg; state Exp; branches; next 1.3; 1.3 date 2002.06.28.21.04.12; author georg; state Exp; branches; next 1.2; 1.2 date 2002.06.28.19.34.39; author georg; state Exp; branches; next 1.1; 1.1 date 2002.06.28.19.28.29; author georg; state Exp; branches; next ; desc @init @ 1.9 log @pretty @ text @#!/usr/bin/env python import string,sys import time,os,stat import traceback version = "$Id: fte-image-checker.py,v 1.8 2002/07/01 10:41:27 georg Exp georg $" maxage=100 # seconds workdir="/home/httpd/sunpendulum/fte/img" offline="off.jpg" files="""azores.jpg bermuda.jpg cairo.jpg dubai.jpg ensenada.jpg granada.jpg maui.jpg neworleans.jpg""" class Picture: def __init__ (self,fpath,offline): self.fpath = fpath self.offline = offline self.isOffline = 0 self.doit() def __str__(self): return ("%14s, Age: %6d, Next check: %3d" % (self.fpath,self.getAge(),self.checkInSec())) def getAge(self): # return Age try: age = time.time()-os.stat(self.fpath)[stat.ST_MTIME] except e: sys.stdout.write("%s %s\n" % (str(e),str(self))) sys.stdout.flush() return age def checkInSec(self): u = maxage - self.getAge() if u > 0: return u else: return maxage def setOffline(self): # copy the offline thing if not self.isOffline: # Status change self.isOffline = 1 sys.stdout.write("setting offline: %s\n" % str(self)) sys.stdout.flush() offline_mtime = os.stat(self.fpath)[stat.ST_MTIME] o=open(self.offline) i=open(self.fpath,"w") i.write(o.read()) i.close() o.close() os.utime(self.fpath,(offline_mtime,offline_mtime)) def setOnline(self): if self.isOffline: # Status change self.isOffline = 0 sys.stdout.write("recovered: %s\n" % str(self)) sys.stdout.flush() def isOk(self): # no data manipulatio tooOld = self.getAge() > maxage if not tooOld: sys.stdout.write(" online: %s\n" % str(self)) sys.stdout.flush() else: sys.stdout.write( " OFFLINE:%s\n" % str(self)) sys.stdout.flush() return (not tooOld) def doit(self): if self.isOk(): self.setOnline() else: self.setOffline() def __cmp__ (self,other): a = self.checkInSec() b = other.checkInSec() return int(((a > b) - 0.5)*2) if __name__ == '__main__': os.chdir(workdir) f=string.split(files,""" """) l=[] for i in f: try: l.append(Picture(i,offline)) except: sys.stdout.write("Error with %s\n" % i) sys.stdout.flush() l.sort() while 1: for i in l: # sys.stdout.write( i try: i.doit() except: traceback.print_stack () l.sort() sleep=l[0].checkInSec() if sleep >= maxage: sys.stdout.write( "All are offline\n") sys.stdout.flush() sys.stdout.write( " sleeping: %d\n" % sleep) sys.stdout.flush() time.sleep(sleep) @ 1.8 log @cleanup @ text @d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.7 2002/06/28 23:57:50 georg Exp georg $" d48 1 a57 1 self.isOffline = 1 d71 1 a71 1 sys.stdout.write( " offline:%s\n" % str(self)) d110 1 a110 1 sys.stdout.write( "sleeping: %f\n" % sleep) @ 1.7 log @flush @ text @d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.6 2002/06/28 23:49:30 georg Exp georg $" d26 1 d33 1 a33 1 self.age = time.time()-os.stat(self.fpath)[stat.ST_MTIME] d37 1 a37 1 return self.age d47 1 a47 4 if self.isOffline: sys.stdout.write(" still offline: %s\n"%str(self)) sys.stdout.flush() else: d50 1 a50 1 offline_mtime = os.stat(self.offline)[stat.ST_MTIME] d59 2 a60 6 def isOk(self): self.tooOld = self.getAge() > maxage if not self.tooOld: if self.isOffline: sys.stdout.write("recovered: %s\n" % str(self)) sys.stdout.flush() d62 6 d73 1 a73 1 return (not self.tooOld) d76 3 a78 1 if not self.isOk(): @ 1.6 log @printn -< sys.stdout.wri @ text @d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.5 2002/06/28 23:29:56 georg Exp georg $" d35 1 d48 1 d51 1 d66 1 d69 1 d72 1 d94 1 d107 1 d109 1 @ 1.5 log @*** empty log message *** @ text @d3 1 a3 1 import string d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.4 2002/06/28 21:19:12 georg Exp georg $" d31 4 a34 1 self.age = time.time()-os.stat(self.fpath)[stat.ST_MTIME] d46 1 a46 1 print " still offline: ",self d48 1 a48 1 print "setting offline: ", self d62 1 a62 1 print "recovered: ", self d64 1 a64 1 print " online: ", self d66 1 a66 1 print " offline:", self d87 1 a87 1 print "Error with", i d91 1 a91 1 # print i d99 2 a100 2 print "All are offline" print "sleeping: ",sleep @ 1.4 log @one more print @ text @d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.3 2002/06/28 21:04:12 georg Exp georg $" d10 1 a10 1 a11 1 d20 1 d76 1 @ 1.3 log @*** empty log message *** @ text @d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.2 2002/06/28 19:34:39 georg Exp georg $" d62 2 @ 1.2 log @*** empty log message *** @ text @d7 1 a7 1 version = "$Id: fte-image-checker.py,v 1.1 2002/06/28 19:28:29 georg Exp georg $" d94 1 a94 1 print "sleep (after sort)",sleep @ 1.1 log @Initial revision @ text @d7 1 a7 1 version = "$Id$" d28 1 a28 1 return ("%20s, Age: %8d, Next check: %3d" % (self.fpath,self.getAge(),self.checkInSec())) @