Example #1
0
 def htmlCode(self):
     examnr = self.examnr
     if examnr < 0:
         return '<em>Error: Invalid exam number</em>'
     table = []
     table.append([
         '', 'Matr.-Nr.', 'Name', 'Punkte',
         'Punkte in den einzelnen Aufgaben'
     ])
     l = Utils.SortNumerAlpha(Data.people.keys())
     maxscore = 0
     counter = 0
     for k in l:
         p = Data.people[k]
         if (examnr < len(p.exams) and p.exams[examnr] != None):
             exam = p.exams[examnr]
             if (exam.maxscore != 0):
                 maxscore = exam.maxscore
             if (exam.registration == 1 and exam.totalscore != -1):
                 counter += 1
                 table.append([
                     str(counter), k,
                     Utils.CleanWeb(p.lname) + ', ' +
                     Utils.CleanWeb(p.fname),
                     locale.str(exam.totalscore),
                     Utils.CleanWeb(exam.scores)
                 ])
     s = ('<p>Maximal erreichbare Punktzahl: ' + locale.str(maxscore) +
          '</p>\n')
     s += createHTMLTable(table)
     return s
Example #2
0
 def createLaTeXFile( self ):
     courseName = Config.conf['CourseName']
     lecturer = self.getString( 'lecturer' ).strip().replace( ' ', '~' )
     semester = self.getString( 'semester' ).strip()
     date = self.getString( 'date' ).strip()
     if date == '':
         date = '\\today'
     # count number of registrations
     count = 0
     l = Utils.SortNumerAlpha( Data.people.keys() )
     for k in l:
         p = Data.people[k]
         if self.examnr < len( p.exams ) and \
            p.exams[self.examnr] != None and \
            p.exams[self.examnr].registration:
             count += 1
     # get people for which a Deckblatt should be created
     s = ''
     l = Utils.SortNumerAlpha( Data.people.keys() )
     for k in l:
         p = Data.people[k]
         if self.examnr < len( p.exams ) and \
            p.exams[self.examnr] != None and \
            p.exams[self.examnr].registration:
             for i in range( self.copies ):
                 s += ( r'\deckblatt{%s}{%s}{%s}{%s}{%s}{%s}' %
                     ( lecturer, semester, courseName, date,
                         p.lname + ', ' + p.fname, k ) )
                 s += '\n'
     latexInput = LatexHead + s + LatexFoot
     return latexInput
Example #3
0
def dumpExtensions():
    '''Writes the list of registered extensions to stderr.'''
    Utils.Error('List of registered extensions:', prefix='Info: ')
    for extensionName in _registered_extensions_.keys():
        (category, shortDesc, longDesc, author, copyright, date,
         isSimpleExtension,
         extensionClass) = _registered_extensions_[extensionName]
        p = extensionClass()
        Utils.Error(p.name(), prefix='- ')
Example #4
0
def NoValidFunction(req, res, e):
    # We save the result in a temporary directory as well as the exception
    # message. Then we remove the ValidatorIcon.
    tmp = tempfile.mktemp()
    os.mkdir(tmp)
    fn = 'novalid_' + os.path.basename(req.path)
    Utils.FileString(os.path.join(tmp, fn), res[1])
    Utils.Error('Saved in dir ' + tmp, prefix='See: ')
    Utils.FileString(os.path.join(tmp, 'message'), str(e))
    # Remove ValidatorIcon:
    res[1] = string.replace(res[1], WebWorkers.ValidatorIconText, '')
    # Adjust Content-length:
    res[0]['Content-length'] = str(len(res[1]))
Example #5
0
 def headAndBody(self):
     courseName = Config.conf['CourseName']
     lecturer = self.getString('lecturer').strip().replace(' ', '~')
     semester = self.getString('semester').strip()
     benotet = (self.getString('benotet') == 'ja')
     date = self.getString('date').strip()
     if date == '':
         date = '\\today'
     # get people for which a Schein should be created
     s = ''
     l = Utils.SortNumerAlpha(Data.people.keys())
     for k in l:
         if self.getString('Schein' + k) == 'true':
             p = Data.people[k]
             if benotet:
                 grade = self.calculateGrade(p)
                 s += (r'\scheinMitNote{%s}{%s}{%s}{%s}{%s}{%s}{%s}' %
                       (lecturer, semester, courseName, date,
                        p.fname + ' ' + p.lname, k, grade))
             else:
                 s += (r'\schein{%s}{%s}{%s}{%s}{%s}{%s}' %
                       (lecturer, semester, courseName, date,
                        p.fname + ' ' + p.lname, k))
             s += '\n'
     latexInput = LatexHead + s + LatexFoot
     #        return ( { 'Content-type' : 'text/x-latex',                   'Content-Disposition' : 'attachment; filename="scheine.tex"'}, latexInput )
     pdf = LatexImage.LatexToPDF(latexInput)
     if not pdf:
         pdf = ''
     head = {
         'Content-type': 'application/pdf',
         'Content-Disposition': 'attachment; filename="scheine.pdf"'
     }
     return (head, pdf)
Example #6
0
 def parseValues(self):
     examnr = self.examnr
     # get the maxscore
     maxscore = self.getNumber('maxscore')
     if maxscore == None:
         return '<em>Error: Invalid maximal score.</em>'
     elif maxscore == '':
         return '<em>Error: Missing maximal score.</em>'
     else:
         self.maxscore = maxscore
     # get the individual scores
     self.scores = {}
     self.oldscores = {}
     l = Utils.SortNumerAlpha(Data.people.keys())
     for k in l:
         p = Data.people[k]
         if (examnr < len(p.exams) and p.exams[examnr] != None
                 and p.exams[examnr].registration == 1):
             score = self.getNumber('P' + str(examnr) + '_' + k, default=-1)
             if score == None:
                 return '<em>Error: Invalid score for ' + k + '.</em>'
             else:
                 if score > maxscore:
                     return ('<em>Error: Score for ' + k + ' exceeds the '
                             'maximal score.</em>')
                 self.scores[k] = [
                     score,
                     self.getString('S' + str(examnr) + '_' + k)
                 ]
                 self.oldscores[k] = [
                     self.getNumber('Pold' + str(examnr) + '_' + k,
                                    default=-1),
                     self.getString('Sold' + str(examnr) + '_' + k)
                 ]
Example #7
0
 def htmlCode(self):
     s = '<h3>Liste der Teilnehmer an Klausur ' + str(
         self.examnr) + '</h3>\n'
     table = []
     table.append(['', 'Matr.-Nr.', 'Name'])
     l = Utils.SortNumerAlpha(Data.people.keys())
     i = 0
     for k in l:
         p = Data.people[k]
         if self.examnr < len( p.exams ) and \
             p.exams[self.examnr] != None and \
             p.exams[self.examnr].registration:
             i += 1
             table.append([
                 str(i), k,
                 Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname)
             ])
     s += createHTMLTable(table)
     return s
