mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
增加清理无用测试数据的功能,同时更新部分文字颜色
This commit is contained in:
parent
991a96ddb7
commit
480050fac3
36
utils/management/commands/cleantestcase.py
Normal file
36
utils/management/commands/cleantestcase.py
Normal file
@ -0,0 +1,36 @@
|
||||
# coding=utf-8
|
||||
import shutil
|
||||
import os
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from problem.models import Problem
|
||||
from contest.models import ContestProblem
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
清除测试用例文件夹中无用的测试用例
|
||||
"""
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write(self.style.WARNING("Please backup your test case dir firstly!"))
|
||||
problem_test_cases = [item.test_case_id for item in Problem.objects.all()]
|
||||
contest_problem_test_cases = [item.test_case_id for item in ContestProblem.objects.all()]
|
||||
|
||||
test_cases = list(set(problem_test_cases + contest_problem_test_cases))
|
||||
test_cases_dir = os.listdir(settings.TEST_CASE_DIR)
|
||||
|
||||
# 在 test_cases_dir 而不在 test_cases 中的
|
||||
dir_to_be_removed = list(set(test_cases_dir).difference(set(test_cases)))
|
||||
if dir_to_be_removed:
|
||||
self.stdout.write(self.style.ERROR("Following dirs will be removed: "))
|
||||
for item in dir_to_be_removed:
|
||||
self.stdout.write(self.style.WARNING(os.path.join(settings.TEST_CASE_DIR, item)))
|
||||
self.stdout.write(self.style.ERROR("Input yes to confirm: "))
|
||||
if raw_input() == "yes":
|
||||
for item in dir_to_be_removed:
|
||||
shutil.rmtree(os.path.join(settings.TEST_CASE_DIR, item), ignore_errors=True)
|
||||
self.stdout.write(self.style.SUCCESS("Done"))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS("Nothing happened"))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS("Test case dir is clean, nothing to do"))
|
@ -1,5 +1,5 @@
|
||||
# coding=utf-8
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core.management.base import BaseCommand
|
||||
from account.models import User, SUPER_ADMIN, UserProfile
|
||||
from utils.shortcuts import rand_str
|
||||
|
||||
@ -11,6 +11,6 @@ class Command(BaseCommand):
|
||||
user.set_password(rand_password)
|
||||
user.save()
|
||||
UserProfile.objects.create(user=user)
|
||||
self.stdout.write("Successfully created super admin user.\nUsername: root\nPassword: %s\n"
|
||||
"Remember to change password and turn on two factors auth "
|
||||
"after installation." % rand_password)
|
||||
self.stdout.write(self.style.SUCCESS("Successfully created super admin user.\nUsername: root\nPassword: %s\n"
|
||||
"Remember to change password and turn on two factors auth "
|
||||
"after installation." % rand_password))
|
||||
|
Loading…
Reference in New Issue
Block a user