From 4dd9601d6bc67ac5963aaedb99c1dfd6551cd222 Mon Sep 17 00:00:00 2001 From: Yakov Dlougach Date: Wed, 17 Apr 2024 12:48:33 +0200 Subject: [PATCH] Fix problems without accepts --- code_analyzer/githomes.py | 9 +++++++-- misc_scripts/reset_db.php | 2 +- www/problem.php | 24 ++++++++++++++---------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/code_analyzer/githomes.py b/code_analyzer/githomes.py index be7a3a9..ab9dfbc 100755 --- a/code_analyzer/githomes.py +++ b/code_analyzer/githomes.py @@ -127,6 +127,7 @@ def initCDS( self ): #self.http.disable_ssl_certificate_validation=True r = self.http_session.get("%s/%s/teams" % (self.CDSRoot, contest_id)) + r.raise_for_status() teamData = r.json() startTime = time.strftime( "%a, %d %b %Y %H:%M:%S GMT", time.gmtime(0) ) @@ -255,7 +256,9 @@ def pullBackupsCDS( self ): print(f'Unable to fetch backups for team {backup.team}{backup.path}. The team is skipped') continue - if response.status_code == requests.codes.ok: + if response.status_code == requests.codes.ok and not response.content: + print("Skipping because backup is empty file") + elif response.status_code == requests.codes.ok and response.content: sys.stdout.write("updated, commit to git... ") backup.modTime = response.headers["last-modified"] @@ -270,7 +273,9 @@ def pullBackupsCDS( self ): shutil.rmtree( backupDir ) os.makedirs( backupDir ) try: - subprocess.call( [ "unzip", "-q", f.name, "-x",".git","-x",".git/*", "-d", backupDir ] ) + retcode = subprocess.call( [ "unzip", "-q", f.name, "-x",".git","-x",".git/*", "-d", backupDir ] ) + if retcode != 0: + raise RuntimeError() except: print(f"Failed to unzip {f.name} for {backupDir}") os.unlink( f.name ) diff --git a/misc_scripts/reset_db.php b/misc_scripts/reset_db.php index 65d47b7..e60d79b 100755 --- a/misc_scripts/reset_db.php +++ b/misc_scripts/reset_db.php @@ -40,7 +40,7 @@ -------------------------------------------------------- TRUNCATING ALL THE RELEVANT TABLES %d", $row['team_id'], $row['team_id']); + if ($first_submission_time) { + $result = mysqli_query($db, "select distinct team_id as team_id from submissions " + . " where problem_id = '$problem_id' and contest_time = $first_submission_time order by team_id"); + $first_teams_to_submit = array(); + while ($row = mysqli_fetch_assoc($result)) { + $first_teams_to_submit[] = sprintf("%d", $row['team_id'], $row['team_id']); + } } $first_teams_to_submit = $first_teams_to_submit ? sprintf("(Team %s)", implode(", ", $first_teams_to_submit)) : ""; ######################################### - $result = mysqli_query($db, "select distinct team_id as team_id from submissions " - . " where problem_id = '$problem_id' and result = 'AC' and contest_time = $first_solution_time order by team_id"); - $first_teams_to_solve = array(); - while ($row = mysqli_fetch_assoc($result)) { - $first_teams_to_solve[] = sprintf("%d", $row['team_id'], $row['team_id']); + if ($first_solution_time) { + $result = mysqli_query($db, "select distinct team_id as team_id from submissions " + . " where problem_id = '$problem_id' and result = 'AC' and contest_time = $first_solution_time order by team_id"); + $first_teams_to_solve = array(); + while ($row = mysqli_fetch_assoc($result)) { + $first_teams_to_solve[] = sprintf("%d", $row['team_id'], $row['team_id']); + } } $first_teams_to_solve = $first_teams_to_solve ? sprintf("(Team %s)", implode(", ", $first_teams_to_solve)) : "";