Example #8
0
 def createPDFFile(self):
     table = []
     l = Utils.SortNumerAlpha(Data.people.keys())
     for k in l:
         p = Data.people[k]
         if self.examnr < len( p.exams ) and \
            p.exams[self.examnr] != None and \
            p.exams[self.examnr].registration:
             table.append([k, p.lname + ', ' + p.fname])
     s = ('\\section*{Liste der Teilnehmer an Klausur ' + str(self.examnr) +
          '}\n')
     lines = '\\cline{1-3}\\cline{5-7}\n'
     linesshort = '\\hline\n'
     eol = '\\\\\n'
     tablehead = ('\\begin{tabular}{|r|c|l|l|r|c|l|}\n' + lines +
                  ' & Matr.-Nr. & Name & & & Matr.-Nr. & Name ' + eol +
                  lines)
     tableheadshort = ('\\begin{tabular}{|r|c|l|}\n' + linesshort +
                       ' & Matr.-Nr. & Name ' + eol + linesshort)
     tablefoot = lines + '\\end{tabular}\n'
     tablefootshort = linesshort + '\\end{tabular}\n'
     maxRows = 44
     offset = 0
     while offset < len(table):
         if offset > 0:
             s += '\\newpage\n'
         twoColumns = (offset + maxRows < len(table))
         if twoColumns:
             s += tablehead
         else:
             s += tableheadshort
         for i in range(offset, min(offset + maxRows, len(table))):
             s += str(i + 1) + ' & ' + table[i][0] + ' & ' + table[i][1]
             if twoColumns:
                 s += ' & & '
                 if i + maxRows < len(table):
                     s += (str(i + maxRows + 1) + ' & ' +
                           table[i + maxRows][0] + ' & ' +
                           table[i + maxRows][1])
                 else:
                     s += '& &'
             s += eol
         if twoColumns:
             s += tablefoot
         else:
             s += tablefootshort
         offset += 2 * maxRows
     latexInput = LatexTemplate % (s)
     pdf = LatexImage.LatexToPDF(latexInput)
     if not pdf:
         return ''
     return pdf
Example #9
0
 def createExamRegistrationMask(self):
     examnr = self.examnr
     s = '<h3>An-/Abmeldung von Klausur ' + str(examnr) + '</h3>\n'
     s += ('<form action="/AdminExtension" method="post">\n'
           '<div><input type="hidden" name="extension" value="' +
           self.name() + '" />\n'
           '<input type="hidden" name="state" value="1" />\n'
           '<input type="hidden" name="examnr" value="' + str(examnr) +
           '" /></div>\n')
     table = []
     table.append(['', 'Matr.-Nr.', 'Name', 'Klausurteilnahme'])
     l = Utils.SortNumerAlpha(Data.people.keys())
     counter = 0
     for k in l:
         counter += 1
         p = Data.people[k]
         checked = ''
         if (examnr < len(p.exams) and p.exams[examnr] != None
                 and p.exams[examnr].registration == 1):
             checked = 'checked="checked" '
         table.append([
             str(counter), k,
             Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname),
             '<input type="checkbox" name="T' + k + '" '
             'value="true" ' + checked + ' />'
         ])
     s += createHTMLTable(table)
     s += (
         '<p><input type="submit" name="Action" value="Send" />\n'
         # Not sure how I can make of the AdminPasswdField() method. OTOH, this method
         # only uses a global variable, so there's no reason for it to be a method of
         # a class.
         #               '' + handler.AdminPasswdField() + '\n'
         '<input type="password" size="16" maxlength="16" '
         'name="passwd" value="" /></p>\n'
         '</form>\n')
     return s
Example #10
0
 def createTextFile(self):
     s = '# All participants of exam number ' + str(self.examnr) + ':\n'
     s += '# ID:angemeldet?:name:fname\n'
     s += '# Time and date of export: ' + Utils.LocalTimeString() + '\n'
     l = Utils.SortNumerAlpha(Data.people.keys())
     for k in l:
         p = Data.people[k]
         if self.examnr < len( p.exams ) and \
             p.exams[self.examnr] != None and \
             p.exams[self.examnr].registration:
             s += (k + ':1:' + Utils.Protect(p.lname) + ':' +
                   Utils.Protect(p.fname) + '\n')
         else:
             s += (k + ':0:' + Utils.Protect(p.lname) + ':' +
                   Utils.Protect(p.fname) + '\n')
     return s
Example #11
0
def ReadConfig():
    global conf
    configfile = os.path.join(home, "Config.xml")
    parseconf = {
        'fourth': pyRXPU.recordLocation,
        'ReturnDefaultedAttributes': 0,
        'MergePCData': 1,
        'Validate': 1,
        'eoCB': OurDtdOpener
    }
    tree = XMLRewrite.Parse(config=parseconf, file=configfile)
    if not tree:
        Utils.Error("Cannot parse the Config.xml file!")
        FailMiserably()

    # Now run through the tree:
    # We know by the DTD that there is exactly one "Config" element.
    if tree[2] != None:  # there might be no subelements
        for node in tree[2]:
            if type(node) == types.TupleType:
                # We know by the DTD that there is only element content, but
                # strings in between are still reported by pyRXP.
                key = node[0].encode('ISO-8859-1', 'replace')
                if Parameters.has_key(key):
                    info = Parameters[key]
                    # special case 'ConfigData', create dictionary if not there
                    if key == 'ConfigData':
                        if not conf.has_key(key):
                            conf[key] = {}
                        cnf = conf[key]
                        key = node[1]['key'].encode('ISO-8859-1', 'replace')
                    else:
                        cnf = conf
                    if info[0] == 'STRING' or info[0] == 'INT' or \
                       info[0] == 'FLOAT' or info[0] == 'PATH':
                        # We know by the DTD that there is only #PCDATA content
                        # Usually this will come as one chunk because of
                        # "MergePCData=1" above. We strip whitespace at
                        # beginning and end:
                        cnf[key] = string.strip(string.join(node[2]))
                        if info[0] == 'STRING' or info[0] == 'PATH':
                            try:
                                cnf[key] = cnf[key].encode('ISO8859-1')
                            except:
                                Utils.Error(
                                    'Value "' + cnf[key] + '" of ' +
                                    'configuration field "' + key + '" at ' +
                                    Utils.StrPos(node[3]) +
                                    ' has no ISO8859-1' +
                                    ' encoding. We assume the empty string.',
                                    prefix='Warning: ')
                                cnf[key] = ""
                            if info[0] == 'PATH':
                                cnf[key] = os.path.join(home, cnf[key])
                        elif info[0] == 'INT':
                            try:
                                cnf[key] = int(cnf[key])
                            except:
                                Utils.Error('Value "' + cnf[key] + '" of ' +
                                            'configuration field "' + key +
                                            '" at ' + Utils.StrPos(node[3]) +
                                            ' is not an integer. We' +
                                            ' assume 0.',
                                            prefix='Warning: ')
                                cnf[key] = 0
                        elif info[0] == 'FLOAT':
                            try:
                                cnf[key] = float(cnf[key])
                            except:
                                Utils.Error('Value "' + cnf[key] + '" of ' +
                                            'configuration field "' + key +
                                            '" at ' + Utils.StrPos(node[3]) +
                                            ' is not a float. We' +
                                            ' assume 0.0 .',
                                            prefix='Warning: ')
                                cnf[key] = 0.0
                    elif info[0] == 'LIST' or info[0] == 'PATHLIST':
                        # We know by the DTD, that the children are just a list
                        # of elements with #PCDATA content:
                        cnf[key] = []
                        for subnode in node[2]:
                            if type(subnode) == types.TupleType:
                                s = string.strip(string.join(subnode[2]))
                                try:
                                    s = s.encode('ISO8859-1')
                                except:
                                    Utils.Error('Value "' + s + '" of ' +
                                                'configuration field "' + key +
                                                '" at ' +
                                                Utils.StrPos(node[3]) +
                                                ' has no ISO8859-1' +
                                                ' encoding. We ignore it.',
                                                prefix='Warning: ')
                                if info[0] == 'PATHLIST':
                                    s = os.path.join(home, s)
                                cnf[key].append(s)

                else:  # A configuration field that we do not know!
                    Utils.Error('Unknown configuration field "' + key +
                                '" at ' + Utils.StrPos(node[3]) +
                                ', ignoring.',
                                prefix='Warning: ')
    abort = 0
    for k in Parameters.keys():
        if Parameters[k][1] and not (conf.has_key(k)):
            Utils.Error('Essential configuration option not found: "' + k +
                        '".')
            abort = 1
    if abort:
        FailMiserably()
    # See whether we can find the VERSION file:
    try:
        f = file(os.path.join(home, "VERSION"))
        version = f.readline()
        f.close()
        conf["Version"] = string.strip(version)
    except:
        conf["Version"] = 'UNKNOWN'
        pass  # we silently ignore, if the VERSION file is not found
