def buildAllSeries(self): """Builds all configured Series""" seriesConfigFiles = os.listdir(self.__seriesConfigDir) seriesConfigFiles = Utils.natsort(seriesConfigFiles) #seriesConfigFiles.sort() if os.path.isdir(self.__smscmoodleOutputDir): shutil.rmtree(self.__smscmoodleOutputDir) os.mkdir(self.__smscmoodleOutputDir) self.__outputDir = self.__smscmoodleOutputDir for config in seriesConfigFiles: if not config.startswith("."): self.__log.debug("Will treat from file: "+config+" serie:"+config.split(".")[0].partition("serie")[2]) self.__serie=config.split(".")[0].partition("serie")[2] self.__log.info("Found Serie "+self.__serie+". Will now build it.") self.buildSerie()
def makeWorkbook(self): seriesConfigFiles = os.listdir(self.__seriesConfigDir) #seriesConfigFiles.sort() seriesConfigFiles = Utils.natsort(seriesConfigFiles) if os.path.isdir(self.__smscmoodleOutputDir): shutil.rmtree(self.__smscmoodleOutputDir) os.mkdir(self.__smscmoodleOutputDir) self.__outputDir = self.__smscmoodleOutputDir for config in seriesConfigFiles: self.__serie=int(config.split(".")[0].partition("serie")[2]) self.__log.info("Found Serie "+str(self.__serie)+". Will now build it.") seriesConfig = ConfigParser.SafeConfigParser() self.__log.debug("Reading "+self.__seriesConfigDir+"/serie"+str(self.__serie)+".cfg") seriesConfig.read(self.__seriesConfigDir+"/"+config) titles = seriesConfig.get('Serie', 'titles') numbers = seriesConfig.get('Serie', 'exo-numbers') outputDir = self.__smscmoodleOutputDir seriesname = str(self.__serie)+"serie" seriesname = self.__doCreateSerie(titles.split(','), numbers.split(','), outputDir, seriesname) solutionname = str(self.__serie)+"solution" solutionname = self.__doCreateSolution(titles.split(','), numbers.split(','), outputDir, solutionname) self.__makeWorkBookTitlePage(outputDir) if self.__usepdftk: subprocess.call(["pdftk "+outputDir+"/*.pdf cat output workbook.pdf"], shell=True, cwd="./", stdout=DEVNULL, stderr=STDOUT) else: subprocess.call(["gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=workbook.pdf "+outputDir+"/*.pdf"], shell=True, cwd="./", stdout=DEVNULL, stderr=STDOUT) shutil.rmtree(self.__smscmoodleOutputDir) Utils.cleanTempFiles(self.__keepTempFiles)
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 doMakeWorkbook(self): """Creates on big pdf containig all passed exams""" examConfigFiles = os.listdir(self.__examProperties) #seriesConfigFiles.sort() examConfigFiles = Utils.natsort(examConfigFiles) if os.path.isdir(self.__smscExamOutputDir): shutil.rmtree(self.__smscExamOutputDir) os.mkdir(self.__smscExamOutputDir) self.__outputDir = self.__smscExamOutputDir for config in examConfigFiles: self.__exam=config.split(".")[0].partition("exam")[2] self.__log.info("Found Exam "+str(self.__exam)+". Will now build it.") seriesConfig = ConfigParser.SafeConfigParser() self.__log.debug("Reading "+self.__examProperties+"/exam"+str(self.__exam)+".cfg") 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') outputDir=self.__smscExamOutputDir for lang in self.__languages: examName = str(self.__exam)+"-"+lang examName = self.__doCreateExam(titles.split(','), numbers.split(','), outputDir, date, percentages, lang, False, examName) outputDir = self.__smscExamOutputDir solutionname = str(self.__exam)+"-solution" solutionname = self.__doCreateSolution(titles.split(','), numbers.split(','), outputDir, date, percentages, solutionname) self.__makeWorkBookTitlePage(outputDir) if self.__usepdftk: subprocess.call(["pdftk "+outputDir+"/*.pdf cat output workbook.pdf"], shell=True, cwd="./", stdout=DEVNULL, stderr=STDOUT) else: subprocess.call(["gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=workbook.pdf "+outputDir+"/*.pdf"], shell=True, cwd="./", stdout=DEVNULL, stderr=STDOUT) shutil.rmtree(self.__smscExamOutputDir) Utils.cleanTempFiles([])
def doBuildAllExams(self): """Builds all configured Exams""" examConfigFiles = os.listdir(self.__examProperties) #seriesConfigFiles = Utils.natsort(examConfigFiles) examConfigFiles.sort() if os.path.isdir(self.__smscExamOutputDir): shutil.rmtree(self.__smscExamOutputDir) os.mkdir(self.__smscExamOutputDir) self.__outputDir = self.__smscExamOutputDir for config in examConfigFiles: if not config.startswith("."): self.__log.debug("Will treat from file: "+config)#+" serie:"+config.split(".")[0].partition("serie")[2]) #self.__exam=int(config.split(".")[0].partition("serie")[2]) #self.__log.info("Found Serie "+str(self.__exam)+". Will now build it.") self.__exam=config.split("exam")[1].partition(".")[0] self.__log.info("Found Exam "+self.__exam+". Will now build it.") self.doBuildExam()
def script(cls): args = docopt(cls.__doc__) config = args['<config>'] if '#' in config: config, section = config.split('#') else: section = 'chapman' _setup_logging(config) cp = ConfigParser() cp.read(config) settings = dict(cp.items(section)) app_section = settings.pop('app') app_context = bootstrap('{}#{}'.format(config, app_section)) settings = cls.settings_schema.to_python(settings) if args['--name']: settings['name'] = args['--name'] self = cls(**settings) self.run( app_context['app'], app_context['registry'], int(args['--concurrency']), bool(args['--debug']))
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)