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)
37 LogFile.write(self, s)
40 class HeadRequest(urllib2.Request):
45 def __init__(self, address):
46 self.read_setup = False
47 self.log = urllib2.urlopen(address)
48 self.address = address
52 line = self.log.readline()
53 sys.stderr.write(sys.argv[0] + " : " + str(self) + " read \""+str(line) + "\" from address " + str(self.address) + "\n")
55 sys.stderr.write(sys.argv[0] + " : " + str(self) + " retrieving from address " + str(self.address) + "\n")
56 date_mod = datetime.datetime.strptime(self.log.headers['last-modified'], "%a, %d %b %Y %H:%M:%S GMT")
59 next_log = urllib2.urlopen(HeadRequest(self.address))
60 date_new = datetime.datetime.strptime(next_log.headers['last-modified'], "%a, %d %b %Y %H:%M:%S GMT")
61 while date_new <= date_mod:
62 next_log = urllib2.urlopen(HeadRequest(self.address))
63 date_new = datetime.datetime.strptime(next_log.headers['last-modified'], "%a, %d %b %Y %H:%M:%S GMT")
65 self.log = urllib2.urlopen(address)
67 line = self.log.readline()
78 def log_init(board, players):
80 log_file.setup(board, players)