Example #12
0
def FailMiserably():
    Utils.Error("Aborting.", prefix="")
    sys.exit(1)
Example #13
0
    sol = sheet.AllSolutions().strip()
    values['ExercisesTable'] = sheet.LatexSheetTable('')
    values['ExercisesNoTable'] = sheet.LatexSheetNoTable()
    if len(sol) > 0:
      values['ExercisesTable'] = values['ExercisesTable']+ \
        '\n\\newpage\n\n\\begin{verbatim}\n'+ sol +'\n\\end{verbatim}\n\n'
    latexinput = None
    pdf = None
    if opt.has_key('-n'):
      templ = Config.conf['PDFTemplateNoTable']
    else:
      templ = Config.conf['PDFTemplate']
    try:
      latexinput = SimpleTemplate.FillTemplate(templ, values)
    except:
      print('Cannot produce LaTeX input.')
    if latexinput:
      try:
        pdf = LatexImage.LatexToPDF(latexinput)
      except:
        pdf = None
    if latexinput:
      Utils.FileString(fname+'_'+sheet.name+'.tex',latexinput)
      print 'Wrote LaTeX code to '+fname+'_'+sheet.name+'.tex'
      if pdf:
        Utils.FileString(fname+'_'+sheet.name+'.pdf',pdf)    
        print 'Wrote PDF file to '+fname+'_'+sheet.name+'.pdf'
        shutil.rmtree('tmpsheettest')


Example #14
0
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import os, sys

from fmTools import Utils

Utils.Error('Loading extensions...', prefix='Info: ')

import plugins

pluginsPath = os.path.join(plugins.__path__[0])
for pluginDir in os.listdir(pluginsPath):
    if pluginDir in ['CVS', '.svn', '.git']:
        continue  # skip the CVS and similae  directory
    if not os.path.isdir(os.path.join(pluginsPath, pluginDir)):
        continue  # skip non-directories
    # load modules in this directory
    module = None
    try:
        module = __import__(plugins.__name__ + '.' + pluginDir)
    except ImportError:
        Utils.Error('Importing plugin ' + pluginDir + '.' + name + ' failed')
