예제 #1
0
def init_exam(exam_date):
    """ To be called at the beginning of Jupyter exam sheets
        
        exam_date : exam date string in the format 'yyyy-mm-dd'
    """
    if exam_date != '_JM_(exam.date)':
        conf.parse_date(exam_date) # little hack so the template can work somewhat properly
    import sys
    sys.path.append('solutions/')
    sys.path.append('exercises/')
    return init('../../')
예제 #2
0
def expand_JM(source, target, exam_date):
    d = conf.parse_date(exam_date)
    sourcef = open(source, "r")
    s = sourcef.read()
    s = s.replace('_JM_(exam.date)', exam_date )
    s = s.replace('_JM_(exam.date_human)', d.strftime('%A %d, %B %Y') )
    for k in conf.__dict__:
        s = s.replace('_JM_(conf.' + k + ')', str(conf.__dict__[k]))
    p = re.compile('_JM_\([a-zA-Z][\w\.]*\)')
    if p.search(s):
        warn("FOUND _JM_ macros which couldn't be expanded!")
        print("               file: " + source)
        print("\n                 ".join(p.findall(s)))
        print("")
    destf = open(target, 'w')    
    destf.write(s)