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
19beb3d3
Commit
19beb3d3
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Nový skript na opravování rozbitých submitů
parent
ecde2727
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/fix-submits
+19
-34
19 additions, 34 deletions
bin/fix-submits
with
19 additions
and
34 deletions
bin/fix-submits
+
19
−
34
View file @
19beb3d3
#!/usr/bin/env python3
#!/usr/bin/env python3
import
argparse
import
argparse
import
datetime
import
os
import
os
from
sqlalchemy.orm
import
joinedload
from
sqlalchemy.orm
import
joinedload
import
subprocess
import
subprocess
...
@@ -18,57 +17,43 @@ args = parser.parse_args()
...
@@ -18,57 +17,43 @@ args = parser.parse_args()
mo
.
util
.
init_standalone
()
mo
.
util
.
init_standalone
()
sess
=
db
.
get_session
()
sess
=
db
.
get_session
()
fixed
=
0
errors
=
0
def
fix_paper
(
id
:
int
):
def
fix_paper
(
id
:
int
):
global
fixed
,
errors
paper
=
(
sess
.
query
(
db
.
Paper
)
paper
=
(
sess
.
query
(
db
.
Paper
)
.
options
(
joinedload
(
db
.
Paper
.
for_user_obj
))
.
options
(
joinedload
(
db
.
Paper
.
for_user_obj
))
.
get
(
id
))
.
get
(
id
))
assert
paper
is
not
None
assert
paper
is
not
None
print
(
f
"
=== Paper #
{
id
}
(
{
paper
.
file_name
}
)
"
)
assert
paper
.
orig_file_name
is
not
None
print
(
f
"
=== Paper #
{
id
}
(
{
paper
.
orig_file_name
}
)
"
)
sol
=
(
sess
.
query
(
db
.
Solution
)
.
filter_by
(
task_id
=
paper
.
for_task
,
user_id
=
paper
.
for_user
)
.
one
())
if
paper
.
paper_id
not
in
[
sol
.
final_submit
,
sol
.
final_feedback
]:
print
(
'
--> not final
\n
'
)
sess
.
rollback
()
return
tmp_file
=
tempfile
.
NamedTemporaryFile
(
dir
=
mo
.
util
.
data_dir
(
'
tmp
'
),
prefix
=
'
fix-
'
)
tmp_file
=
tempfile
.
NamedTemporaryFile
(
dir
=
mo
.
util
.
data_dir
(
'
tmp
'
),
prefix
=
'
fix-
'
)
res
=
subprocess
.
run
([
'
qpdf
'
,
os
.
path
.
join
(
mo
.
util
.
data_dir
(
'
submits
'
),
paper
.
orig_file_name
),
tmp_file
.
name
])
res
=
subprocess
.
run
([
'
qpdf
'
,
os
.
path
.
join
(
mo
.
util
.
data_dir
(
'
submits
'
),
paper
.
file_name
),
tmp_file
.
name
])
if
res
.
returncode
in
[
0
,
3
]:
if
res
.
returncode
in
[
0
,
3
]:
sub
=
mo
.
submit
.
Submitter
()
sub
=
mo
.
submit
.
Submitter
()
new_paper
=
db
.
Paper
(
task
=
paper
.
task
,
try
:
for_user_obj
=
paper
.
for_user_obj
,
sub
.
submit_fix
(
paper
,
tmp_file
.
name
)
type
=
paper
.
type
,
uploaded_by_obj
=
paper
.
uploaded_by_obj
,
uploaded_at
=
paper
.
uploaded_at
+
datetime
.
timedelta
(
seconds
=
1
),
note
=
'
Automatická konverze rozbitého PDF
'
)
sub
.
submit_paper
(
new_paper
,
tmp_file
.
name
)
assert
not
new_paper
.
broken
sess
.
add
(
new_paper
)
if
new_paper
.
type
==
db
.
PaperType
.
solution
:
sol
.
final_submit_obj
=
new_paper
elif
new_paper
.
type
==
db
.
PaperType
.
feedback
:
sol
.
final_feedback_obj
=
new_paper
else
:
assert
False
print
(
'
--> OK
'
)
sess
.
commit
()
sess
.
commit
()
fixed
+=
1
except
mo
.
submit
.
SubmitException
:
sess
.
rollback
()
errors
+=
1
else
:
else
:
print
(
f
'
--> ERROR: qpdf failed with exit code
{
res
.
returncode
}
'
)
print
(
f
'
--> ERROR: qpdf failed with exit code
{
res
.
returncode
}
'
)
sess
.
rollback
()
sess
.
rollback
()
errors
+=
1
print
(
""
)
if
args
.
id
is
not
None
:
if
args
.
id
is
not
None
:
fix_paper
(
args
.
id
)
fix_paper
(
args
.
id
)
else
:
else
:
papers
=
sess
.
query
(
db
.
Paper
).
filter_by
(
broken
=
Tru
e
).
all
()
papers
=
sess
.
query
(
db
.
Paper
).
filter_by
(
file_name
=
Non
e
).
all
()
sess
.
rollback
()
sess
.
rollback
()
for
p
in
papers
:
for
p
in
papers
:
fix_paper
(
p
.
paper_id
)
fix_paper
(
p
.
paper_id
)
print
(
f
'
Opraveno
{
fixed
}
PDF, stále rozbito
{
errors
}
'
)
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