Example #15
0
 def htmlCode(self):
     html = ''
     try:
         smtpserver = smtplib.SMTP(self.__server)
         if self.__username <> "" and self.__mailpw <> "":
             smtpserver.login(self.__username, self.__mailpw)
     except:
         smtpserver = None
         html += '<p>Error: Could not contact the server %s</p>\n' % self.__server
     html += '<p>'
     html += '(<a href="/adminmenu.html">back to administrator menu</a>)'
     html += '&nbsp;&nbsp;'
     html += '(<a href="/adminextensions.html">back to administrator ' + \
      'extensions</a>)'
     html += '</p>\n'
     varlist = ["i", "n", "f", "s", "g", "a", "m"]
     vartofieldtitle = {}
     vartofieldtitle["i"] = "ID"
     vartofieldtitle["n"] = "last name"
     vartofieldtitle["f"] = "first name"
     vartofieldtitle["s"] = "semester"
     vartofieldtitle["g"] = "group"
     vartofieldtitle["a"] = "field of studies"
     vartofieldtitle["m"] = "mail address"
     for sheetnr, sheetname, sheet in Exercises.SheetList():
         if not sheet.IsClosed(): continue
         if not sheet.counts: continue
         varlist.append(str(sheetnr) + "c")
         vartofieldtitle[str(sheetnr) + "c"] = "points from interactive " \
          "part of exercise sheet " + str(sheetnr)
     varlist.append("C")
     vartofieldtitle["C"] = "total points from interactive exercises"
     for sheetnr, sheetname, sheet in Exercises.SheetList():
         if not sheet.IsClosed(): continue
         if not sheet.counts: continue
         varlist.append(str(sheetnr) + "h")
         vartofieldtitle[str(sheetnr) + "h"] = "points from written homework " \
          "part of exercise sheet " + str(sheetnr)
     varlist.append("H")
     vartofieldtitle["H"] = "total points from written homework exercises"
     varlist.append("T")
     vartofieldtitle[
         "T"] = "total points from written and interactive exercises"
     for i in range(Data.Exam.maxexamnumber):
         varlist.append(str(i) + "e")
         vartofieldtitle[str(i) + "e"] = "points from exam " + str(i)
     varlist.append("E")
     vartofieldtitle["E"] = "total points from exams"
     for i in range(Data.Exam.maxexamnumber):
         varlist.append(str(i) + "r")
         vartofieldtitle[str(i) + "r"] = "registered for exam " + str(i) + \
          " (no/yes)"
     persondatakeys = []
     for k in Data.people.keys():
         for key in Data.people[k].persondata.keys():
             if key not in persondatakeys: persondatakeys.append(key)
     persondatakeys.sort()
     for i in range(len(persondatakeys)):
         varlist.append("%dd" % i)
         vartofieldtitle[varlist[-1]] = persondatakeys[i]
     if self.__state > 0 and smtpserver <> None:
         fullfrom = self.__from
         maillist = []
         if self.__fromname <> "":
             fullfrom = "%s <%s>" % (self.__fromname, self.__from)
         if self.__state % 2 == 1:
             html += '<p>Please confirm that the following participants should ' \
              'receive a mail.</p>\n'
         else:
             html += '<p>Tried to send last mail to the following ' \
              'participants:</p>\n'
         html += '<table>\n'
         html += '<tr>\n'
         html += \
          '<th>ID</th><th>last name</th><th>first name</th><th>status</th>\n'
         html += '</tr>\n'
         for k in Utils.SortNumerAlpha(Data.people.keys()):
             p = Data.people[k]
             vardict = {}
             vardict["i"] = k
             vardict["n"] = p.lname
             vardict["f"] = p.fname
             vardict["s"] = p.sem
             vardict["g"] = p.group
             vardict["a"] = p.stud
             vardict["m"] = p.email
             totalintscore = 0.0
             for sheetnr, sheetname, sheet in Exercises.SheetList():
                 if not sheet.IsClosed(): continue
                 if not sheet.counts: continue
                 vardict[str(sheetnr) + "c"] = -1
                 if p.mcresults.has_key(sheetname):
                     vardict[str(sheetnr) +
                             "c"] = p.mcresults[sheetname].score
                     totalintscore += p.mcresults[sheetname].score
             vardict["C"] = totalintscore
             totalhomescore = 0.0
             for sheetnr, sheetname, sheet in Exercises.SheetList():
                 if not sheet.IsClosed(): continue
                 if not sheet.counts: continue
                 vardict[str(sheetnr) + "h"] = -1
                 if p.homework.has_key(sheetname) and \
                  p.homework[sheetname].totalscore <> -1:
                     vardict[str(sheetnr) +
                             "h"] = p.homework[sheetname].totalscore
                     totalhomescore += p.homework[sheetname].totalscore
             vardict["H"] = totalhomescore
             vardict["T"] = totalintscore + totalhomescore
             totalexamscore = 0.0
             for i in range(Data.Exam.maxexamnumber):
                 if i >= len(p.exams) or p.exams[i] == None or \
                  p.exams[i].totalscore < 0:
                     vardict[str(i) + "e"] = -1
                 else:
                     vardict[str(i) + "e"] = p.exams[i].totalscore
                     totalexamscore += p.exams[i].totalscore
                 vardict[str(i) + "r"] = "no"
                 if i < len(p.exams) and p.exams[i] <> None:
                     if p.exams[i].registration == 1:
                         vardict[str(i) + "r"] = "yes"
             vardict["E"] = totalexamscore
             for i in range(len(persondatakeys)):
                 try:
                     vardict["%dd" % i] = p.persondata[persondatakeys[i]]
                 except:
                     vardict["%dd" % i] = ""
             filter = True
             for i in range(5):
                 if self.__fieldlist[i] <> None:
                     val1 = vardict[self.__fieldlist[i]]
                     val2 = self.__vallist[i]
                     if len(val2
                            ) >= 2 and val2[0] == '"' and val2[-1] == '"':
                         val2 = val2[1:-1]
                         val1 = str(val1)
                     else:
                         try:
                             val1 = int(val1)
                             val2 = int(val2)
                         except:
                             try:
                                 val1 = float(val1)
                                 val2 = float(val2)
                             except:
                                 pass
                     if self.__rellist[i] == "equal":
                         if not val1 == val2: filter = False
                     if self.__rellist[i] == "greater":
                         if not val1 > val2: filter = False
                     if self.__rellist[i] == "greaterequal":
                         if not val1 >= val2: filter = False
                     if self.__rellist[i] == "less":
                         if not val1 < val2: filter = False
                     if self.__rellist[i] == "lessequal":
                         if not val1 <= val2: filter = False
                     if self.__rellist[i] == "notequal":
                         if not val1 <> val2: filter = False
                     if self.__rellist[i] == "begins":
                         if not str(val1)[:len(str(val2))] == str(val2):
                             filter = False
                     if self.__rellist[i] == "contains":
                         if not str(val2) in str(val1): filter = False
                     if self.__rellist[i] == "ends":
                         if not str(val1)[-len(str(val2)):] == str(val2):
                             filter = False
             if filter and p.email <> "":
                 msg = "From: %s\r\n" % fullfrom
                 msg += "Subject: %s\r\n" % self.__subject
                 msg += "To: %s\r\n" % p.email
                 msg += "Content-type: text/plain; charset=iso-8859-15\r\n"
                 msg += "\r\n"
                 msg += self.__text
                 msg = msg.replace("%%", "_!_/_")
                 usedvar = False
                 for var in vardict.keys():
                     if ("%%%s" % var) in msg: usedvar = True
                     msg = msg.replace("%%%s" % var, str(vardict[var]))
                 msg = msg.replace("_!_/_", "%")
                 msg = msg.strip() + "\r\n"
                 html += '<tr>\n'
                 if self.__state % 2 == 1:
                     status = "not yet sent"
                 else:
                     status = "successful"
                     if usedvar:
                         try:
                             smtpserver.sendmail(fullfrom, p.email, msg)
                             time.sleep(self.__pause)
                         except:
                             status = "<strong>not successful</strong>"
                     else:
                         maillist.append(p.email)
                         status = "BCC"
                 html += '<td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n' % (k, \
                  p.lname, p.fname, status)
                 html += '</tr>\n'
         html += '</table>\n'
         if maillist <> [] and self.__state % 2 == 0:
             msg = "From: %s\r\n" % fullfrom
             msg += "Subject: %s\r\n" % self.__subject
             msg += "To: %s\r\n" % fullfrom
             msg += "BCC: %s\r\n" % string.join(maillist, ", ")
             msg += "Content-type: text/plain; charset=iso-8859-15\r\n"
             msg += "\r\n"
             msg += self.__text
             msg = msg.replace("%%", "%")
             msg = msg.strip() + "\r\n"
             try:
                 smtpserver.sendmail(fullfrom, [fullfrom] + maillist, msg)
                 pass
             except:
                 html = html.replace("BCC",
                                     "<strong>not successful</strong>")
         smtpserver.quit()
     html += '<form action="/AdminExtension" method="post" ' + \
      'accept-charset="ISO-8859-15">\n'
     html += '<div>\n'
     html += '<input type="hidden" name="extension" value="%s" />\n' % \
      self.name()
     html += '<input type="hidden" name="state" value="%d" />\n' % \
      (self.__state + 1)
     html += '</div>\n'
     if self.__state % 2 == 0:
         html += '<p>\n'
         html += 'Select participants who should receive a mail.\n'
         html += 'The following conditions have all to be met simultaneously.\n'
         html += '(Please note that comparisons are interpreted as numerical '
         html += 'comparisons whenever it is possible. To force comparison of '
         html += 'texts, include the value in quotes ("..."))\n'
         html += 'If no condition is given, every participant will receive '
         html += 'a mail.\n'
         html += '</p>\n'
         html += '<table>\n'
         for i in range(5):
             html += '<tr>\n'
             html += '<td>\n'
             html += '<select name="field%d">\n' % i
             html += '<option value="none">field</option>\n'
             for var in varlist:
                 if self.__fieldlist[i] == var:
                     html += '<option value="%s" selected="selected">%s</option>\n' % \
                      (var, vartofieldtitle[var])
                 else:
                     html += '<option value="%s">%s</option>\n' % \
                      (var, vartofieldtitle[var])
             html += '</select>\n'
             html += '</td>\n'
             reqsel = ""
             rgtsel = ""
             rgesel = ""
             rltsel = ""
             rlesel = ""
             rnesel = ""
             rbgsel = ""
             rcosel = ""
             rensel = ""
             if self.__rellist[i] == "equal":
                 reqsel = ' selected="selected"'
             if self.__rellist[i] == "greater":
                 rgtsel = ' selected="selected"'
             if self.__rellist[i] == "greaterequal":
                 rgesel = ' selected="selected"'
             if self.__rellist[i] == "less": rltsel = ' selected="selected"'
             if self.__rellist[i] == "lessequal":
                 rlesel = ' selected="selected"'
             if self.__rellist[i] == "notequal":
                 rnesel = ' selected="selected"'
             if self.__rellist[i] == "begins":
                 rbgsel = ' selected="selected"'
             if self.__rellist[i] == "contains":
                 rcosel = ' selected="selected"'
             if self.__rellist[i] == "ends": rensel = ' selected="selected"'
             html += '<td>\n'
             html += '<select name="relation%s">\n' % i
             html += '<option value="none">relation</option>\n'
             html += '<option value="equal"%s>=</option>\n' % reqsel
             html += '<option value="greater"%s>&gt;</option>\n' % rgtsel
             html += '<option value="greaterequal"%s>&gt;=</option>\n' % rgesel
             html += '<option value="less"%s>&lt;</option>\n' % rltsel
             html += '<option value="lessequal"%s>&lt;=</option>\n' % rlesel
             html += '<option value="notequal"%s>not equal to</option>\n' % rnesel
             html += '<option value="begins"%s>begins with</option>\n' % rbgsel
             html += '<option value="contains"%s>contains</option>\n' % rcosel
             html += '<option value="ends"%s>ends with</option>\n' % rensel
             html += '</select>\n'
             html += '</td>\n'
             html += '<td>\n'
             html += '<input type="text" name="value%d" size="30" value="%s" />' % \
              (i, self.__vallist[i])
             html += '</td>\n'
             html += '</tr>\n'
         html += '</table>\n'
         html += ('<p>server:&nbsp;<input type="text" name="server" ' +
                  'size="40" value="%s" /></p>\n') % self.__server
         html += (
             '<p>user name for mail server (if needed):&nbsp;<input type=' +
             '"text" name="username" size="40" value="%s" /></p>\n'
         ) % self.__username
         html += ('<p>pause between two mails:&nbsp;<input type="text" ' + \
          'name="pause" size="5" value="%s" /> seconds</p>\n') % self.__pause
         html += ('<p>from address:&nbsp;<input type="text" name="from" ' +
                  'size="40" value="%s" /></p>\n') % self.__from
         html += ('<p>from name (optional):&nbsp;<input type="text" ' +
                  'name="fromname" size="40" value="%s" /></p>\n'
                  ) % self.__fromname
         html += '<p>\n'
         html += 'In the following text fields you may use variables, '
         html += 'which are set according to the participant the mail '
         html += 'is sent to.<br />\n'
         html += '<strong>%i</strong>: ID'
         html += '; <strong>%n</strong>: last name'
         html += '; <strong>%f</strong>: first name'
         html += '; <strong>%s</strong>: semester'
         html += '; <strong>%g</strong>: group'
         html += '; <strong>%a</strong>: field of studies'
         html += '; <strong>%m</strong>: email address'
         html += '; <strong>%1c</strong>, <strong>%2c</strong>, ...: points ' \
          'from interactive part of exercise sheet 1, 2, ...'
         html += '; <strong>%C</strong>: total points from interactive exercises'
         html += '; <strong>%1h</strong>, <strong>%2h</strong>, ...: points ' \
          'from written homework part of exercise sheet 1, 2, ...'
         html += '; <strong>%H</strong>: total points from written homework ' \
          'exercises'
         html += '; <strong>%T</strong>: total points from interactive and ' \
          'written homework exercises'
         html += '; <strong>%0e</strong>, <strong>%1e</strong>, ...: points ' \
          'from exam 0, 1, ...'
         html += '; <strong>%E</strong>: total points from exams'
         for i in range(len(persondatakeys)):
             html += '; <strong>%%%dd</strong>: %s' % (i, persondatakeys[i])
         html += '.\n'
         html += '(In order to produce a %-sign, type ' \
          '<strong>%%</strong>.)<br />\n'
         html += 'If no variables are used, only one mail will be sent &ndash; '
         html += 'addressed to the from address with all recipients in a BCC ' \
          'list.\n'
         html += '</p>\n'
         html += ('<p>subject:&nbsp;<input type="text" ' + 'name="subject" '
                  + 'size="40" value="%s" /></p>\n') % self.__subject
         html += '<p><textarea name="text" cols="50" rows="10">' + \
          self.__text + '</textarea></p>\n'
     else:
         html += '<table>\n'
         for i in range(5):
             html += '<tr>\n'
             if self.__fieldlist[i] in varlist:
                 html += '<td>\n'
                 html += '<input type="hidden" name="field%d" value="%s" />' % \
                  (i, self.__fieldlist[i])
                 html += vartofieldtitle[self.__fieldlist[i]] + "\n"
                 html += '</td>\n'
             else:
                 html += '<td>\n'
                 html += ('<input type="hidden" name="field%d" value="none" ' + \
                  '/>&nbsp;\n') % i
                 html += '</td>\n'
             html += '<td>\n'
             html += '<input type="hidden" name ="relation%d" value="%s" />' % \
              (i, self.__rellist[i])
             if self.__rellist[i] == "equal": html += "="
             if self.__rellist[i] == "greater": html += "&gt;"
             if self.__rellist[i] == "greaterequal": html += "&gt;="
             if self.__rellist[i] == "less": html += "&lt;"
             if self.__rellist[i] == "lessequal": html += "&lt;="
             if self.__rellist[i] == "notequal": html += "not equal to"
             if self.__rellist[i] == "begins": html += "begins with"
             if self.__rellist[i] == "contains": html += "contains"
             if self.__rellist[i] == "ends": html += "ends with"
             html += '\n</td>\n'
             html += '<td>\n'
             html += '<input type="hidden" name="value%d" value="%s" />%s\n' % \
              (i, self.__vallist[i], self.__vallist[i])
             html += '</td>\n'
             html += '</tr>\n'
         html += '</table>\n'
         html += ('<p>server:&nbsp;<input type="hidden" name="server" ' +
                  'value="%s" />%s</p>\n') % (self.__server, self.__server)
         html += (
             '<p>user name for mail server (if needed):&nbsp;<input type=' +
             '"hidden" name="username" value="%s" />%s</p>\n') % (
                 self.__username, self.__username)
         html += (
             '<p>password for mail server (if needed):&nbsp;<input type=' +
             '"password" name="mailpw" size="10" value="%s" /></p>\n'
         ) % self.__mailpw
         html += ('<p>pause between two mails:&nbsp;<input type="hidden" ' + \
          'name="pause" value="%s" />%s seconds</p>\n') % (self.__pause,
          self.__pause)
         html += ('<p>from address:&nbsp;<input type="hidden" name="from" '
                  + 'value="%s" />%s</p>\n') % (self.__from, self.__from)
         html += ('<p>from name (optional):&nbsp;<input type="hidden" ' +
                  'name="fromname" value="%s" />%s</p>\n') % (
                      self.__fromname, self.__fromname)
         html += ('<p>subject:&nbsp;<input type="hidden" ' +
                  'name="subject" ' + 'value="%s" />%s</p>\n') % (
                      self.__subject, self.__subject)
         html += '<p><textarea name="text" cols="50" rows="10" ' + \
          'readonly="readonly">' + self.__text + '</textarea></p>\n'
     html += '<p>administrator password: <input type="password" ' + \
      'size="16" maxlength="16" name="passwd" value="" />' + \
      '&nbsp;<input type="submit" /></p>\n'
     html += '</form>\n'
     return html
