Skip to content

Commit bbb9b32

Browse files
committed
Make code cleaner
1 parent adae5e6 commit bbb9b32

File tree

106 files changed

+432
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+432
-389
lines changed

easy_toolbox.py

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# pip requirements:
44
# python ^3.6
55
# inquirer (only for GUI)
6-
#
6+
#
77
# system:
88
# docker
99
# docker-compose
@@ -19,8 +19,9 @@
1919
import os
2020

2121

22-
BASE_DOCKER_COMMAND = "OIOIOI_UID=$(id -u) docker-compose" + \
23-
" -f docker-compose-dev.yml"
22+
BASE_DOCKER_COMMAND = (
23+
"OIOIOI_UID=$(id -u) docker-compose" + " -f docker-compose-dev.yml"
24+
)
2425

2526
RAW_COMMANDS = [
2627
("build", "Build OIOIOI container from source.", "build", True),
@@ -31,17 +32,38 @@
3132
("bash", "Open command prompt on web container.", "{exec} web bash"),
3233
("bash-db", "Open command prompt on database container.", "{exec} db bash"),
3334
# This one CLEARS the database. Use wisely.
34-
("flush-db", "Clear database.", "{exec} web python manage.py flush --noinput", True),
35-
("add-superuser", "Create admin_admin.",
36-
"{exec} web python manage.py loaddata ../oioioi/oioioi_cypress/cypress/fixtures/admin_admin.json"),
35+
(
36+
"flush-db",
37+
"Clear database.",
38+
"{exec} web python manage.py flush --noinput",
39+
True,
40+
),
41+
(
42+
"add-superuser",
43+
"Create admin_admin.",
44+
"{exec} web python manage.py loaddata ../oioioi/oioioi_cypress/cypress/fixtures/admin_admin.json",
45+
),
3746
("test", "Run unit tests.", "{exec} web ../oioioi/test.sh"),
38-
("test-slow", "Run unit tests. (--runslow)", "{exec} web ../oioioi/test.sh --runslow"),
39-
("test-abc", "Run specific test file. (edit the toolbox)",
40-
"{exec} web ../oioioi/test.sh -v oioioi/problems/tests/test_task_archive.py"),
41-
("test-coverage", "Run coverage tests.",
42-
"{exec} 'web' ../oioioi/test.sh oioioi/problems --cov-report term --cov-report xml:coverage.xml --cov=oioioi"),
43-
("cypress-apply-settings", "Apply settings for CyPress.",
44-
"{exec} web bash -c \"echo CAPTCHA_TEST_MODE=True >> settings.py\""),
47+
(
48+
"test-slow",
49+
"Run unit tests. (--runslow)",
50+
"{exec} web ../oioioi/test.sh --runslow",
51+
),
52+
(
53+
"test-abc",
54+
"Run specific test file. (edit the toolbox)",
55+
"{exec} web ../oioioi/test.sh -v oioioi/problems/tests/test_task_archive.py",
56+
),
57+
(
58+
"test-coverage",
59+
"Run coverage tests.",
60+
"{exec} 'web' ../oioioi/test.sh oioioi/problems --cov-report term --cov-report xml:coverage.xml --cov=oioioi",
61+
),
62+
(
63+
"cypress-apply-settings",
64+
"Apply settings for CyPress.",
65+
"{exec} web bash -c \"echo CAPTCHA_TEST_MODE=True >> settings.py\"",
66+
),
4567
]
4668

4769
longest_command_arg = max([len(command[0]) for command in RAW_COMMANDS])
@@ -63,7 +85,9 @@ def fill_tty(self, disable=False):
6385
self.command = self.command.format(exec="exec -T" if disable else "exec")
6486

6587
def long_str(self) -> str:
66-
return f"Option({self.arg}, Description='{self.help}', Command='{self.command}')"
88+
return (
89+
f"Option({self.arg}, Description='{self.help}', Command='{self.command}')"
90+
)
6791

6892
def __str__(self) -> str:
6993
spaces = longest_command_arg - len(self.arg)
@@ -75,7 +99,9 @@ def __str__(self) -> str:
7599

76100
def check_commands() -> None:
77101
if len(set([opt.arg for opt in COMMANDS])) != len(COMMANDS):
78-
raise Exception("Error in COMMANDS. Same name was declared for more then one command.")
102+
raise Exception(
103+
"Error in COMMANDS. Same name was declared for more then one command."
104+
)
79105

80106

81107
NO_INPUT = False
@@ -110,12 +136,9 @@ def get_action_from_args() -> Option:
110136

111137
def get_action_from_gui() -> Option:
112138
import inquirer
139+
113140
questions = [
114-
inquirer.List(
115-
"action",
116-
message="Select OIOIOI action",
117-
choices=COMMANDS
118-
)
141+
inquirer.List("action", message="Select OIOIOI action", choices=COMMANDS)
119142
]
120143
answers = inquirer.prompt(questions)
121144
return answers["action"]
@@ -130,7 +153,9 @@ def run_command(command) -> None:
130153

131154

132155
def warn_user(action: Option) -> bool:
133-
print(f"You are going to execute command [{action.command}] marked as `dangerous`. Are you sure? [y/N]")
156+
print(
157+
f"You are going to execute command [{action.command}] marked as `dangerous`. Are you sure? [y/N]"
158+
)
134159
while True:
135160
choice = input().lower()
136161
if not choice or "no".startswith(choice):
@@ -152,10 +177,19 @@ def run() -> None:
152177

153178

