增加清理无用测试数据的功能,同时更新部分文字颜色

This commit is contained in:
virusdefender 2016-01-26 16:39:30 +08:00
parent 991a96ddb7
commit 480050fac3
2 changed files with 40 additions and 4 deletions

View 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"))

View File

@ -1,5 +1,5 @@
# coding=utf-8 # 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 account.models import User, SUPER_ADMIN, UserProfile
from utils.shortcuts import rand_str from utils.shortcuts import rand_str
@ -11,6 +11,6 @@ class Command(BaseCommand):
user.set_password(rand_password) user.set_password(rand_password)
user.save() user.save()
UserProfile.objects.create(user=user) UserProfile.objects.create(user=user)
self.stdout.write("Successfully created super admin user.\nUsername: root\nPassword: %s\n" 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 " "Remember to change password and turn on two factors auth "
"after installation." % rand_password) "after installation." % rand_password))