Source code for uw.local.teaching.bin.submit_posting_pads
"""Automatic printing of PAC seating lookup posting pads.
Python process to print posting pads to help final examination candidates to
find their seats.
"""
from datetime import date
from pathlib import Path
from subprocess import check_output
from sys import argv
from tempfile import mkdtemp
import os.path
from uw.sql.wrap import open_psycopg2_db_service_cursor
from uw.local import termtools
from ...print_.db.nms_requisition import nms_requisition
from ..db.cursor import Cursor
[docs]def submit_posting_pads (cursor, term):
java_dir = mkdtemp ()
print(java_dir)
java_output = check_output (['java', 'ca.uwaterloo.odyssey.exams.preparePostingPads', term.code (), java_dir])
java_output = [int (i) for i in java_output.strip ().split (b'\n')]
timeslots = java_output[0]
pagecount = java_output[1:]
corner_pads = 2 * 2
corner_pages = corner_pads * timeslots
hall_pads = 2 * len (pagecount)
hall_pages = 2 * sum (pagecount)
total_pads = corner_pads + hall_pads
total_pages = corner_pages + hall_pages
job = nms_requisition (cursor)
print('job_id=%d' % job.job_id)
# **TODO: Obtain contact and accounting information from an admin unit
person_id = 30098361
job.set_contact (person_id)
job.set_flexfield ('60360 10000-10508 100')
job.set_title ('PAC Seating Lookup Signs %s' % term.abbreviation ())
job.set_date_required (cursor.execute_required_value ("select uw_business_day_offset (uw_this_prev_business_day (lower (term_exam_dates)), -1) from uw_term where term_id = %(term_id)s", term_id=term.code ()))
job.set_end_use ('teaching')
job.set_courier (person_id)
job.set_copyprint (
pages=total_pages,
copies=1,
simplex=True,
paper_bond=True,
size_ledger=True,
paper_white=True,
ink_black=True,
)
job.set_binding (padding=True)
job.set_instructions ('Please print 2 copies each of [SW]-door.pdf and 1 copy each of [SW]-page-*.pdf, and pad each copy along the top (long) edge. Final result %d pads.\n\nPage count: 2 * 2 * %d = %d; 2 * (%s) = %d; total %d.' % (total_pads, timeslots, corner_pages, ' + '.join ('%d' % p for p in pagecount), hall_pages, total_pages))
files = []
for corner in ['S', 'W']:
files.append ('%s-door.pdf' % corner)
for page in range (1, len (pagecount) + 1):
files.append ('%s-page-%d.pdf' % (corner, page))
java_dir = Path (java_dir)
for file in files:
job.attach_file (file, (java_dir / file).read_bytes ())
[docs]def main ():
term_code = argv[1]
cursor = open_psycopg2_db_service_cursor (cursor_class=Cursor)
submit_posting_pads (cursor, termtools.fromCode (term_code))
cursor.connection.commit ()