Skip to content

Commit

Permalink
Allow adding prefix in problem name
Browse files Browse the repository at this point in the history
  • Loading branch information
leduythuccs committed Oct 6, 2023
1 parent 6630594 commit 5b8eb81
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions judge/management/commands/export_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
problem_data_storage = ProblemDataStorage()


def export_problem(code, export_name=None):
export_name = export_name or code
def export_problem(code, export_code=None, prefix_name=''):
export_code = export_code or code

problem = Problem.objects.get(code=code)

# Retrieve
data = {
'code': export_name, # Use for custom names
'name': problem.name,
'code': export_code, # Use for custom names
'name': prefix_name + problem.name,
'description': problem.description,
'time_limit': problem.time_limit,
'memory_limit': problem.memory_limit,
Expand All @@ -30,15 +30,15 @@ def export_problem(code, export_name=None):
'partial': problem.partial,
}

tmp_dir = os.path.join('/', 'tmp', export_name)
tmp_dir = os.path.join('/', 'tmp', export_code)
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
os.mkdir(tmp_dir)

json.dump(data, open(os.path.join(tmp_dir, 'problem.json'), 'w'))
if problem_data_storage.exists(code):
shutil.copytree(problem_data_storage.path(code), tmp_dir, dirs_exist_ok=True)
package_dir = shutil.make_archive(os.path.join('/', 'tmp', export_name), 'zip', tmp_dir)
package_dir = shutil.make_archive(os.path.join('/', 'tmp', export_code), 'zip', tmp_dir)
shutil.rmtree(tmp_dir) # Remove unused directory after packing

return package_dir
Expand Down

0 comments on commit 5b8eb81

Please sign in to comment.