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
Commits
d5f4c52b
Commit
d5f4c52b
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Submit používá link_to_dir a uchovává vadné soubory v data/errors/
parent
1e030420
Branches
Branches containing commit
No related tags found
1 merge request
!21
Reforma uploadů
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mo/submit.py
+6
-17
6 additions, 17 deletions
mo/submit.py
with
6 additions
and
17 deletions
mo/submit.py
+
6
−
17
View file @
d5f4c52b
...
@@ -2,7 +2,6 @@ import datetime
...
@@ -2,7 +2,6 @@ import datetime
import
multiprocessing
import
multiprocessing
import
os
import
os
import
pikepdf
import
pikepdf
import
secrets
import
werkzeug.utils
import
werkzeug.utils
import
mo.db
as
db
import
mo.db
as
db
...
@@ -30,10 +29,11 @@ class Submitter:
...
@@ -30,10 +29,11 @@ class Submitter:
logger
.
info
(
f
'
Submit: Hotovo: file=
{
paper
.
file_name
}
pages=
{
paper
.
pages
}
bytes=
{
paper
.
bytes
}
time=
{
duration
:
.
3
f
}
'
)
logger
.
info
(
f
'
Submit: Hotovo: file=
{
paper
.
file_name
}
pages=
{
paper
.
pages
}
bytes=
{
paper
.
bytes
}
time=
{
duration
:
.
3
f
}
'
)
except
SubmitException
as
e
:
except
SubmitException
as
e
:
duration
=
(
datetime
.
datetime
.
now
()
-
t_start
).
total_seconds
()
duration
=
(
datetime
.
datetime
.
now
()
-
t_start
).
total_seconds
()
logger
.
info
(
f
'
Submit: Chyba:
{
e
}
(time=
{
duration
:
.
3
f
}
)
'
)
preserved_as
=
mo
.
util
.
link_to_dir
(
tmpfile
,
mo
.
util
.
data_dir
(
'
errors
'
),
prefix
=
'
submit-
'
)
logger
.
info
(
f
'
Submit: Chyba:
{
e
}
(time=
{
duration
:
.
3
f
}
), uloženo do
{
preserved_as
}
'
)
raise
raise
def
_
create_file_name
(
self
,
paper
:
db
.
Paper
)
->
str
:
def
_
file_paper
(
self
,
paper
:
db
.
Paper
,
tmpfile
:
str
)
:
round
=
paper
.
task
.
round
round
=
paper
.
task
.
round
secure_category
=
werkzeug
.
utils
.
secure_filename
(
round
.
category
)
secure_category
=
werkzeug
.
utils
.
secure_filename
(
round
.
category
)
top_level
=
f
'
{
round
.
year
}
-
{
secure_category
}
-
{
round
.
seq
}
'
top_level
=
f
'
{
round
.
year
}
-
{
secure_category
}
-
{
round
.
seq
}
'
...
@@ -42,18 +42,11 @@ class Submitter:
...
@@ -42,18 +42,11 @@ class Submitter:
os
.
makedirs
(
sub_user_dir
,
exist_ok
=
True
)
os
.
makedirs
(
sub_user_dir
,
exist_ok
=
True
)
secure_task_code
=
werkzeug
.
utils
.
secure_filename
(
paper
.
task
.
code
)
secure_task_code
=
werkzeug
.
utils
.
secure_filename
(
paper
.
task
.
code
)
while
True
:
full_name
=
mo
.
util
.
link_to_dir
(
tmpfile
,
sub_user_dir
,
prefix
=
f
'
{
secure_task_code
}
-
{
paper
.
type
.
name
[
:
3
]
}
-
'
,
suffix
=
'
.pdf
'
)
nonce
=
secrets
.
token_hex
(
8
)
paper
.
file_name
=
os
.
path
.
join
(
user_dir
,
os
.
path
.
basename
(
full_name
))
file_name
=
f
'
{
secure_task_code
}
-
{
paper
.
type
.
name
[
:
3
]
}
-
{
nonce
}
.pdf
'
if
not
os
.
path
.
lexists
(
os
.
path
.
join
(
sub_user_dir
,
file_name
)):
break
logger
.
warning
(
f
'
Retrying file creation for
{
sub_user_dir
}
/
{
file_name
}
'
)
return
os
.
path
.
join
(
user_dir
,
file_name
)
def
_do_submit
(
self
,
paper
:
db
.
Paper
,
tmpfile
:
str
):
def
_do_submit
(
self
,
paper
:
db
.
Paper
,
tmpfile
:
str
):
# Zpracování PDF spustíme v samostatném procesu, aby bylo dostatečně oddělené
# Zpracování PDF spustíme v samostatném procesu, aby bylo dostatečně oddělené
# FIXME: Omezit paměť apod.
pipe_rx
,
pipe_tx
=
multiprocessing
.
Pipe
(
duplex
=
False
)
pipe_rx
,
pipe_tx
=
multiprocessing
.
Pipe
(
duplex
=
False
)
proc
=
multiprocessing
.
Process
(
name
=
'
submit
'
,
target
=
Submitter
.
_process_pdf
,
args
=
(
tmpfile
,
pipe_tx
))
proc
=
multiprocessing
.
Process
(
name
=
'
submit
'
,
target
=
Submitter
.
_process_pdf
,
args
=
(
tmpfile
,
pipe_tx
))
proc
.
start
()
proc
.
start
()
...
@@ -83,11 +76,7 @@ class Submitter:
...
@@ -83,11 +76,7 @@ class Submitter:
paper
.
bytes
=
os
.
path
.
getsize
(
tmpfile
)
paper
.
bytes
=
os
.
path
.
getsize
(
tmpfile
)
paper
.
pages
=
result
[
'
pages
'
]
paper
.
pages
=
result
[
'
pages
'
]
paper
.
file_name
=
self
.
_create_file_name
(
paper
)
self
.
_file_paper
(
paper
,
tmpfile
)
# FIXME: fsync?
dest
=
os
.
path
.
join
(
self
.
submit_dir
,
paper
.
file_name
)
os
.
rename
(
tmpfile
,
dest
)
# Zpracování PDF běží v samostatném procesu, výsledek pošle jako slovník rourou.
# Zpracování PDF běží v samostatném procesu, výsledek pošle jako slovník rourou.
def
_process_pdf
(
tmpfile
,
pipe
):
def
_process_pdf
(
tmpfile
,
pipe
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment