def get_last_failed_upload(self, tourney_name): try: with countdowntourney.tourney_open(tourney_name, db_dir) as tourney: failed_upload = tourney.get_last_failed_upload() if failed_upload is not None and failed_upload.get( "ts", None) is not None and failed_upload[ "ts"] >= self.tourney_upload_start_time.get( tourney_name, 0): return failed_upload else: return None except countdowntourney.TourneyException as e: sys.stderr.write("Failed to get last failed upload info: %s\n" % (str(e))) return None
def get_last_successful_upload_time(self, tourney_name): try: with countdowntourney.tourney_open(tourney_name, db_dir) as tourney: upload_time = tourney.get_last_successful_upload_time() # Don't return this time if it's before the user even pressed # the "start uploading" button" if upload_time is None or upload_time < self.tourney_upload_start_time.get( tourney_name, 0): return None else: return upload_time except countdowntourney.TourneyException as e: sys.stderr.write( "Failed to get last successful upload time: %s\n" % (str(e))) return None
} if (renames != null) { for (var i = 0; i < renames.length; ++i) { renames[i].style.display = "none"; } } } </script> """) cgicommon.assert_client_from_localhost() if tourneyname is not None: try: tourney = countdowntourney.tourney_open(tourneyname, cgicommon.dbdir) except countdowntourney.TourneyException as e: cgicommon.show_tourney_exception(e) cgicommon.show_sidebar(tourney) cgicommon.writeln("<div class=\"mainpane\">") cgicommon.writeln("<h1>Division Setup</h1>") if tourneyname is None: cgicommon.writeln("<h1>Sloblock</h1>") cgicommon.writeln( "<p>No tourney name specified. <a href=\"/cgi-bin/home.py\">Home</a></p>" ) elif not tourney: cgicommon.writeln("<p>No valid tourney name specified</p>")
def body(self): while True: uploading_tourneys = self.uploading_tourneys.copy() for tourney_name in uploading_tourneys: now = time.time() last_upload_time = self.tourney_last_upload_attempt_time.get( tourney_name, 0) if now >= last_upload_time + upload_interval_sec: # Upload this tourney to the web if it's been at least # upload_interval_sec seconds since the previous upload # attempt. try: self.tourney_last_upload_attempt_time[ tourney_name] = now with countdowntourney.tourney_open( tourney_name, db_dir) as tourney: game_state = get_game_state(tourney) tourney_unique_id = get_tourney_unique_id(tourney) auth = self.tourney_auth.get(tourney_name, None) if auth: username = auth.get("username") password = auth.get("password") private = auth.get("private", False) else: username = None password = None private = False req = { "username": username, "password": password, "private": private, "unique_id": tourney_unique_id, "tourney": tourney_name } # If the game state has changed since the last time # we did a successful upload, include the new game # state, otherwise we just submit a null update # which only checks the server still works and # reads how many current visitors there are. if tourney_name not in self.tourney_last_uploaded_game_state or game_state != self.tourney_last_uploaded_game_state[ tourney_name]: req["state"] = game_state # Send the submission to the server & get the reply rep = make_https_json_request( http_server_host, http_server_port, http_submit_path, req) num_viewers = None if rep.get("success", False): self.tourney_last_uploaded_game_state[ tourney_name] = game_state tourney.log_successful_upload() if "state" in req: self.write_log( "Successfully uploaded state for tourney \"%s\"" % (tourney_name)) else: self.write_log( "No change since last upload of tourney \"%s\"" % (tourney_name)) num_viewers = rep.get("viewers", None) if num_viewers is not None: self.write_log( "Server reports %d viewer%s." % (num_viewers, "s" if num_viewers != 1 else "")) else: if rep.get("http_failure", False): failure_type = countdowntourney.UPLOAD_FAIL_TYPE_HTTP else: failure_type = countdowntourney.UPLOAD_FAIL_TYPE_REJECTED tourney.log_failed_upload( failure_type, rep.get("message", "(no message)")) self.write_log( "Failed to upload state for tourney \"%s\": %s" % (tourney_name, rep.get("message", "(no message"))) self.tourney_num_viewers[ tourney_name] = num_viewers except countdowntourney.TourneyException as e: self.write_log( "UploaderThread: couldn't open tourney %s: %s" % (tourney_name, str(e))) traceback.print_tb(e.__traceback__) continue except Exception as e: self.write_log("Uploader thread threw exception: %s" % (str(e))) traceback.print_tb(e.__traceback__) continue time.sleep(1)