def __makeWorkBookTitlePage(self, _outputDir):
     texfile = "/tmp/0wbtitlepage.tex"
     wbtitle = open(texfile, 'w')
     latex = LaTeX(self.__examProperties+"/exam"+self.__exam+".cfg",self.__smsclecturer, self.__smscname, '', 'solution', self.__smscunilogo, self.__smscgroupelogo, self.__smscpdftitle, self.__smscpdfauthor, self.__smscpdfkeyword, self.__noCiteList, 'french')
     latex.makeWorkBookTitlePageHeader(wbtitle)
     examConfigFiles = os.listdir(self.__examProperties)
     examConfigFiles = Utils.natsort(examConfigFiles)
     for config in examConfigFiles:
         seriesConfig = ConfigParser.SafeConfigParser()
         seriesConfig.read(self.__examProperties+"/"+config)
         titles = seriesConfig.get('Exam', 'titles')
         numbers = seriesConfig.get('Exam', 'exo-numbers')
         date = seriesConfig.get('Exam', 'date')
         percentages = seriesConfig.get('Exam', 'percentage')
         examnumber = config.split(".")[0].partition("exam")[2]
         wbtitle.write(r"\textsf{ \textbf{Exam "+examnumber+"}} \dotfill"+"\n")
         for number in numbers.split(","):
             wbtitle.write(number+"\n")
         wbtitle.write(r"\begin{itemize}"+"\n")
         for title in titles.split(","):
             wbtitle.write(r"\item "+title+"\n")
         wbtitle.write(r"\end{itemize}"+"\n")
     latex.printWorkBookTitlePageFooter(wbtitle)
     wbtitle.close()
     Utils.doLatex(texfile, _outputDir, True)
    def doMakeCatalogue(self):
        """Creates on big pdf containing all available exercises"""
        outputDir = "Catalogue"
        if os.path.isdir(outputDir):
            shutil.rmtree(outputDir)
        os.mkdir(outputDir)
        afile = "/tmp/catalog.tex"
        catalog = open(afile, 'w')
        latex = LaTeX(self.__examProperties+"/exam"+self.__exam+".cfg", self.__smsclecturer, self.__smscname, '', 'solution', self.__smscunilogo, self.__smscgroupelogo, self.__smscpdftitle, self.__smscpdfauthor, self.__smscpdfkeyword, self.__noCiteList, 'french')
        latex.createHeader(catalog, True)
        catalog.write(r'\renewcommand{\exercice}[1]{\subsection*{Problem: #1}}'+"\n")
        catalog.write(r'\renewcommand{\solution}[1]{\subsection*{Solution: #1}}'+"\n")
        catalog.write(r'\renewcommand{\question}[1]{\subsubsection*{#1}}'+"\n")
        catalog.write(r''+"\n")
        catalog.write(r'\makeatletter'+"\n")
        catalog.write(r'\renewcommand{\section}{\@startsection{section}{3}{2pt}{12pt}{10pt}{\center \huge \sffamily \bfseries}}'+"\n")
        catalog.write(r'\renewcommand{\thesection}{(\roman{section})}'+"\n")
        catalog.write(r'\renewcommand{\thesubsection}{(\roman{subsection})}'+"\n")
        exos = os.listdir(self.__exerciseDir)
        exos = Utils.natsort(exos)
        for exo in exos:
            if exo.find("ex") != -1:
                number = exo[2:]
                catalog.write(r'\section*{Exercise '+number+'}'+"\n")
                catalog.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exerciseDir+'/ex'+number+'/latex/ressources}'+'\n')
                for lang in self.__languages:
                    catalog.write(r'\renewcommand{\exercice}[1]{\subsection*{Problem '+lang+': #1}}'+"\n")
                    exo = open(os.path.join(os.path.join(self.__exerciseDir, "ex"+number),"latex/exo-"+lang+".tex"), 'r')
                    for line in exo:
                        catalog.write(line)
                    exo.close()
                catalog.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exerciseDir+'/ex'+number+'/latex/ressources}'+'\n')
                catalog.write(r'\renewcommand{\exercice}[1]{\subsection*{Solution: #1}}'+"\n")
                solution = open(os.path.join(os.path.join(self.__exerciseDir, "ex"+number),"latex/exo-solution.tex"), 'r')
                for line in solution:
                    catalog.write(line)
                solution.close()
                if self.__smscaddClearPage:
                    catalog.write("\clearpage")
        

        latex.createFooter(catalog)
        catalog.close()
        Utils.doLatex(afile, outputDir)
        basename = os.path.split(afile)[1].split(".")[0]
        shutil.move(os.path.join(outputDir, basename+".pdf"), basename+".pdf")
        shutil.rmtree(outputDir)
    def __doCreateSolution(self, titles, numbers, outputDir, date, percentages, filename = None):
        filename = filename or "solution"+str(self.__exam)
        texfile = os.path.join("/tmp/", filename+".tex")
        solution = open(texfile, 'w')
        latex = LaTeX(self.__examProperties+"/exam"+self.__exam+".cfg", self.__smsclecturer, self.__smscname, '', 'solution', self.__smscunilogo, self.__smscgroupelogo, self.__smscpdftitle, self.__smscpdfauthor, self.__smscpdfkeyword, self.__noCiteList, 'french')
        latex.createHeader(solution, True)

        for number in numbers:
            solution.write(r"\newpage"+"\n")
            solution.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exerciseDir+'/ex'+number+'/latex/ressources}'+'\n')
            exo = open(self.__exerciseDir+"/"+"ex"+number+"/latex/exo-solution.tex", 'r')
            for line in exo:
                solution.write(line)

        latex.createFooter(solution)
        solution.close()

        Utils.doLatex(texfile, outputDir)
        return os.path.join(outputDir, filename+".pdf")
