6 def __init__(self, file_name):
8 self.log = open(file_name, "w", 0)
11 self.log.write(str(datetime.datetime.now()) + " : " + s + "\n")
13 def setup(self, board, players):
14 self.log.write("# Log starts " + str(datetime.datetime.now()) + "\n")
16 self.log.write("# " + p.colour + " : " + p.name + "\n")
18 self.log.write("# Initial board\n")
21 if board.grid[x][y] != None:
22 self.log.write(str(board.grid[x][y]) + "\n")
24 self.log.write("# Start game\n")
26 class HttpLog(LogFile):
27 def __init__(self, file_name):
28 LogFile.__init__(self, file_name)
29 self.file_name = file_name
33 self.log = open(self.file_name, "w", 0)
35 LogFile.setup(self, game.board, game.players)
38 class HeadRequest(urllib2.Request):
43 def __init__(self, address):
44 self.read_setup = False
45 self.log = urllib2.urlopen(address)
46 self.address = address
50 line = self.log.readline()
51 sys.stderr.write(sys.argv[0] + " : " + str(self.__class__.__name__) + " read \""+str(line.strip("\r\n")) + "\" from address " + str(self.address) + "\n")
53 sys.stderr.write(sys.argv[0] + " : " + str(self.__class__.__name__) + " retrieving from address " + str(self.address) + "\n")
54 date_mod = datetime.datetime.strptime(self.log.headers['last-modified'], "%a, %d %b %Y %H:%M:%S GMT")
57 next_log = urllib2.urlopen(HeadRequest(self.address))
58 date_new = datetime.datetime.strptime(next_log.headers['last-modified'], "%a, %d %b %Y %H:%M:%S GMT")
59 while date_new <= date_mod:
60 next_log = urllib2.urlopen(HeadRequest(self.address))
61 date_new = datetime.datetime.strptime(next_log.headers['last-modified'], "%a, %d %b %Y %H:%M:%S GMT")
63 self.log = urllib2.urlopen(self.address)
65 line = self.log.readline()
78 def log_init(board, players):
80 log_file.setup(board, players)