Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Merge requests
!14
Asynchronní joby
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Asynchronní joby
mj/jobs
into
devel
Overview
0
Commits
12
Changes
1
Merged
Martin Mareš
requested to merge
mj/jobs
into
devel
4 years ago
Overview
0
Commits
12
Changes
1
0
0
Merge request reports
Viewing commit
66986b5e
Show latest version
1 file
+
50
−
5
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
66986b5e
Job pro stahování řešení
· 66986b5e
Martin Mareš
authored
4 years ago
Dostává množinu papírů, které má zazipovat.
mo/jobs/submit.py
+
50
−
5
View file @ 66986b5e
Edit in single-file editor
Open in Web IDE
# Implementace jobů pracujících se submity
# Implementace jobů pracujících se submity
from
mo.util
import
logger
import
os
from
sqlalchemy.orm
import
joinedload
from
tempfile
import
NamedTemporaryFile
import
unicodedata
import
werkzeug.utils
import
zipfile
import
mo.config
as
config
from
mo.util
import
logger
,
data_dir
import
mo.db
as
db
import
mo.db
as
db
from
mo.jobs
import
TheJob
,
job_handler
from
mo.jobs
import
TheJob
,
job_handler
@job_handler
(
db
.
JobType
.
download_submits
)
@job_handler
(
db
.
JobType
.
download_submits
)
def
handle_download_submits
(
tj
:
TheJob
):
def
handle_download_submits
(
tj
:
TheJob
):
logger
.
debug
(
'
Entering download_submits
'
)
"""
Zazipuje zadané papíry.
pass
Vstupní JSON:
{
'
papers
'
: [ seznam paper_id ke stažení ] }
Výstupní JSON:
null
"""
job
=
tj
.
job
assert
job
.
in_json
is
not
None
# FIXME: Typování JSONu...
ids
=
job
.
in_json
[
'
papers
'
]
sess
=
db
.
get_session
()
papers
=
(
sess
.
query
(
db
.
Paper
)
.
filter
(
db
.
Paper
.
paper_id
.
in_
(
ids
))
.
options
(
joinedload
(
db
.
Paper
.
for_user_obj
),
joinedload
(
db
.
Paper
.
task
))
.
all
())
temp_file
=
NamedTemporaryFile
(
suffix
=
'
.zip
'
,
dir
=
data_dir
(
'
tmp
'
),
mode
=
'
w+b
'
)
logger
.
debug
(
'
Job: Vytvářím archiv %s
'
,
temp_file
.
name
)
cnt
=
0
with
zipfile
.
ZipFile
(
temp_file
,
mode
=
'
w
'
)
as
zip
:
for
p
in
papers
:
cnt
+=
1
full_name
=
p
.
for_user_obj
.
full_name
()
ascii_name
=
(
unicodedata
.
normalize
(
'
NFD
'
,
full_name
)
.
encode
(
'
ascii
'
,
'
ignore
'
)
.
decode
(
'
utf-8
'
))
fn
=
f
'
{
p
.
task
.
code
}
_
{
cnt
:
04
d
}
_
{
p
.
for_user
}
_
{
p
.
paper_id
}
_
{
ascii_name
}
.pdf
'
fn
=
werkzeug
.
utils
.
secure_filename
(
fn
)
logger
.
debug
(
'
Job: Přidávám %s
'
,
fn
)
zip
.
write
(
filename
=
os
.
path
.
join
(
data_dir
(
'
submits
'
),
p
.
file_name
),
arcname
=
fn
)
job
.
out_file
=
tj
.
attach_file
(
temp_file
.
name
,
'
.zip
'
)
temp_file
.
close
()
@job_handler
(
db
.
JobType
.
upload_feedback
)
@job_handler
(
db
.
JobType
.
upload_feedback
)
def
handle_upload_feedback
(
tj
:
TheJob
):
def
handle_upload_feedback
(
tj
:
TheJob
):
logger
.
debug
(
'
Entering upload_feedback
'
)
raise
NotImplementedError
()
pass
Loading