Example #16
0
 def htmlCode(self):
     lecturer = Config.conf['Lecturer']
     semester = Config.conf['Semester']
     s = ('<hr />\n'
          '<form action="/AdminExtension" method="post">\n'
          '<div><input type="hidden" name="extension" value="' +
          self.name() + '" />\n'
          '<input type="hidden" name="state" value="1" /></div>\n'
          '<p>'
          'Dozent: <input size="30" maxlength="40" name="lecturer" '
          'value="' + lecturer + '" /><br />\n'
          'Semester: <input size="30" maxlength="40" name="semester" '
          'value="' + semester + '" /><br />\n'
          'Scheine: <input type="radio" name="benotet" '
          'value="ja" />benotet / '
          '<input type="radio" name="benotet" '
          'value="nein" />unbenotet<br />\n'
          'Datum: <input size="20" maxlength="20" name="date" '
          'value="" /> (falls leer wird heutiges Datum genommen)'
          '</p>\n'
          '<p>Waehlen Sie diejenigen Kursteilnehmer aus, fuer die ein '
          'Schein generiert werden soll.</p>\n')
     table = []
     titleRow = ['', 'Schein', 'Matr.-Nr.', 'Name', 'Uebungspunkte']
     for i in range(Data.Exam.maxexamnumber):
         titleRow.append('Klausur ' + str(i))
     titleRow.append('Bemerkung')
     table.append(titleRow)
     nurScheinbedErf = (self.getString('nurScheinbedErf') == 'true')
     l = Utils.SortNumerAlpha(Data.people.keys())
     counter = 0
     for k in l:
         p = Data.people[k]
         if nurScheinbedErf and not self.ScheinbedingungErfuellt(p):
             continue
         counter += 1
         row = [str(counter)]
         if self.ScheinbedingungErfuellt(p):
             row.append('<input type="checkbox" name="Schein' + k + '" '
                        'value="true" />')
         else:
             row.append('-')
         row += [
             k,
             Utils.CleanWeb(p.lname + ', ' + p.fname),
             locale.str(p.TotalScore())
         ]
         for i in range(Data.Exam.maxexamnumber):
             if (len(p.exams) <= i or p.exams[i] == None
                     or p.exams[i].totalscore < 0):
                 row.append('-')
             else:
                 row.append(locale.str(p.exams[i].totalscore))
         if self.ScheinbedingungErfuellt(p):
             row.append('Scheinbedingung ist erfuellt')
         else:
             row.append('Scheinbedingung ist nicht erfuellt')
         table.append(row)
     s += createHTMLTable(table)
     s += (
         '<p><input type="submit" name="Action" value="Send" />\n'
         # Not sure how I can make use of the AdminPasswdField() method. OTOH, this
         # method only uses a global variable, so there's no reason for it to be a
         # method of a class.
         #               '' + handler.AdminPasswdField() + '\n'
         '<input type="password" size="16" maxlength="16" '
         'name="passwd" value="" /></p>\n'
         '</form>\n')
     return s
