Skip to content
Snippets Groups Projects

Sazba diplomů

Merged Martin Mareš requested to merge diplomy into devel
1 file
+ 14
13
Compare changes
  • Side-by-side
  • Inline
+ 14
13
@@ -54,6 +54,9 @@ class CertMaker:
certs: List[Cert]
out_files: Dict[db.CertType, str]
qr_encoder: QREncoder
certs_dir: str
out_dir: str # relativní k certs_dir
job_dir: str # adresář jobu
def __init__(self, the_job: TheJob):
self.the_job = the_job
@@ -80,6 +83,10 @@ class CertMaker:
self.out_files = {}
self.qr_encoder = QREncoder(f'{self.job.dir_path()}/qr')
self.certs_dir = mo.util.data_dir('certs')
self.out_dir = os.path.join(self.round.round_code_short(), str(self.contest.contest_id))
self.job_dir = self.job.dir_path()
def plan(self) -> None:
sess = db.get_session()
pions_pants = (sess.query(db.Participation, db.Participant)
@@ -133,14 +140,13 @@ class CertMaker:
if not certs:
return
temp_dir = self.job.dir_path()
name = cert_type.file_name()
logger.debug(f'{self.the_job.log_prefix} Vytvářím certifikáty typu {name} v {temp_dir} ({len(certs)} listů)')
logger.debug(f'{self.the_job.log_prefix} Vytvářím certifikáty typu {name} v {self.job_dir} ({len(certs)} listů)')
certs.sort(key=lambda cert: cert.sort_key)
self.make_tex_source(f'{temp_dir}/{name}.tex', certs)
run_tex(temp_dir, f'{name}.tex')
self.out_files[cert_type] = f'{temp_dir}/{name}.pdf'
self.make_tex_source(f'{self.job_dir}/{name}.tex', certs)
run_tex(self.job_dir, f'{name}.tex')
self.out_files[cert_type] = f'{self.job_dir}/{name}.pdf'
def make_tex_source(self, filename: str, certs: List[Cert]) -> None:
with open(filename, 'w') as f:
@@ -199,11 +205,6 @@ class CertMaker:
sess = db.get_session()
conn = sess.connection()
certs_dir = mo.util.data_dir('certs')
out_dir = os.path.join(self.round.round_code_short(), str(self.contest.contest_id))
full_dir = os.path.join(certs_dir, out_dir)
os.makedirs(full_dir, exist_ok=True)
# Nejdříve smažeme už zbytečné soubory s QR kódy
self.qr_encoder.remove_all()
@@ -216,11 +217,11 @@ class CertMaker:
# Založíme nové soubory
for ctype, out_file in self.out_files.items():
file = mo.util.link_to_dir(out_file, full_dir, prefix=f'{ctype.file_name()}-', suffix='.pdf')
pdf_file = mo.util.link_to_dir(out_file, self.out_dir, base_dir=self.certs_dir, prefix=f'{ctype.file_name()}-', suffix='.pdf', make_dirs=True)
sess.add(db.CertFile(
cert_set_id=self.contest_id,
type=ctype,
pdf_file=os.path.join(out_dir, os.path.basename(file)),
pdf_file=pdf_file,
))
# Založíme nové certifikáty
@@ -253,7 +254,7 @@ class CertMaker:
# Nakonec smažeme staré soubory
for old_file in old_files:
mo.util.unlink_if_exists(os.path.join(certs_dir, old_file))
mo.util.unlink_if_exists(os.path.join(self.certs_dir, old_file))
@job_handler(db.JobType.create_certs)
Loading