154179
def print_help() -> None:
155-
print("OIOIOI helper toolbox", "", "This script allows to control OIOIOI with Docker commands.",
156-
f"Commands are always being run with '{BASE_DOCKER_COMMAND}' prefix.",
157-
f"Aveliable commands are: ", "",
158-
*COMMANDS, "", "Example `build`:", f"{sys.argv[0]} build", sep="\n")
180+
print(
181+
"OIOIOI helper toolbox",
182+
"",
183+
"This script allows to control OIOIOI with Docker commands.",
184+
f"Commands are always being run with '{BASE_DOCKER_COMMAND}' prefix.",
185+
f"Aveliable commands are: ",
186+
"",
187+
*COMMANDS,
188+
"",
189+
"Example `build`:",
190+
f"{sys.argv[0]} build",
191+
sep="\n",
192+
)
159193

160194

161195
def main() -> None:

oioioi/_locale/apps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
class LocaleConfig(AppConfig):
55
default_auto_field = 'django.db.models.AutoField'
66
name = 'oioioi._locale'
7-

oioioi/acm/controllers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ def fill_evaluation_environ(self, environ, submission):
5858

5959
def update_report_statuses(self, submission, queryset):
6060
if submission.kind == 'TESTRUN':
61-
self._activate_newest_report(submission, queryset,
62-
kind=['TESTRUN', 'FAILURE'])
61+
self._activate_newest_report(
62+
submission, queryset, kind=['TESTRUN', 'FAILURE']
63+
)
6364
return
6465

6566
self._activate_newest_report(submission, queryset, kind=['FULL', 'FAILURE'])

oioioi/acm/score.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _to_repr(self):
163163
164164
``penalties_count`` is number of unsuccessful submissions.
165165
"""
166-
ordering = 10 ** 10 * (self.problems_solved + 1) - self.total_time
166+
ordering = 10**10 * (self.problems_solved + 1) - self.total_time
167167
return '%020d:%010d:%010d:%010d' % (
168168
ordering,
169169
self.problems_solved,

oioioi/acm/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ def acm_test_scorer(test, result):
88

99

1010
def acm_group_scorer(test_results):
11-
status = aggregate_statuses(
12-
[result['status'] for result in test_results.values()]
13-
)
11+
status = aggregate_statuses([result['status'] for result in test_results.values()])
1412
return None, None, status
1513

1614

1715
def acm_score_aggregator(group_results):
1816
if not group_results:
1917
return None, None, 'OK'
20-
status = aggregate_statuses(
21-
[result['status'] for result in group_results.values()]
22-
)
18+
status = aggregate_statuses([result['status'] for result in group_results.values()])
2319
return BinaryScore(status == 'OK'), BinaryScore(True), status

oioioi/balloons/management/commands/import_balloons_displays.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,4 @@ def handle(self, *args, **options):
111111
if ok:
112112
self.stdout.write(_("Processed %d entries") % (all_count))
113113
else:
114-
raise CommandError(
115-
_("There were some errors. Database not changed.\n")
116-
)
114+
raise CommandError(_("There were some errors. Database not changed.\n"))

oioioi/balloons/models.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
check_django_app_dependencies(__name__, ['oioioi.participants', 'oioioi.acm'])
1212

1313

14-
1514
class ProblemBalloonsConfig(models.Model):
1615
problem_instance = models.OneToOneField(
1716
ProblemInstance,
@@ -27,13 +26,7 @@ class Meta(object):
2726
verbose_name_plural = _("balloons colors")
2827

2928
def __str__(self):
30-
return (
31-
str(self.problem_instance)
32-
+ u' ('
33-
+ str(self.color)
34-
+ u')'
35-
)
36-
29+
return str(self.problem_instance) + u' (' + str(self.color) + u')'
3730

3831

3932
class BalloonsDisplay(models.Model):
@@ -55,7 +48,6 @@ def __str__(self):
5548
return str(self.ip_addr)
5649

5750

58-
5951
class BalloonDelivery(models.Model):
6052
user = models.ForeignKey(User, verbose_name=_("user"), on_delete=models.CASCADE)
6153
problem_instance = models.ForeignKey(

oioioi/base/admin.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ class ModelAdminMeta(admin.ModelAdmin.__class__, ClassInitMeta):
6262
pass
6363

6464

65-
class ModelAdmin(
66-
admin.ModelAdmin, ObjectWithMixins, metaclass=ModelAdminMeta
67-
):
68-
65+
class ModelAdmin(admin.ModelAdmin, ObjectWithMixins, metaclass=ModelAdminMeta):
6966
# This is handled by AdminSite._reinit_model_admins
7067
allow_too_late_mixins = True
7168

@@ -332,11 +329,7 @@ def get_urls(self):
332329

333330
def login(self, request, extra_context=None):
334331
next_url = request.GET.get('next', None)
335-
suffix = (
336-
'?' + urllib.parse.urlencode({'next': next_url})
337-
if next_url
338-
else ''
339-
)
332+
suffix = '?' + urllib.parse.urlencode({'next': next_url}) if next_url else ''
340333
return HttpResponseRedirect(reverse('auth_login') + suffix)
341334

342335

oioioi/base/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
@api_view()
1414
def ping(request):
15-
""" Test endpoint for unauthorized user. """
15+
"""Test endpoint for unauthorized user."""
1616
return Response("pong")
1717

1818

1919
@api_view()
2020
@enforce_condition(not_anonymous, login_redirect=False)
2121
def auth_ping(request):
22-
""" Test endpoint for authorized user. """
22+
"""Test endpoint for authorized user."""
2323
return Response("pong " + str(request.user))
2424

2525

oioioi/base/captcha_check.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class CaptchaAudioWarning(Warning):
1313

1414

1515
def _check_executable(setting_name, path, expected_code=0):
16-
1716
if not os.path.isfile(path):
1817
raise ImproperlyConfigured(
1918
'{}: {} is not a valid path.'.format(setting_name, path)

0 commit comments

Comments
 (0)