Skip to content

Commit

Permalink
feat: Allow DumpExporter to only export tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaldmiao committed Mar 20, 2021
1 parent 9236084 commit d273682
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cms/db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def get_datasets_to_judge(task):

def enumerate_files(
session, contest=None,
skip_submissions=False, skip_user_tests=False, skip_print_jobs=False,
skip_generated=False):
skip_submissions=False, skip_user_tests=False, skip_users=False,
skip_print_jobs=False, skip_generated=False):
"""Enumerate all the files (by digest) referenced by the
contest.
Expand All @@ -302,7 +302,7 @@ def enumerate_files(
queries.append(dataset_q.join(Dataset.testcases)
.with_entities(Testcase.output))

if not skip_submissions:
if not skip_submissions and not skip_users:
submission_q = task_q.join(Task.submissions)
queries.append(submission_q.join(Submission.files)
.with_entities(File.digest))
Expand All @@ -312,7 +312,7 @@ def enumerate_files(
.join(SubmissionResult.executables)
.with_entities(Executable.digest))

if not skip_user_tests:
if not skip_user_tests and not skip_users:
user_test_q = task_q.join(Task.user_tests)
queries.append(user_test_q.with_entities(UserTest.input))
queries.append(user_test_q.join(UserTest.files)
Expand All @@ -327,7 +327,7 @@ def enumerate_files(
queries.append(user_test_result_q
.with_entities(UserTestResult.output))

if not skip_print_jobs:
if not skip_print_jobs and not skip_users:
queries.append(contest_q.join(Contest.participations)
.join(Participation.printjobs)
.with_entities(PrintJob.digest))
Expand Down
29 changes: 24 additions & 5 deletions cmscontrib/DumpExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from cms.db import version as model_version, Codename, Filename, \
FilenameSchema, FilenameSchemaArray, Digest, SessionGen, Contest, User, \
Task, Submission, UserTest, SubmissionResult, UserTestResult, PrintJob, \
Admin, Message, Question, Announcement, Participation, \
enumerate_files
from cms.db.filecacher import FileCacher
from cmscommon.datetime import make_timestamp
Expand Down Expand Up @@ -136,15 +137,18 @@ class DumpExporter:

def __init__(self, contest_ids, export_target,
dump_files, dump_model, skip_generated,
skip_submissions, skip_user_tests, skip_print_jobs):
skip_submissions, skip_user_tests, skip_users, skip_print_jobs):
if contest_ids is None:
with SessionGen() as session:
contests = session.query(Contest).all()
self.contests_ids = [contest.id for contest in contests]
users = session.query(User).all()
self.users_ids = [user.id for user in users]
tasks = session.query(Task)\
.filter(Task.contest_id.is_(None)).all()
if not skip_users:
users = session.query(User).all()
self.users_ids = [user.id for user in users]
tasks = session.query(Task)\
.filter(Task.contest_id.is_(None)).all()
else:
self.user_ids = []
self.tasks_ids = [task.id for task in tasks]
else:
# FIXME: this is ATM broken, because if you export a contest, you
Expand All @@ -158,6 +162,7 @@ def __init__(self, contest_ids, export_target,
self.skip_generated = skip_generated
self.skip_submissions = skip_submissions
self.skip_user_tests = skip_user_tests
self.skip_users = skip_users
self.skip_print_jobs = skip_print_jobs
self.export_target = export_target

Expand Down Expand Up @@ -208,6 +213,7 @@ def do_export(self):
session, contest,
skip_submissions=self.skip_submissions,
skip_user_tests=self.skip_user_tests,
skip_users=self.skip_users,
skip_print_jobs=self.skip_print_jobs,
skip_generated=self.skip_generated)
for file_ in files:
Expand Down Expand Up @@ -306,6 +312,7 @@ class of the given object), an item for each column property
val = getattr(obj, prp.key)
data[prp.key] = encode_value(col.type, val)

user_related_classes = [User, Admin, UserTest, Submission, PrintJob, Message, Question, Announcement, Participation]
for prp in cls._rel_props:
other_cls = prp.mapper.class_

Expand All @@ -317,6 +324,15 @@ class of the given object), an item for each column property
if self.skip_user_tests and other_cls is UserTest:
continue

if self.skip_users:
skip = False
for rel_class in user_related_classes:
if other_cls is rel_class:
skip = True
break
if skip:
continue

# Skip print jobs if requested
if self.skip_print_jobs and other_cls is PrintJob:
continue
Expand Down Expand Up @@ -397,6 +413,8 @@ def main():
help="don't export submissions")
parser.add_argument("-U", "--no-user-tests", action="store_true",
help="don't export user tests")
parser.add_argument("-X", "--no-users", action="store_true",
help="don't export users")
parser.add_argument("-P", "--no-print-jobs", action="store_true",
help="don't export print jobs")
parser.add_argument("export_target", action="store",
Expand All @@ -412,6 +430,7 @@ def main():
skip_generated=args.no_generated,
skip_submissions=args.no_submissions,
skip_user_tests=args.no_user_tests,
skip_users=args.no_users,
skip_print_jobs=args.no_print_jobs)
success = exporter.do_export()
return 0 if success is True else 1
Expand Down

0 comments on commit d273682

Please sign in to comment.