def deploy(exam, json, roster, default_deadline): """ Deploy an exam to the website. You must specify an exam JSON and associated roster CSV. You can deploy the JSON multiple times and the password will remain unchanged. """ json = json.read() roster = csv.reader(roster, delimiter=",") json = loads(json) json["default_deadline"] = default_deadline json["secret"] = Fernet.generate_key().decode("utf-8") try: json["secret"] = get_exam(exam=exam)["secret"] except: pass set_exam(exam=exam, json=json) next(roster) # ditch headers set_roster(exam=exam, roster=list(roster)) print("Exam uploaded with password:"******"secret"][:-1])
def deploy(exam, json, roster, start_time, default_deadline): """ Deploy an exam to the website. You must specify an exam JSON and associated roster CSV. You can deploy the JSON multiple times and the password will remain unchanged. """ json = json.read() roster = csv.reader(roster, delimiter=",") exam_content = loads(json) exam_content["default_deadline"] = default_deadline exam_content["secret"] = Fernet.generate_key().decode("utf-8") try: exam_content["secret"] = get_exam(exam=exam)["secret"] except: pass set_exam(exam=exam, json=exam_content) next(roster) # ditch headers roster = list(roster) set_roster(exam=exam, roster=roster) print("Exam uploaded with password:"******"secret"][:-1]) print("Exam deployed to https://exam.cs61a.org/{}".format(exam)) print("Initializing announcements...") elements = list(extract_questions(exam_content, include_groups=True)) for element in elements: element["id"] = element.get("id", rand_id()) # add IDs to groups elements = { element["id"]: get_name(element) for element in elements if element["type"] != "group" or not is_compressible_group(element) } json = dumps(exam_content) # re-serialize with group IDs students = [{ "email": email, "questions": [{ "start_time": start_time, "end_time": int(deadline), "student_question_name": get_name(element), "canonical_question_name": elements[element["id"]], } for element in list( extract_questions(scramble(email, loads(json)), include_groups=True))], "start_time": start_time, "end_time": int(deadline), } for email, deadline in roster] print("Updating announcements roster with {} students...".format( len(students))) for i in range(0, len(students), 100): print("Uploading from student #{} to #{}".format( i, min(i + 100, len(students)))) process_ok_exam_upload( exam=exam, data={ "students": students[i:i + 100], "questions": [{ "canonical_question_name": name } for name in elements.values()], }, clear=i == 0, ) print("Announcements deployed to https://announcements.cs61a.org")
def deploy(exam, json, roster, start_time, enable_clarifications): """ Deploy an exam to the website. You must specify an exam JSON and associated roster CSV. You can deploy the JSON multiple times and the password will remain unchanged. """ json = json.read() roster = csv.reader(roster, delimiter=",") exam_content = loads(json) exam_content["default_deadline"] = 0 exam_content["secret"] = Fernet.generate_key().decode("utf-8") try: old_secret = get_exam(exam=exam)["secret"] if old_secret: print("Reusing old secret...") exam_content["secret"] = old_secret except Exception: pass set_exam(exam=exam, json=exam_content) roster = list(roster) if not verify_roster(roster=roster): exit(1) roster = roster[1:] # ditch headers set_roster(exam=exam, roster=roster) print("Exam uploaded with password:"******"secret"][:-1]) print("Exam deployed to https://exam.cs61a.org/{}".format(exam)) print("Initializing announcements...") elements = list(extract_questions(exam_content, include_groups=True)) for element in elements: element["id"] = element.get("id", rand_id()) # add IDs to groups elements = { element["id"]: get_name(element) for element in elements if element["type"] != "group" or not is_compressible_group(element) } students = [ { "email": email, "start_time": start_time, "end_time": int(deadline), "no_watermark": bool(int(rest[0]) if rest else False), } for email, deadline, *rest in roster ] print("Updating announcements roster with {} students...".format(len(students))) process_ok_exam_upload( exam=exam, data={ "students": students, "questions": [ {"canonical_question_name": name} for name in elements.values() ], }, clear=True, enable_clarifications=enable_clarifications, ) print("Announcements deployed to https://announcements.cs61a.org")