Example #17
0
 def createExamResultInputMask(self):
     examnr = self.examnr
     s = '<h3>Eingabe der Ergebnisse von Klausur ' + str(examnr) + '</h3>\n'
     s += ('<p><em>Hinweis:</em> Es werden nur diejenigen '
           'Kursteilnehmer angezeigt, die zu dieser Klausur angemeldet '
           'sind.</p>')
     s += ('<form action="/AdminExtension" method="post">\n'
           '<div><input type="hidden" name="extension" value="' +
           self.name() + '" />\n'
           '<input type="hidden" name="state" value="1" />\n'
           '<input type="hidden" name="examnr" value="' + str(examnr) +
           '" /></div>\n')
     table = []
     table.append([
         '', 'Matr.-Nr.', 'Name', 'Punkte',
         'Punkte in den einzelnen Aufgaben'
     ])
     l = Utils.SortNumerAlpha(Data.people.keys())
     counter = 0
     oldmaxscore = ''
     for k in l:
         p = Data.people[k]
         checked = ''
         if (examnr < len(p.exams) and p.exams[examnr] != None):
             exam = p.exams[examnr]
             if (exam.maxscore != 0):
                 oldmaxscore = locale.str(exam.maxscore)
             if (exam.registration == 1):
                 counter += 1
                 oldtotalscore = ''
                 if (exam.totalscore != -1):
                     oldtotalscore = locale.str(exam.totalscore)
                 table.append([
                     str(counter), k,
                     Utils.CleanWeb(p.lname) + ', ' +
                     Utils.CleanWeb(p.fname), '<input type="hidden" '
                     'name="Pold' + str(examnr) + '_' + k + '" '
                     'value="' + oldtotalscore + '" />'
                     '<input size="6" maxlength="6" '
                     'name="P' + str(examnr) + '_' + k + '" '
                     'value="' + oldtotalscore + '" />',
                     '<input type="hidden" '
                     'name="Sold' + str(examnr) + '_' + k + '" '
                     'value="' + Utils.CleanWeb(exam.scores) + '" />'
                     '<input size="40" maxlength="100" '
                     'name="S' + str(examnr) + '_' + k + '" '
                     'value="' + Utils.CleanWeb(exam.scores) + '" />'
                 ])
     s += ('<p>Maximal erreichbare Punktzahl: '
           '<input name="maxscore" value="' + oldmaxscore + '" '
           'size="4" maxlength="4" /></p>\n')
     s += createHTMLTable(table)
     s += (
         '<p><input type="submit" name="Action" value="Send" />\n'
         # Not sure how I can make use of the AdminPasswdField() method. OTOH, this
         # method only uses a global variable, so there's no reason for it to be a
         # method of a class.
         #               '' + handler.AdminPasswdField() + '\n'
         '<input type="password" size="16" maxlength="16" '
         'name="passwd" value="" /></p>\n'
         '</form>\n')
     return s
Example #18
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.'
Example #19
0
Config.ReadConfig()
Config.PostProcessing()  # some postprocessing of configuration data

f = file("log/server.log", "r")
f.seek(0, 2)  # seek to end of file
p = f.tell()

# Now send the request:
try:
    u = urllib.urlopen('http://localhost:' + str(Config.conf['Port']) +
                       '/AdminWork?Action=PID')
    spid = u.read()
    u.close()
except:
    Utils.Error('Cannot contact server. No server running?')
    sys.exit(1)

pid = os.fork()
if pid == 0:
    time.sleep(0.5)  # Let the parent get hold of the log file
    os.kill(int(spid), signal.SIGUSR1)
    try:
        # generate a request such that server notices the signal
        u = urllib.urlopen('http://localhost:' + str(Config.conf['Port']) +
                           '/')
        u.close()
    except:
        pass
    print 'Sent server with PID ' + spid + ' a USR1 signal.'
    sys.exit(0)  # Terminate this child process
Example #20
0
import sys, os, time

# get paths right
homedir = os.path.abspath(sys.path[0])
okudir = os.path.join(homedir, '..')
os.environ["OKUSONHOME"] = okudir
sys.path = [os.path.join(okudir, 'server')] + sys.path

# read config
import Config
Config.ReadConfig()
Config.PostProcessing()

# read exercises and sheets
from fmTools import Utils, AsciiData
Utils.Error('Reading exercises and sheets...', prefix='Info: ')
import Exercises
for d in Config.conf['ExerciseDirectories']:
    Exercises.ReadExercisesDirectory(d)
for d in Config.conf['SheetDirectories']:
    Exercises.ReadSheetsDirectory(d)

# list of triples (number, name, sheet)
sheets = Exercises.SheetList()

# read data
import Data
Utils.Error('Reading personal data...', prefix='Info: ')
Data.peopledesc.LoadFile()
Utils.Error('Reading multiple choice data...', prefix='Info: ')
Data.mcresultsdesc.LoadFile()
Example #21
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 #22
0
    def createSummary(self):
        examnr = self.examnr
        maxscore = self.maxscore
        scores = self.scores
        oldscores = self.oldscores

        # put the changes into the database
        table = []
        table.append([
            '', 'Matr.-Nr.', 'Name', 'Punkte',
            'Punkte in den einzelnen Aufgaben'
        ])
        unchanged = []
        unchanged.append([
            '', 'Matr.-Nr.', 'Name', 'Punkte (alt)', 'Punkte (aktuell)',
            'Punkte (Ihre Angabe)', 'Details (alt)', 'Details (aktuell)',
            'Details (Ihre Angabe)'
        ])
        counter = 0
        unchangedcount = 0
        Data.Lock.acquire()
        for k in Utils.SortNumerAlpha(scores.keys()):
            p = Data.people[k]
            while len(p.exams) < examnr + 1:
                p.exams.append(None)
            exam = p.exams[examnr]
            newOrChanged = False
            # we only have to save non-default values for not yet existing
            # entries or changed values for existing entries
            newtotalscore = scores[k][0]
            newdetails = scores[k][1]
            oldtotalscore = oldscores[k][0]
            olddetails = oldscores[k][1]
            # if ( exam == None ):       # only needed for the following print
            #     curtotalscore = -1
            #     curdetails = '<None>'
            # else:
            #     curtotalscore = exam.totalscore
            #     curdetails = exam.scores
            # print ( k + ': totalscore (old/cur/new): ' + str(oldtotalscore) +
            #             '/' + str(curtotalscore) + '/' + str(newtotalscore) +
            #             ' -- details (old/cur/new): "' + olddetails + '"/"' +
            #             curdetails + '"/"' + newdetails + '"' )
            if (exam == None):
                # do we have non-default values?
                if (newtotalscore != -1 or newdetails != ''):
                    exam = Data.Exam()
                    newOrChanged = True
            else:
                # has the user made changes?
                valuesChanged = ((newtotalscore != oldtotalscore)
                                 or (newdetails != olddetails))
                # are there changes with respect to the currently stored values
                # (because of changes by another user while the first user editted
                # the values)
                needsSaving = ((newtotalscore != exam.totalscore)
                               or (newdetails != exam.scores))
                # have there been changes behind our back
                changedBehindBack = ((oldtotalscore != exam.totalscore)
                                     or (olddetails != exam.scores))
                if (valuesChanged and needsSaving and changedBehindBack):
                    # the user has changed a value and additionally this value has
                    # been changed by another user while the first user editted
                    # the values; in this case we don't save our values
                    unchangedcount += 1
                    if newtotalscore == -1:
                        newtotalscorestr = '-'
                    else:
                        newtotalscorestr = locale.str(newtotalscore)
                    if oldtotalscore == -1:
                        oldtotalscorestr = '-'
                    else:
                        oldtotalscorestr = locale.str(oldtotalscore)
                    if exam.totalscore == -1:
                        curtotalscorestr = '-'
                    else:
                        curtotalscorestr = locale.str(exam.totalscore)
                    unchanged.append([
                        str(unchangedcount), k,
                        Utils.CleanWeb(p.lname) + ', ' +
                        Utils.CleanWeb(p.fname), oldtotalscorestr,
                        curtotalscorestr, newtotalscorestr, olddetails,
                        exam.scores, newdetails
                    ])
                elif (valuesChanged):
                    newOrChanged = True
                elif (exam.maxscore != maxscore
                      and (oldtotalscore != -1 or olddetails != '')):
                    newOrChanged = True
            if newOrChanged:
                exam.totalscore = newtotalscore
                exam.scores = newdetails
                exam.maxscore = maxscore
                line = AsciiData.LineTuple((k, str(examnr), str(newtotalscore),
                                            str(maxscore), newdetails))
                try:
                    Data.examdesc.AppendLine(line)
                except:
                    Data.Lock.release()
                    Utils.Error('[' + Utils.LocalTimeString() +
                                '] Failed to store exam result:\n' + line)
                    return '<em>Error: The results could not be saved.</em>'
                p.exams[examnr] = exam
                counter += 1
                if newtotalscore == -1:
                    newtotalscorestr = '-'
                else:
                    newtotalscorestr = locale.str(newtotalscore)
                table.append([
                    str(counter), k,
                    Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname),
                    newtotalscorestr, newdetails
                ])
        Data.Lock.release()

        Utils.Error('[' + Utils.LocalTimeString() + '] Changed results '
                    'for exam ' + str(examnr),
                    prefix=self.name() + ': ')
        s = '<h3>Ergebnisse von Klausur ' + str(examnr) + '</h3>\n'
        if len(unchanged) > 1:
            s += (
                '<p>Einige Werte wurden geändert, während Sie die Werte editiert '
                'haben. Daher wurden die folgenden Änderungen <strong>nicht</strong> '
                'gespeichert.')
            s += createHTMLTable(unchanged)
        s += '<p>Die folgenden Änderungen wurden gespeichert.</p>'
        s += createHTMLTable(table)
        return s
