Exemplo n.º 1
0
		wrap()

	def tickWrap(self):
		try:
			self.tick()
			return True
		except Exception, e:
			print "EventThread error:"
			if self.gameCon is not None:
				self.gameCon.err = str(e)
				if hasattr(self.gameCon, 'game'):
					WSSpadesHandler.on_game_change(self.gameCon.game)
			traceback.print_exc()
			return False
		finally:
			DB.setActiveGame(getattr(self.gameCon, 'game', None))

	def tick(self):
		if self.gameCon is None:
			# Get list of logs (['YYYY-mm-dd_HHMMSS.log'])
			# Unfortunately the server doesn't return an etag for this page; instead we cache based on the number of logs displayed, on the assumption that logs will never be removed
			req = requests.get(logURL)
			if req.status_code != 200:
				raise RuntimeError("Server returned %d looking up log list" % req.status_code)
			logs = map(str, lxml.html.fromstring(req.text).xpath('//a[substring-after(@href, ".")="log"]/@href'))
			logs = filter(None, map(Shim.onLogLoad, logs))

			numGames = len(getGames())
			if len(logs) < numGames:
				raise RuntimeError("Only got %d %s from server (have %d in database)" % (len(logs), 'log' if len(logs) == 1 else 'logs', numGames))
			elif len(logs) == numGames: # No new logs