Skip to content
Snippets Groups Projects

Automatická oprava rozbitých PDF

Merged Martin Mareš requested to merge mj/auto-fix-jobs into devel
1 unresolved thread
1 file
+ 5
4
Compare changes
  • Side-by-side
  • Inline
+ 5
4
#!/usr/bin/env python3
import argparse
import datetime
import os
from sqlalchemy.orm import joinedload
import subprocess
@@ -29,7 +30,7 @@ def fix_paper(id: int):
.get(id))
assert paper is not None
assert paper.orig_file_name is not None
print(f"=== Paper #{id} ({paper.orig_file_name})")
print(f"=== Paper #{id} ({paper.orig_file_name}){' [RETRY]' if paper.fixed_at else ''}")
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])
@@ -37,16 +38,16 @@ def fix_paper(id: int):
sub = mo.submit.Submitter()
try:
sub.submit_fix(paper, tmp_file.name)
sess.commit()
fixed += 1
except mo.submit.SubmitException:
sess.rollback()
errors += 1
else:
print(f'--> ERROR: qpdf failed with exit code {res.returncode}')
sess.rollback()
errors += 1
paper.fixed_at = datetime.datetime.now()
sess.commit()
if args.id is not None:
fix_paper(args.id)
Loading