Example #23
0
 def __filteroutput(self, type="html"):
     tablerowbeforefirst = '<tr>\n'
     tablerowinbetween = '\n</tr>\n<tr>\n'
     tablerowafterlast = '\n</tr>\n'
     tablecellbeforefirst = '<td>'
     tablecellinbetween = '</td><td>'
     tablecellafterlast = '</td>'
     tableheadinbetween = '</th><th>'
     reltext = {
         'equal': '=',
         'greater': '&gt;',
         'greaterequal': '&gt;=',
         'less': '&lt;',
         'lessequal': '&lt;=',
         'notequal': 'not equal to',
         'begins': 'begins with',
         'contains': 'contains',
         'ends': 'ends with'
     }
     masklist = [('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;')]
     if type == "text":
         tablerowbeforefirst = ''
         tablerowinbetween = '\n'
         tablerowafterlast = '\n'
         tablecellbeforefirst = ''
         tablecellinbetween = ':'
         tablecellafterlast = ''
         tableheadinbetween = ':'
         reltext = {
             'equal': '=',
             'greater': '>',
             'greaterequal': '>=',
             'less': '<',
             'lessequal': '<=',
             'notequal': 'not equal to',
             'begins': 'begins with',
             'contains': 'contains',
             'ends': 'ends with'
         }
         masklist = []
     if type == "csv":
         tablerowbeforefirst = ''
         tablerowinbetween = '\n'
         tablerowafterlast = '\n'
         tablecellbeforefirst = '"'
         tablecellinbetween = '";"'
         tablecellafterlast = '"'
         tableheadinbetween = '";"'
         reltext = {
             'equal': '=',
             'greater': '>',
             'greaterequal': '>=',
             'less': '<',
             'lessequal': '<=',
             'notequal': 'not equal to',
             'begins': 'begins with',
             'contains': 'contains',
             'ends': 'ends with'
         }
         masklist = []
     if type == "latex":
         tablerowbeforefirst = ''
         tablerowinbetween = ' \\\\\n'
         tablerowafterlast = '\n'
         tablecellbeforefirst = ''
         tablecellinbetween = ' & '
         tablecellafterlast = ''
         tableheadinbetween = '} & \\textbf{'
         reltext = {
             'equal': '$=$',
             'greater': '$>$',
             'greaterequal': '$\\geq$',
             'less': '$<$',
             'lessequal': '$\\leq$',
             'notequal': '$\\neq$',
             'begins': 'begins with',
             'contains': 'contains',
             'ends': 'ends with'
         }
         masklist = [('\\', '\\textbackslash '), ('{', '\\{'), ('}', '\\}'),
                     ('\\textbackslash ', '\\textbackslash{}'),
                     ('"', '\\textquotedbl{}'), ('#', '\\#'), ('$', '\\$'),
                     ('%', '\\%'), ('&', '\\&'), ('<', '\\textless{}'),
                     ('>', '\\textgreater{}'), ('[', '\\relax['),
                     (']', '\\relax]'), ('^', '\\^{}'), ('_', '\\_'),
                     ('|', '\\textbar{}'), ('~', '\\~{}')]
     totalcount = 0
     filtercount = 0
     resultlist = []
     for k in Utils.SortNumerAlpha(Data.people.keys()):
         p = Data.people[k]
         vardict = {}
         vardict["i"] = k
         vardict["n"] = p.lname
         vardict["f"] = p.fname
         vardict["s"] = p.sem
         vardict["g"] = p.group
         vardict["a"] = p.stud
         vardict["m"] = p.email
         totalintscore = 0.0
         for sheetnr, sheetname, sheet in Exercises.SheetList():
             if not sheet.IsClosed(): continue
             if not sheet.counts: continue
             vardict[str(sheetnr) + "c"] = -1
             if p.mcresults.has_key(sheetname):
                 vardict[str(sheetnr) + "c"] = p.mcresults[sheetname].score
                 totalintscore += p.mcresults[sheetname].score
         vardict["C"] = totalintscore
         totalhomescore = 0.0
         for sheetnr, sheetname, sheet in Exercises.SheetList():
             if not sheet.IsClosed(): continue
             if not sheet.counts: continue
             vardict[str(sheetnr) + "h"] = -1
             if p.homework.has_key(sheetname) and \
              p.homework[sheetname].totalscore <> -1:
                 vardict[str(sheetnr) +
                         "h"] = p.homework[sheetname].totalscore
                 totalhomescore += p.homework[sheetname].totalscore
         vardict["H"] = totalhomescore
         vardict["T"] = totalintscore + totalhomescore
         totalexamscore = 0.0
         for i in range(Data.Exam.maxexamnumber):
             if i >= len(p.exams) or p.exams[i] == None or \
              p.exams[i].totalscore < 0:
                 vardict[str(i) + "e"] = -1
             else:
                 vardict[str(i) + "e"] = p.exams[i].totalscore
                 totalexamscore += p.exams[i].totalscore
             vardict[str(i) + "r"] = "no"
             if i < len(p.exams) and p.exams[i] <> None:
                 if p.exams[i].registration == 1:
                     vardict[str(i) + "r"] = "yes"
         vardict["E"] = totalexamscore
         for i in range(len(self.__persondatakeys)):
             try:
                 vardict["%dd" % i] = p.persondata[self.__persondatakeys[i]]
             except:
                 vardict["%dd" % i] = ""
         filter = True
         for i in range(5):
             if self.__fieldlist[i] <> None:
                 val1 = vardict[self.__fieldlist[i]]
                 val2 = self.__vallist[i]
                 if len(val2) >= 2 and val2[0] == '"' and val2[-1] == '"':
                     val2 = val2[1:-1]
                     val1 = str(val1)
                 else:
                     try:
                         val1 = int(val1)
                         val2 = int(val2)
                     except:
                         try:
                             val1 = float(val1)
                             val2 = float(val2)
                         except:
                             pass
                 if self.__rellist[i] == "equal":
                     if not val1 == val2: filter = False
                 if self.__rellist[i] == "greater":
                     if not val1 > val2: filter = False
                 if self.__rellist[i] == "greaterequal":
                     if not val1 >= val2: filter = False
                 if self.__rellist[i] == "less":
                     if not val1 < val2: filter = False
                 if self.__rellist[i] == "lessequal":
                     if not val1 <= val2: filter = False
                 if self.__rellist[i] == "notequal":
                     if not val1 <> val2: filter = False
                 if self.__rellist[i] == "begins":
                     if not str(val1)[:len(str(val2))] == str(val2):
                         filter = False
                 if self.__rellist[i] == "contains":
                     if not str(val2) in str(val1): filter = False
                 if self.__rellist[i] == "ends":
                     if not str(val1)[-len(str(val2)):] == str(val2):
                         filter = False
         totalcount += 1
         if filter:
             filtercount += 1
             sortkey = self.__sortkey.replace("%%", "_!_/_")
             for var in vardict.keys():
                 sortkey = sortkey.replace("%%%s" % var, str(vardict[var]))
             sortkey = sortkey.replace("_!_/_", "%")
             sortkey = stringtosortkey(sortkey)
             msg = self.__msg.replace("%%", "_!_/_")
             for var in vardict.keys():
                 if var[-1:] in ["i", "n", "f", "a", "m", "r", "d"]:
                     msg = msg.replace('%%%s' % var,
                                       Utils.Protect(str(vardict[var])))
                 elif var[-1:] in ["s", "g"]:
                     msg = msg.replace("%%%s" % var, str(vardict[var]))
                 else:
                     msg = msg.replace("%%%s" % var,
                                       locale.str(vardict[var]))
             msg = outputstring(msg, masklist, deletecolon=False)
             msg = msg.replace(":", tablecellinbetween)
             msg = msg.replace("_!_/_", "%")
             resultlist.append([sortkey, (k, p.lname, p.fname, msg)])
     resultlist.sort()
     filteroutput = tablerowbeforefirst
     isfirst = True
     for sortkey, (k, ln, fn, msg) in resultlist:
         if not isfirst: filteroutput += tablerowinbetween
         isfirst = False
         filteroutput += tablecellbeforefirst
         #filteroutput += outputstring(k, masklist)
         #filteroutput += tablecellinbetween
         #filteroutput += outputstring(ln, masklist)
         #filteroutput += tablecellinbetween
         #filteroutput += outputstring(fn, masklist)
         if self.__msg <> "":
             #filteroutput += tablecellinbetween
             filteroutput += msg
         filteroutput += tablecellafterlast
     filteroutput += tablerowafterlast
     filterinfo = ["", "", "", "", filtercount, totalcount]
     #filterinfo[0] = '%i:%n:%f'
     #if self.__msg <> "": filterinfo[0] += ":" + self.__msg
     filterinfo[0] = self.__msg
     if not self.__shortcolhead:
         for var, fieldtitle in self.__vartofieldtitle.iteritems():
             filterinfo[0] = filterinfo[0].replace(
                 "%%%s" % var, Utils.Protect(fieldtitle))
     filterinfo[0] = outputstring(filterinfo[0],
                                  masklist,
                                  deletecolon=False)
     filterinfo[0] = filterinfo[0].replace(":", tableheadinbetween)
     filtercriteria = []
     for i in range(5):
         if self.__fieldlist[i] <> None and self.__rellist[i] <> None:
             filtercriteria.append \
              (outputstring(self.__vartofieldtitle[self.__fieldlist[i]], masklist))
             filtercriteria[-1] += " " + reltext[self.__rellist[i]]
             filtercriteria[-1] += " " + outputstring(
                 self.__vallist[i], masklist)
     if filtercriteria <> []:
         filterinfo[1] = " and ".join(filtercriteria)
     filterinfo[2] = self.__sortkey.replace(" ", ", ")
     for var, fieldtitle in self.__vartofieldtitle.iteritems():
         filterinfo[2] = filterinfo[2].replace(
             "%%%s" % var, outputstring(fieldtitle, masklist))
     filterinfo[3] = Utils.LocalTimeString()
     return filterinfo, filteroutput
