Example #1
0
def PostProcessing():
    '''This routine is called by the server to bring configuration options
into a usable form. Some values are changed into other data types.'''
    try:
        l = map(string.strip, conf['Resolutions'].split(','))
        conf['Resolutions'] = map(int, l)
    except:
        Utils.Error('Value of "Resolutions" option must be a comma-separated' +
                    ' list of positive integers.')
        FailMiserably()
    try:
        conf['IdCheckRegExp'] = re.compile(conf['IdCheckRegExp'])
    except:
        Utils.Error('Regular expression in "IdCheckRegExp" cannot be '
                    'compiled.')
        etype, value, tb = sys.exc_info()
        lines = traceback.format_exception(etype, value, tb)
        Utils.Error(string.join(lines), prefix="")
        FailMiserably()
    if not (conf.has_key('GuestIdRegExp')):
        conf['GuestIdRegExp'] = '^$'  # matches only the empty string
    try:
        conf['GuestIdRegExp'] = re.compile(conf['GuestIdRegExp'])
    except:
        Utils.Error('Regular expression in "GuestIdRegExp" cannot be '
                    'compiled.')
        etype, value, tb = sys.exc_info()
        lines = traceback.format_exception(etype, value, tb)
        Utils.Error(string.join(lines), prefix="")
        FailMiserably()
    try:
        conf['GeneralMessages'] = Utils.StringFile(conf['GeneralMessageFile'])
    except:
        Utils.Error(
            'Cannot read general messages for results pages, assuming'
            ' no messages.',
            prefix="Warning:")
        conf['GeneralMessages'] = ''
        traceback.print_exc()
    for i in range(len(conf['AccessList'])):
        s = conf['AccessList'][i]
        try:
            pos = s.find('/')
            if pos < 0:
                Utils.Error('Range in AccessList must contain a slash:\n' + s)
                FailMiserably()
            # Handle a bug in Python 2.2:
            if s[pos + 1:] == '255.255.255.255':
                conf['AccessList'][i] = (socket.inet_aton(s[:pos]),
                                         '\xff\xff\xff\xff')
            else:
                conf['AccessList'][i] = (socket.inet_aton(s[:pos]),
                                         socket.inet_aton(s[pos + 1:]))
        except:
            traceback.print_exc()
            Utils.Error('Cannot parse IP range for AccessList: ' + s)
            FailMiserably()
    for i in range(len(conf['AdministrationAccessList'])):
        s = conf['AdministrationAccessList'][i]
        try:
            pos = s.find('/')
            if pos < 0:
                Utils.Error('Range in AdministrationAccessList must contain '
                            'a slash:\n' + s)
                FailMiserably()
            # Handle a bug in Python 2.2:
            if s[pos + 1:] == '255.255.255.255':
                conf['AdministrationAccessList'][i] = \
                      (socket.inet_aton(s[:pos]),'\xff\xff\xff\xff')
            else:
                conf['AdministrationAccessList'][i] = \
                      (socket.inet_aton(s[:pos]),socket.inet_aton(s[pos+1:]))
        except:
            traceback.print_exc()
            Utils.Error(
                'Cannot parse IP range for AdministrationAccessList: ' + s)
            FailMiserably()
    # Give a default for Header:
    if not (conf.has_key('Header')):
        conf['Header'] = ''
    # Give a default for Footer:
    if not (conf.has_key('Footer')):
        conf['Footer'] = ''
    # Give a default for MaxStringInputLength:
    if not (conf.has_key('MaxStringInputLength')):
        conf['MaxStringInputLength'] = 20
    # Give a default for InteractiveMode:
    if not (conf.has_key('InteractiveMode')):
        conf['InteractiveMode'] = 0
    # Give a default for RestrictToOwnGroup:
    if not (conf.has_key('RestrictToOwnGroup')):
        conf['RestrictToOwnGroup'] = 1
    # Give a default for MCScoreCorrectDefault:
    if not (conf.has_key('MCScoreCorrectDefault')):
        conf['MCScoreCorrectDefault'] = 1
    # Give a default for MCScoreWrongDefault:
    if not (conf.has_key('MCScoreWrongDefault')):
        conf['MCScoreWrongDefault'] = -1
    # Give a default for MCScoreExerciseLowerLimitDefault:
    if not (conf.has_key('MCScoreExerciseLowerLimitDefault')):
        conf['MCScoreExerciseLowerLimitDefault'] = 0
    # Give a default for the DocumentRoot:
    if not (conf.has_key('DocumentRoot')):
        conf['DocumentRoot'] = os.path.join(home, 'html')
    # Give a default for GroupInfoFile:
    if not (conf.has_key('GroupInfoFile')):
        conf['GroupInfoFile'] = os.path.join(home, 'data/groupinfo.txt')
    # Give a default for ExtraLaTeXHeader:
    if not (conf.has_key('ExtraLaTeXHeader')):
        conf['ExtraLaTeXHeader'] = ''
    # Preparse the PDFTemplate:
    conf['PDFTemplate'] = SimpleTemplate.ParseString(conf['PDFTemplate'])
    # Same for NoTable variant:
    if not conf.has_key('PDFTemplateNoTable'):
        conf['PDFTemplateNoTable'] = ''
    conf['PDFTemplateNoTable'] = SimpleTemplate.ParseString(
        conf['PDFTemplateNoTable'])
    # Now parse the GradingFunction if applicable:
    if conf.has_key('GradingFunction'):
        d = {}
        try:
            exec conf['GradingFunction'] + '\n' in d
            conf['GradingFunction'] = d['Grade']
        except:
            etype, value, tb = sys.exc_info()
            lines = traceback.format_exception(etype, value, tb)
            Utils.Error('Cannot parse GradingFunction.\n' + string.join(lines))
            conf['GradingFunction'] = None
    else:
        conf['GradingFunction'] = None
    if not (conf.has_key('GradingActive')):
        conf['GradingActive'] = 0
    # Now parse the ExamGradingFunction if applicable:
    if conf.has_key('ExamGradingFunction'):
        d = {}
        try:
            exec conf['ExamGradingFunction'] + '\n' in d
            conf['ExamGradingFunction'] = d['Grade']
        except:
            etype, value, tb = sys.exc_info()
            lines = traceback.format_exception(etype, value, tb)
            Utils.Error('Cannot parse ExamGradingFunction.\n' +
                        string.join(lines))
            conf['ExamGradingFunction'] = None
    else:
        conf['ExamGradingFunction'] = None
    if not (conf.has_key('ExamGradingActive')):
        conf['ExamGradingActive'] = 0
    if not (conf.has_key('DateTimeFormat')):
        conf['DateTimeFormat'] = '%c'
    # Also parse the EMailHeaderFunction:
    d = {}
    try:
        exec conf['EMailHeaderFunction'] + '\n' in d
        conf['EMailHeaderFunction'] = d['EMailHeaderFunction']
    except:
        etype, value, tb = sys.exc_info()
        lines = traceback.format_exception(etype, value, tb)
        Utils.Error('Cannot parse EMailHeaderFunction.\n' + string.join(lines))
        FailMiserably()
    # Compile regular expression for valid email addresses
    try:
        conf['reValidEmail'] = re.compile(conf['ValidEmailAddresses'], re.I)
    except:
        Utils.Error('Regular expression in "ValidEmailAddresses" cannot be '
                    'compiled.')
        etype, value, tb = sys.exc_info()
        lines = traceback.format_exception(etype, value, tb)
        Utils.Error(string.join(lines), prefix="")
        FailMiserably()
Example #2
0
    print ''
    if os.path.exists('tmptestimages/100dpi/' + t.md5sum + '.png'):
        os.system('/bin/sh -c \'' + opt['-v'] +
                  ' tmptestimages/100dpi/*.png\'')
        # remove temp dir
        shutil.rmtree('tmptestimages')
    else:
        os.system('/bin/sh -c \'less +"/^l\." tmptestimages/*/a.log\'')


for a in files:
    if not os.path.exists(a):
        print '\nWARNING:  ' + a + ' does not exist!'
        break
    print '\n\n############  Checking file ' + a + ' ...'
    if len(a) >= 4 and a[-4:] == '.tex':
        # case of LaTeX code for conventional exercise
        t = Exercises.TeXText(Utils.StringFile(a),
                              a, (1, 0, -1, -1),
                              width=Config.conf['WidthOfExerciseTextsHTML'])
        handletext(t)

    elif len(a) >= 4 and a[-4:] == '.auf':
        # case of OKUSON MC-like exercise
        Exercises.AllTexts = []
        Exercises.ReadExercisesFile(a)
        for t in Exercises.AllTexts:
            handletext(t)
    else:
        print 'WARNING: can only check .tex and .auf files.'