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)
Exemple #2
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)
    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")
Exemple #4
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")
Exemple #5
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")