Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
e6a7b380
Verified
Commit
e6a7b380
authored
Jun 22, 2018
by
Peter Stanko
Browse files
Fixes in the pylint
parent
d8e62b44
Changes
66
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
e6a7b380
...
...
@@ -3,6 +3,7 @@
# https://hub.docker.com/r/library/python
image
:
python:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache
:
...
...
@@ -17,6 +18,9 @@ build:
tags
:
-
shared-fi
before_script
:
-
echo exit 0 > /usr/sbin/policy-rc.d
-
apt update && apt install -y redis-server
-
service redis-server start
-
python -V
# Print out python version for debugging
-
pip install pipenv
...
...
app.py
View file @
e6a7b380
...
...
@@ -61,7 +61,8 @@ def cli_init_data(env):
@
click
.
argument
(
'name'
)
def
cli_users_create
(
name
):
log
.
info
(
f
"[CMD] Create User:
{
name
}
"
)
password
=
click
.
prompt
(
'Password'
,
hide_input
=
True
,
confirmation_prompt
=
True
)
password
=
click
.
prompt
(
'Password'
,
hide_input
=
True
,
confirmation_prompt
=
True
)
user
=
manager
.
create_admin_user
(
name
,
password
)
log
.
info
(
f
"[CMD] Created User:
{
user
}
"
)
...
...
@@ -70,7 +71,8 @@ def cli_users_create(name):
@
click
.
argument
(
'name'
)
def
cli_users_set_password
(
name
):
log
.
info
(
f
"[CMD] Update password for user:
{
name
}
"
)
password
=
click
.
prompt
(
'Password'
,
hide_input
=
True
,
confirmation_prompt
=
True
)
password
=
click
.
prompt
(
'Password'
,
hide_input
=
True
,
confirmation_prompt
=
True
)
user
=
manager
.
update_users_password
(
name
,
password
)
log
.
info
(
f
"[CMD] Updated password for user:
{
user
}
"
)
...
...
@@ -104,7 +106,8 @@ def cli_course_creates(name):
log
.
info
(
f
"[CMD] Created Course:
{
course
}
"
)
@
courses_cli
.
command
(
'create-role'
,
help
=
"Creates role by it's type in the course"
)
@
courses_cli
.
command
(
'create-role'
,
help
=
"Creates role by it's type in the course"
)
@
click
.
argument
(
'course'
)
@
click
.
argument
(
'type'
)
@
click
.
argument
(
'name'
,
required
=
False
)
...
...
management/data/__init__.py
View file @
e6a7b380
...
...
@@ -75,7 +75,7 @@ class DataManagement(object):
name
=
name
,
admin
=
True
,
password
=
password
)
)
self
.
db
.
session
.
commit
()
return
user
...
...
@@ -100,7 +100,8 @@ class DataManagement(object):
"""
with
self
.
app
.
app_context
():
course
=
general
.
find_course
(
course_name
)
role
=
self
.
creator
.
scaffold_role
(
course
,
role_type
=
role_type
,
name
=
name
)
role
=
self
.
creator
.
scaffold_role
(
course
,
role_type
=
role_type
,
name
=
name
)
self
.
db
.
session
.
commit
()
return
role
...
...
@@ -108,4 +109,3 @@ class DataManagement(object):
with
self
.
app
.
app_context
():
for
user
in
User
.
query
.
all
():
print
(
f
"
{
user
.
username
}
(
{
user
.
id
}
) -
{
user
.
created_at
}
"
)
management/data/data_dev.py
View file @
e6a7b380
...
...
@@ -14,11 +14,12 @@ def get_project(factory: DataFactory, course: Course, num: int):
post_submit_script
=
"python for kontr post"
,
submission_scheduler_config
=
"python for sub Q"
,
submission_parameters
=
"{
\"
type
\"
:
\"
text
\"
}"
,
submissions_allowed_from
=
time
.
NOW
(),
submissions_allowed_to
=
time
.
NOW
()
+
timedelta
(
days
=
2
),
archive_from
=
time
.
NOW
()
+
timedelta
(
days
=
30
)
)
return
factory
.
create_project
(
course
=
course
,
name
=
f
"HW0
{
num
}
"
,
config
=
project_config
)
submissions_allowed_from
=
time
.
current_time
(),
submissions_allowed_to
=
time
.
current_time
()
+
timedelta
(
days
=
2
),
archive_from
=
time
.
current_time
()
+
timedelta
(
days
=
30
)
)
return
factory
.
create_project
(
course
=
course
,
name
=
f
"HW0
{
num
}
"
,
config
=
project_config
)
def
init_dev_data
(
app
:
Flask
,
db
:
SQLAlchemy
):
...
...
@@ -36,20 +37,26 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
name
=
'Courses Owner'
,
password
=
'654321'
,
uco
=
1010
)
)
db
.
session
.
commit
()
# courses
test_course1
=
factory
.
create_course
(
codename
=
'TestCourse1'
,
name
=
'Test Course One'
)
test_course2
=
factory
.
create_course
(
codename
=
'TestCourse2'
,
name
=
'test Course Two'
)
test_course1
=
factory
.
create_course
(
codename
=
'TestCourse1'
,
name
=
'Test Course One'
)
test_course2
=
factory
.
create_course
(
codename
=
'TestCourse2'
,
name
=
'test Course Two'
)
# groups
tc1_students
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"seminar01"
)
tc1_teachers
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"teachers"
)
tc1_students
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"seminar01"
)
tc1_teachers
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"teachers"
)
tc2_students
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"seminar01"
)
tc2_teachers
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"teachers"
)
tc2_students
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"seminar01"
)
tc2_teachers
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"teachers"
)
tc1_hw01
=
get_project
(
factory
=
factory
,
course
=
test_course1
,
num
=
1
)
tc1_hw03
=
get_project
(
factory
=
factory
,
course
=
test_course1
,
num
=
3
)
...
...
@@ -60,11 +67,11 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
post_submit_script
=
"python for kontr post"
,
submission_scheduler_config
=
"python for sub Q"
,
submission_parameters
=
"{
\"
type
\"
:
\"
text
\"
}"
,
submissions_allowed_from
=
time
.
NOW
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
NOW
()
+
timedelta
(
days
=
10
),
archive_from
=
time
.
NOW
()
+
timedelta
(
days
=
30
)
)
submissions_allowed_from
=
time
.
current_time
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
current_time
()
+
timedelta
(
days
=
10
),
archive_from
=
time
.
current_time
()
+
timedelta
(
days
=
30
)
)
)
tc2_hw01
=
factory
.
create_project
(
course
=
test_course2
,
name
=
"HW01"
,
config
=
dict
(
...
...
@@ -72,20 +79,26 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
post_submit_script
=
"python for kontr post"
,
submission_scheduler_config
=
"python for sub Q"
,
submission_parameters
=
"{
\"
type
\"
:
\"
text
\"
}"
,
submissions_allowed_from
=
time
.
NOW
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
NOW
()
-
timedelta
(
minutes
=
1
),
archive_from
=
time
.
NOW
()
+
timedelta
(
days
=
30
)
)
submissions_allowed_from
=
time
.
current_time
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
current_time
()
-
timedelta
(
minutes
=
1
),
archive_from
=
time
.
current_time
()
+
timedelta
(
days
=
30
)
)
)
# roles
tc1_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course1
)
tc1_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course1
)
tc1_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course1
)
tc2_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course2
)
tc2_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course2
)
tc2_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course2
)
tc1_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course1
)
tc1_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course1
)
tc1_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course1
)
tc2_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course2
)
tc2_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course2
)
tc2_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course2
)
# roles
lecturer1
.
roles
.
append
(
tc1_owner
)
...
...
@@ -112,13 +125,17 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
tc2_sub2
=
Submission
(
user
=
student2
,
project
=
tc2_hw01
,
parameters
=
""
)
tc2_sub2
.
state
=
SubmissionState
.
ABORTED
tc1_sub_p1_cancel
=
Submission
(
user
=
student2
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_cancel
=
Submission
(
user
=
student2
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_cancel
.
state
=
SubmissionState
.
CANCELLED
tc1_sub_p1_abort
=
Submission
(
user
=
student1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_abort
=
Submission
(
user
=
student1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_abort
.
state
=
SubmissionState
.
ABORTED
tc1_sub_p1_finished
=
Submission
(
user
=
student2
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_finished
=
Submission
(
user
=
student2
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_finished
.
state
=
SubmissionState
.
FINISHED
tc1_sub_p1_in_progress
=
Submission
(
user
=
student1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_in_progress
=
Submission
(
user
=
student1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_in_progress
.
state
=
SubmissionState
.
IN_PROGRESS
# Projects in groups
...
...
@@ -143,7 +160,8 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
# components
factory
.
create_component
(
name
=
'executor'
)
factory
.
create_component
(
name
=
'processing'
,
component_type
=
'processing'
)
factory
.
create_component
(
name
=
'processing'
,
component_type
=
'processing'
)
# Commit to the DB
db
.
session
.
commit
()
management/data/data_test.py
View file @
e6a7b380
...
...
@@ -22,18 +22,24 @@ def init_test_data(app: Flask, db: SQLAlchemy):
name
=
'Courses Owner'
,
password
=
'654321'
,
uco
=
1010
)
)
# courses
test_course1
=
factory
.
create_course
(
codename
=
'TestCourse1'
,
name
=
'Test Course One'
)
test_course2
=
factory
.
create_course
(
codename
=
'TestCourse2'
,
name
=
'test Course Two'
)
test_course1
=
factory
.
create_course
(
codename
=
'TestCourse1'
,
name
=
'Test Course One'
)
test_course2
=
factory
.
create_course
(
codename
=
'TestCourse2'
,
name
=
'test Course Two'
)
# groups
tc1_students
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"seminar01"
)
tc1_teachers
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"teachers"
)
tc1_students
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"seminar01"
)
tc1_teachers
=
factory
.
create_group
(
course
=
test_course1
,
name
=
"teachers"
)
tc2_students
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"seminar01"
)
tc2_teachers
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"teachers"
)
tc2_students
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"seminar01"
)
tc2_teachers
=
factory
.
create_group
(
course
=
test_course2
,
name
=
"teachers"
)
tc1_hw01
=
factory
.
create_project
(
course
=
test_course1
,
name
=
"HW01"
,
config
=
dict
(
...
...
@@ -42,11 +48,11 @@ def init_test_data(app: Flask, db: SQLAlchemy):
post_submit_script
=
"python for kontr post"
,
submission_scheduler_config
=
"python for sub Q"
,
submission_parameters
=
"{
\"
type
\"
:
\"
text
\"
}"
,
submissions_allowed_from
=
time
.
NOW
(),
submissions_allowed_to
=
time
.
NOW
()
+
timedelta
(
days
=
2
),
archive_from
=
time
.
NOW
()
+
timedelta
(
days
=
30
)
)
submissions_allowed_from
=
time
.
current_time
(),
submissions_allowed_to
=
time
.
current_time
()
+
timedelta
(
days
=
2
),
archive_from
=
time
.
current_time
()
+
timedelta
(
days
=
30
)
)
)
tc1_hw02
=
factory
.
create_project
(
course
=
test_course1
,
name
=
"HW02"
,
config
=
dict
(
file_whitelist
=
"main.cpp
\n
func.hpp
\n
func.cpp"
,
...
...
@@ -54,11 +60,11 @@ def init_test_data(app: Flask, db: SQLAlchemy):
post_submit_script
=
"python for kontr post"
,
submission_scheduler_config
=
"python for sub Q"
,
submission_parameters
=
"{
\"
type
\"
:
\"
text
\"
}"
,
submissions_allowed_from
=
time
.
NOW
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
NOW
()
+
timedelta
(
days
=
10
),
archive_from
=
time
.
NOW
()
+
timedelta
(
days
=
30
)
)
submissions_allowed_from
=
time
.
current_time
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
current_time
()
+
timedelta
(
days
=
10
),
archive_from
=
time
.
current_time
()
+
timedelta
(
days
=
30
)
)
)
tc2_hw01
=
factory
.
create_project
(
course
=
test_course2
,
name
=
"HW01"
,
config
=
dict
(
...
...
@@ -66,20 +72,26 @@ def init_test_data(app: Flask, db: SQLAlchemy):
post_submit_script
=
"python for kontr post"
,
submission_scheduler_config
=
"python for sub Q"
,
submission_parameters
=
"{
\"
type
\"
:
\"
text
\"
}"
,
submissions_allowed_from
=
time
.
NOW
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
NOW
()
-
timedelta
(
minutes
=
1
),
archive_from
=
time
.
NOW
()
+
timedelta
(
days
=
30
)
)
submissions_allowed_from
=
time
.
current_time
()
-
timedelta
(
days
=
1
),
submissions_allowed_to
=
time
.
current_time
()
-
timedelta
(
minutes
=
1
),
archive_from
=
time
.
current_time
()
+
timedelta
(
days
=
30
)
)
)
# roles
tc1_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course1
)
tc1_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course1
)
tc1_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course1
)
tc2_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course2
)
tc2_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course2
)
tc2_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course2
)
tc1_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course1
)
tc1_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course1
)
tc1_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course1
)
tc2_student
=
factory
.
scaffold_role
(
role_type
=
'student'
,
course
=
test_course2
)
tc2_teacher
=
factory
.
scaffold_role
(
role_type
=
'teacher'
,
course
=
test_course2
)
tc2_owner
=
factory
.
scaffold_role
(
role_type
=
'owner'
,
course
=
test_course2
)
# relationships
teacher_student
=
teacher1
...
...
@@ -106,18 +118,24 @@ def init_test_data(app: Flask, db: SQLAlchemy):
student_both
.
groups
.
append
(
tc2_students
)
# submissions
tc2_sub1
=
Submission
(
user
=
teacher_student
,
project
=
tc2_hw01
,
parameters
=
""
)
tc2_sub1
=
Submission
(
user
=
teacher_student
,
project
=
tc2_hw01
,
parameters
=
""
)
tc2_sub1
.
state
=
SubmissionState
.
FINISHED
tc2_sub2
=
Submission
(
user
=
student_both
,
project
=
tc2_hw01
,
parameters
=
""
)
tc2_sub2
=
Submission
(
user
=
student_both
,
project
=
tc2_hw01
,
parameters
=
""
)
tc2_sub2
.
state
=
SubmissionState
.
ABORTED
tc1_sub_p1_cancel
=
Submission
(
user
=
student_both
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_cancel
=
Submission
(
user
=
student_both
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_cancel
.
state
=
SubmissionState
.
CANCELLED
tc1_sub_p1_abort
=
Submission
(
user
=
student_tc1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_abort
=
Submission
(
user
=
student_tc1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_abort
.
state
=
SubmissionState
.
ABORTED
tc1_sub_p1_finished
=
Submission
(
user
=
student_both
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_finished
=
Submission
(
user
=
student_both
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_finished
.
state
=
SubmissionState
.
FINISHED
tc1_sub_p1_in_progress
=
Submission
(
user
=
student_tc1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_in_progress
=
Submission
(
user
=
student_tc1
,
project
=
tc1_hw01
,
parameters
=
""
)
tc1_sub_p1_in_progress
.
state
=
SubmissionState
.
IN_PROGRESS
# Projects in groups
...
...
@@ -141,10 +159,8 @@ def init_test_data(app: Flask, db: SQLAlchemy):
# components
factory
.
create_component
(
name
=
'executor'
)
factory
.
create_component
(
name
=
'processing'
,
component_type
=
'processing'
)
factory
.
create_component
(
name
=
'processing'
,
component_type
=
'processing'
)
# Commit to the DB
db
.
session
.
commit
()
management/data/shared.py
View file @
e6a7b380
...
...
@@ -38,14 +38,14 @@ PERM_TEACHER = dict(
resubmit_submissions
=
True
,
evaluate_submissions
=
True
,
write_reviews_all
=
True
)
)
PERM_STUDENT
=
dict
(
view_course_limited
=
True
,
create_submissions
=
True
,
read_submissions_own
=
True
,
write_reviews_own
=
True
)
)
PERM_OWNER
=
dict
(
view_course_full
=
True
,
...
...
@@ -61,13 +61,13 @@ PERM_OWNER = dict(
read_submissions_all
=
True
,
read_all_submission_files
=
True
,
write_reviews_all
=
True
)
)
PERMISSION_TYPES
=
dict
(
teacher
=
PERM_TEACHER
,
student
=
PERM_STUDENT
,
owner
=
PERM_OWNER
,
)
)
class
DataFactory
(
object
):
...
...
@@ -82,7 +82,8 @@ class DataFactory(object):
email
=
None
,
admin
=
False
)
->
User
:
email
=
email
or
f
"
{
username
}
@example.com"
password
=
password
or
"123456"
user
=
self
.
__create_entity
(
User
,
uco
=
uco
,
username
=
username
,
is_admin
=
admin
,
email
=
email
)
user
=
self
.
__create_entity
(
User
,
uco
=
uco
,
username
=
username
,
is_admin
=
admin
,
email
=
email
)
user
.
name
=
name
or
f
"
{
username
.
capitalize
()
}
User"
user
.
set_password
(
password
=
password
)
return
user
...
...
@@ -95,7 +96,7 @@ class DataFactory(object):
name
=
'Kontr Admin'
,
uco
=
0
,
admin
=
True
,
)
)
def
__create_entity
(
self
,
klass
,
*
args
,
**
kwargs
):
entity
=
klass
(
*
args
,
**
kwargs
)
...
...
@@ -108,18 +109,20 @@ class DataFactory(object):
secret
=
secret
or
f
"
{
name
}
_secret"
notes
=
notes
or
f
"Component
{
name
}
of type
{
type
}
"
return
self
.
__create_entity
(
Component
,
name
=
name
,
secret
=
secret
,
ip_address
=
ip_addr
,
notes
=
notes
,
type
=
component_type
)
ip_address
=
ip_addr
,
notes
=
notes
,
component_
type
=
component_type
)
def
create_course
(
self
,
codename
,
name
=
None
,
token
=
None
)
->
Course
:
name
=
name
or
codename
desc
=
name
+
"'s description"
course
=
self
.
__create_entity
(
Course
,
codename
=
codename
,
name
=
name
,
description
=
desc
)
course
=
self
.
__create_entity
(
Course
,
codename
=
codename
,
name
=
name
,
description
=
desc
)
course
.
notes_access_token
=
token
or
f
"
{
codename
}
_token"
return
course
def
create_group
(
self
,
course
:
Course
,
name
:
str
)
->
Group
:
desc
=
name
+
"'s description"
return
self
.
__create_entity
(
Group
,
course
=
course
,
name
=
name
,
description
=
desc
)
return
self
.
__create_entity
(
Group
,
course
=
course
,
name
=
name
,
description
=
desc
)
def
create_role
(
self
,
course
:
Course
,
name
:
str
,
permissions
:
dict
=
None
,
desc
:
str
=
None
)
->
Role
:
...
...
@@ -129,7 +132,8 @@ class DataFactory(object):
role
.
description
=
desc
or
f
"
{
name
.
capitalize
()
}
's role"
return
role
def
create_project
(
self
,
course
,
name
,
test_files_source
=
None
,
config
=
None
)
->
Project
:
def
create_project
(
self
,
course
,
name
,
test_files_source
=
None
,
config
=
None
)
->
Project
:
test_files_source
=
test_files_source
or
f
"git://
{
name
}
.repo"
config
=
config
or
{}
desc
=
name
+
"'s description"
...
...
@@ -139,7 +143,8 @@ class DataFactory(object):
project
.
set_config
(
**
config
)
return
project
def
create_review_item
(
self
,
review
,
author
,
file
=
"main.c"
,
line
=
1
,
content
=
"problem here"
):
def
create_review_item
(
self
,
review
,
author
,
file
=
"main.c"
,
line
=
1
,
content
=
"problem here"
):
return
self
.
__create_entity
(
ReviewItem
,
review
=
review
,
user
=
author
,
file
=
file
,
line
=
line
,
content
=
content
)
...
...
@@ -154,5 +159,6 @@ class DataFactory(object):
def
scaffold_role
(
self
,
course
:
Course
,
role_type
:
str
,
name
=
None
)
->
Role
:
name
=
name
or
role_type
permissions
=
PERMISSION_TYPES
[
role_type
]
role
=
self
.
create_role
(
course
=
course
,
name
=
name
,
permissions
=
permissions
)
role
=
self
.
create_role
(
course
=
course
,
name
=
name
,
permissions
=
permissions
)
return
role
migrations/env.py
View file @
e6a7b380
...
...
@@ -81,6 +81,7 @@ def run_migrations_online():
finally
:
connection
.
close
()
if
context
.
is_offline_mode
():
run_migrations_offline
()
else
:
...
...
migrations/versions/c30ed4861044_.py
View file @
e6a7b380
...
...
@@ -20,10 +20,14 @@ def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op
.
add_column
(
'course'
,
sa
.
Column
(
'description'
,
sa
.
Text
(),
nullable
=
True
))
op
.
add_column
(
'group'
,
sa
.
Column
(
'description'
,
sa
.
Text
(),
nullable
=
True
))
op
.
add_column
(
'project'
,
sa
.
Column
(
'assignment_url'
,
sa
.
Text
(),
nullable
=
True
))
op
.
add_column
(
'projectConfig'
,
sa
.
Column
(
'submissions_cancellation_period'
,
sa
.
Integer
(),
nullable
=
True
))
op
.
add_column
(
'submission'
,
sa
.
Column
(
'process_task_id'
,
sa
.
String
(
length
=
36
),
nullable
=
True
))
op
.
add_column
(
'submission'
,
sa
.
Column
(
'storage_task_id'
,
sa
.
String
(
length
=
36
),
nullable
=
True
))
op
.
add_column
(
'project'
,
sa
.
Column
(
'assignment_url'
,
sa
.
Text
(),
nullable
=
True
))
op
.
add_column
(
'projectConfig'
,
sa
.
Column
(
'submissions_cancellation_period'
,
sa
.
Integer
(),
nullable
=
True
))
op
.
add_column
(
'submission'
,
sa
.
Column
(
'process_task_id'
,
sa
.
String
(
length
=
36
),
nullable
=
True
))
op
.
add_column
(
'submission'
,
sa
.
Column
(
'storage_task_id'
,
sa
.
String
(
length
=
36
),
nullable
=
True
))
# ### end Alembic commands ###
...
...
migrations/versions/f2cb9f5ed836_.py
View file @
e6a7b380
This diff is collapsed.
Click to expand it.
portal/__init__.py
View file @
e6a7b380
...
...
@@ -4,6 +4,7 @@ Main Portal module
import
logging
import
os
from
typing
import
Union
from
celery
import
Celery
from
flask
import
Flask
from
flask_cors
import
CORS
...
...
@@ -12,7 +13,6 @@ from flask_migrate import Migrate
from
flask_oauthlib.client
import
OAuth
from
flask_sqlalchemy
import
SQLAlchemy
from
storage
import
Storage
from
typing
import
Union
from
portal
import
rest
from
portal.config
import
CONFIGURATIONS
...
...
@@ -30,7 +30,8 @@ gitlab_factory = GitlabFactory()
log
=
logging
.
getLogger
(
__name__
)
def
configure_app
(
app
:
Flask
,
env
:
str
=
None
,
ignore_local
:
bool
=
False
)
->
Flask
:
def
configure_app
(
app
:
Flask
,
env
:
str
=
None
,
ignore_local
:
bool
=
False
)
->
Flask
:
"""Configures the Flask app based on production stage.
Args:
...
...
@@ -64,7 +65,7 @@ def configure_storage(app: Flask) -> Flask:
test_files_dir
=
app
.
config
.
get
(
'PORTAL_STORAGE_TEST_FILES_DIR'
),
submissions_dir
=
app
.
config
.
get
(
'PORTAL_STORAGE_SUBMISSIONS_DIR'
),
workspace_dir
=
app
.
config
.
get
(
'PORTAL_STORAGE_WORKSPACE_DIR'
)
)
)
storage
.
init_storage
(
**
storage_config
)
return
app
...
...
@@ -109,6 +110,5 @@ def create_app(environment: str = None):
def
get_celery
(
app
:
Flask
)
->
Union
[
Celery
,
None
]:
if
not
app
.
config
.
get
(
'BROKER_URL'
):
return
None
else
:
from
portal.async
import
celery
return
celery
from
portal.async
import
celery_app
return
celery_app
portal/async/__init__.py
View file @
e6a7b380
from
celery
import
Celery
from
flask
import
Flask
celery
=
Celery
()
celery
_app
=
Celery
()
def
init_app
(
app
:
Flask
)
->
Flask
:
"""Initializes the async module
Args:
app(Flask): Flask application
Returns(Flask): Flask application
"""
if
app
.
config
.
get
(
'BROKER_URL'
):
celery
.
conf
.
update
(
app
.
config
)
celery
_app
.
conf
.
update
(
app
.
config
)
class
ContextTask
(
celery
.
Task
):
# pylint: disable=too-few-public-methods
class
ContextTask
(
celery_app
.
Task
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
with
app
.
app_context
():
return
self
.
run
(
*
args
,
**
kwargs
)
celery
.
Task
=
ContextTask
# pylint: enable=too-few-public-methods
celery_app
.
Task
=
ContextTask
return
app
portal/async/enqueue.py
View file @
e6a7b380
import
logging
from
celery.worker.control
import
revoke
from
portal.async
import
celery_app
from
portal.async.helpers
import
reset_task_id
from
portal.database.models
import
Submission
,
SubmissionState
from
portal.service.general
import
write_entity
log
=
logging
.
getLogger
(
__name__
)
def
_reset_task_id
(
submission
:
Submission
,
state
=
None
):
if
state
is
not
None
:
submission
.
state
=
state
submission
.
process_task_id
=
None
write_entity
(
submission
)
def
submission_enqueue_ended
(
submission
:
Submission
):
# TODO: TBD
log
.
info
(
f
"[ASYNC] Submission enqueue ended:
{
submission
}
"
)
_reset_task_id
(
submission
=
submission
,
state
=
SubmissionState
.
QUEUED
)
reset_task_id
(
submission
=
submission
,
task_id_type
=
'process_task_id'
,
state
=
SubmissionState
.
QUEUED
)
def
revoke_enqueue_task
(
submission
:
Submission
):
log
.
info
(
f
'[ASYNC] Submission storage upload cancelled
{
submission
}
'
)
task_id
=
submission
.
process_task_id
if
task_id
:
revoke
(
task_id
,
terminate
=
True
)
_reset_task_id
(
submission
=
submission
,
state
=
SubmissionState
.
CANCELLED
)
celery_app
.
control
.
revoke
(
task_id
=
task_id
,
terminate
=
True
)
reset_task_id
(
submission
=
submission
,
task_id_type
=
'process_task_id'
,
state
=
SubmissionState
.
CANCELLED
)
portal/async/helpers.py
0 → 100644
View file @
e6a7b380