Example #24
0
    def createSuccessMessage(self):
        examnr = self.examnr
        # evaluate the changes
        registrations = {}
        l = Utils.SortNumerAlpha(Data.people.keys())
        for k in l:
            p = Data.people[k]
            wasRegistered = (examnr < len(p.exams) and p.exams[examnr] != None
                             and p.exams[examnr].registration == 1)
            shouldBeRegistered = self.options.has_key('T' + k)
            if wasRegistered != shouldBeRegistered:
                registrations[k] = int(shouldBeRegistered)

        # put the changes into the database
        registered = []
        unregistered = []
        Data.Lock.acquire()
        timestamp = int(time.time())
        for k in Utils.SortNumerAlpha(registrations.keys()):
            v = registrations[k]
            line = AsciiData.LineTuple(
                (k, str(examnr), str(v), str(timestamp)))
            try:
                Data.examregdesc.AppendLine(line)
            except:
                Data.Lock.release()
                Utils.Error('[' + Utils.LocalTimeString() +
                            '] Failed to register person for exam:\n' + line)
                return '<emph>Error: The changes could not be saved.</emph>'
            p = Data.people[k]
            while len(p.exams) < examnr + 1:
                p.exams.append(None)
            if p.exams[examnr] == None:
                p.exams[examnr] = Data.Exam()
            p.exams[examnr].timestamp = timestamp
            p.exams[examnr].registration = v
            if Data.Exam.maxexamnumber < examnr + 1:
                Data.Exam.maxexamnumber = examnr + 1
            line = (Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname) +
                    ' (' + k + ')')
            if v == 1:
                registered.append(line)
            else:
                unregistered.append(line)
        Data.Lock.release()

        Utils.Error('[' + Utils.LocalTimeString() + '] Changed registrations '
                    'for exam ' + str(examnr),
                    prefix='BulkExamRegistration: ')
        s = '<h3>An-/Abmeldung von Klausur ' + str(examnr) + '</h3>\n'
        if len(registered) > 0:
            s += ('<div>Die folgenden Personen wurden zur Klausur angemeldet:'
                  '</div>\n'
                  '<ul>\n<li>' + str('</li>\n<li>').join(registered) +
                  '</li>\n</ul>\n')
        if len(unregistered) > 0:
            s += ('<div>Die folgenden Personen wurden von der Klausur '
                  ' abgemeldet:</div>\n'
                  '<ul>\n<li>' + str('</li>\n<li>').join(unregistered) +
                  '</li>\n</ul>\n')
        return s
Example #25
0
import os, sys, string, time, tempfile, traceback, locale, signal

import Config  # this automatically determines our home dir
# but does not read the configuration file

# try to get correct locale from environment
try:
    locale.setlocale(locale.LC_ALL, '')
except:
    pass

# Fetch the "Utils" and switch error reporting to log file:
from fmTools import Utils
Utils.ErrorLogFileName = os.path.join(Config.home, 'log/server.log')
Utils.currentError = Utils.ErrorToLogfile
Utils.Error(time.asctime(time.localtime()) + ' Starting server...', prefix='')

# Now we can read our configuration file with proper error reporting
# (note that this might fail miserably):

Config.ReadConfig()
Config.PostProcessing()  # some postprocessing of configuration data

# We perform a few sanity checks and give appropriate messages:
if not (os.path.isdir(Config.conf['DocumentRoot'])):
    Utils.Error('Cannot find DocumentRoot directory: ' +
                Config.conf['DocumentRoot'])
    Utils.Error('Aborting.', prefix='')
    sys.exit(0)
if not (os.path.isdir(os.path.join(Config.conf['DocumentRoot'], 'images'))):
    Utils.Error('DocumentRoot directory does not contain an "images" '