예제 #4
0
    def makeCatalogue(self):
        """Creates a pdf containing all exercises. Each exercise is always followed by its solution"""
        afile = "/tmp/catalogue.tex"
        self.__serie=0
        if os.path.isdir("Catalogue"):
            shutil.rmtree("Catalogue")
        os.mkdir("Catalogue")
        catalogue = open(afile, 'w') #use open(file 'a') for appending to a given file
        latex = LaTeX(self.__serie)
        latex.createHeader(catalogue, [])
        catalogue.write(r'\renewcommand{\exercice}[1]{\subsection*{Problem: #1}}'+"\n")
        catalogue.write(r'\renewcommand{\solution}[1]{\subsection*{Solution: #1}}'+"\n")
        catalogue.write(r'\renewcommand{\question}[1]{\subsubsection*{#1}}'+"\n")
        catalogue.write(r''+"\n")
        catalogue.write(r'\makeatletter'+"\n")
        catalogue.write(r'\renewcommand{\section}{\@startsection{section}{3}{2pt}{12pt}{10pt}{\center \huge \sffamily \bfseries}}'+"\n")
        catalogue.write(r'\renewcommand{\thesection}{(\roman{section})}'+"\n")
        catalogue.write(r'\renewcommand{\thesubsection}{(\roman{subsection})}'+"\n")
        exos = os.listdir(self.__exoDirName)
        #exos.sort()
        exos = Utils.natsort(exos)
        for exo in exos:
            if exo.find("ex") != -1:
                number = exo[2:]
                catalogue.write(r'\section*{Exercise '+number+'}'+"\n")
                catalogue.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/resources}'+'\n')
                exo = open(os.path.join(os.path.join(self.__exoDirName, "ex"+number),"latex/exo.tex"), 'r')
                for line in exo:
                    catalogue.write(line)
                exo.close()
                catalogue.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/resources}'+'\n')
                solution = open(os.path.join(os.path.join(self.__exoDirName, "ex"+number),"latex/exosol.tex"), 'r')
                for line in solution:
                    catalogue.write(line)
                solution.close()
                if self.__smscaddClearPage:
                    catalogue.write("\clearpage")


        latex.createFooter(catalogue)
        catalogue.close()
        outputDir = "Catalogue"
        Utils.doLatex(afile, outputDir, True)
        basename = os.path.split(afile)[1].split(".")[0]
        shutil.move(os.path.join(outputDir, basename+".pdf"), basename+".pdf")
        shutil.rmtree(outputDir)
예제 #5
0
    def __doCreateSolution(self, _titles, _numbers, _outputDir, filename = None):
        filename = filename or "solution"+str(self.__serie)
        texfile = os.path.join("/tmp/", filename+".tex")
        solution = open(texfile, 'w')
        latex = LaTeX(self.__serie)
        latex.createHeader(solution, _titles, True)

        for number in _numbers:
            solution.write(r'\setcounter{section}{'+number+'}\n')
            solution.write(r'\addtocounter{section}{-1}'+'\n')
            solution.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/ressources}'+'\n')
            exo = open(self.__exoDirName+"/"+"ex"+number+"/latex/exosol.tex", 'r')
            for line in exo:
                solution.write(line)

        latex.createFooter(solution)
        solution.close()

        Utils.doLatex(texfile, _outputDir)
        return os.path.join(_outputDir, filename+".pdf")
예제 #6
0
    def __doCreateSerie(self, _titles, _numbers, _outputDir, filename = None):
        filename = filename or "serie"+str(self.__serie)
        texfile = os.path.join("/tmp/", filename+".tex")
        serie = open(texfile, 'w') #use open(file 'a') for appending to a given file
        self.__smscsolutiontext = ''
        latex = LaTeX(self.__serie)
        latex.createHeader(serie, _titles)

        for number in _numbers:
            serie.write(r'\setcounter{section}{'+number+'}\n')
            serie.write(r'\addtocounter{section}{-1}'+'\n')
            serie.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/ressources}'+'\n')
            exo = open(self.__exoDirName+"/"+"ex"+number+"/latex/exo.tex", 'r')
            for line in exo:
                serie.write(line)

        latex.createFooter(serie)
        serie.close()

        Utils.doLatex(texfile, _outputDir)
        return os.path.join(_outputDir, filename+".pdf")
예제 #7
0
 def __makeWorkBookTitlePage(self, _outputDir):
     texfile = "/tmp/0wbtitlepage.tex"
     wbtitle = open(texfile, 'w')
     latex = LaTeX(self.__serie)
     latex.makeWorkBookTitlePageHeader(wbtitle)
     seriesConfigFiles = os.listdir(self.__seriesConfigDir)
     #seriesConfigFiles.sort()
     seriesConfigFiles = Utils.natsort(seriesConfigFiles)
     for config in seriesConfigFiles:
         seriesConfig = ConfigParser.SafeConfigParser()
         seriesConfig.read(self.__seriesConfigDir+"/"+config)
         titles = seriesConfig.get('Serie', 'titles')
         numbers = seriesConfig.get('Serie', 'exo-numbers')
         serienumber = config.split(".")[0].partition("serie")[2]
         wbtitle.write(r"\textsf{ \textbf{S{\'e}rie "+serienumber+"}} \dotfill"+"\n")
         for number in numbers.split(","):
             wbtitle.write(number+"\n")
         wbtitle.write(r"\begin{itemize}"+"\n")
         for title in titles.split(","):
             wbtitle.write(r"\item "+title+"\n")
         wbtitle.write(r"\end{itemize}"+"\n")
     latex.printWorkBookTitlePageFooter(wbtitle)
     wbtitle.close()
     Utils.doLatex(texfile, _outputDir, True)