def processTemplate(self): ### process in one step template_full_path = os.path.join(self.inputPath, self.templateFile) self.make_sure_path_exists(template_full_path) lines = self.readFile(template_full_path) output_dir = os.path.join(self.outputPath) self.make_sure_path_exists(output_dir) self.output_dir = output_dir print self.output_dir self.outFile = os.path.join(self.output_dir, self.outFile) # Iterate over the lines of the file for line in lines: if not line.startswith('{%'): self.writeOutputFile(self.outFile, line) else: # process the line containing directives content = self.findBetween(line, Constants.constants.STARTTAG, Constants.constants.ENDTAG) fields = re.split(':', content) directCommand = fields[0].strip() directContent = fields[1].strip() if directCommand in Constants.constants.LOADDIRECTIVES: full_path = os.path.join(self.inputPath, directContent) if directCommand == 'LoadStyleSheet': styleProcessor = StylesheetYamlProcessor(full_path) styleDict = styleProcessor.readYaml() else: graphDataProcessor = GraphDataProcessor(full_path) graphDataDict = graphDataProcessor.readYaml() if directCommand in Constants.constants.STYLEDIRECTIVES: if styleDict[directContent]: contentFields = directContent.split('.') s = '%s[' % (contentFields[0].strip()) strList = list() strList.append(s) #print aline for key, value in styleDict[directContent].iteritems(): #print key, '=', value s = '%s="%s"\t' % (key, value) strList.append(s) #aline = aline.join(s) #s = '' strList.append(']') s = ''.join(strList) #print s self.writeOutputFile(self.outFile, s) if directCommand in Constants.constants.DATADIRECTIVES: if graphDataDict[directContent]: self.writeOutputFile(self.outFile, str(graphDataDict[directContent]))
def processTemplate(self): ### process in one step template_full_path = os.path.join(self.inputPath, self.templateFile) self.make_sure_path_exists(template_full_path) lines = self.readFile(template_full_path) output_dir = os.path.join(self.outputPath) self.make_sure_path_exists(output_dir) self.output_dir = output_dir print self.output_dir self.outFile = os.path.join(self.output_dir, self.outFile) # Iterate over the lines of the file for line in lines: if not line.startswith("{%"): self.writeOutputFile(self.outFile, line) else: # process the line containing directives content = self.findBetween(line, Constants.constants.STARTTAG, Constants.constants.ENDTAG) fields = re.split(":", content) directCommand = fields[0].strip() directContent = fields[1].strip() if directCommand in Constants.constants.LOADDIRECTIVES: full_path = os.path.join(self.inputPath, directContent) if directCommand == "LoadStyleSheet": styleProcessor = StylesheetYamlProcessor(full_path) styleDict = styleProcessor.readYaml() else: graphDataProcessor = GraphDataProcessor(full_path) graphDataDict = graphDataProcessor.readYaml() if directCommand in Constants.constants.STYLEDIRECTIVES: if styleDict[directContent]: contentFields = directContent.split(".") s = "%s[" % (contentFields[0].strip()) strList = list() strList.append(s) # print aline for key, value in styleDict[directContent].iteritems(): # print key, '=', value s = '%s="%s"\t' % (key, value) strList.append(s) # aline = aline.join(s) # s = '' strList.append("]") s = "".join(strList) # print s self.writeOutputFile(self.outFile, s) if directCommand in Constants.constants.DATADIRECTIVES: if graphDataDict[directContent]: self.writeOutputFile(self.outFile, str(graphDataDict[directContent]))
def processTemplateT1(self, T2outFileName, resultFileName): ## step T1: apply styling rules to the output of T2 stepT2_output_path = os.path.join(self.output_dir, T2outFileName) self.make_sure_path_exists(stepT2_output_path) lines = self.readFile(stepT2_output_path) output_file = os.path.join(self.output_dir, resultFileName) stepT1_output_file = os.path.join(self.output_dir, 'default_output.gv') # Iterate over the lines of the file for line in lines: if not line.startswith('{%'): self.writeOutputFile(stepT1_output_file, line) else: # process the line containing directives content = self.findBetween(line, Constants.constants.STARTTAG, Constants.constants.ENDTAG) fields = re.split(':', content) directCommand = fields[0].strip() directContent = fields[1].strip() if directCommand in Constants.constants.LOADDIRECTIVES: if directCommand == 'LoadStyleSheet': full_path = os.path.join(self.inputPath, directContent) styleProcessor = StylesheetYamlProcessor(full_path) styleDict = styleProcessor.readYaml() if directCommand in Constants.constants.STYLEDIRECTIVES: if styleDict[directContent]: contentFields = directContent.split('.') s = '%s[' % (contentFields[0].strip()) strList = list() strList.append(s) #print aline for key, value in styleDict[directContent].iteritems(): #print key, '=', value s = '%s="%s"\t' % (key, value) strList.append(s) strList.append(']') s = ''.join(strList) #print s self.writeOutputFile(stepT1_output_file, s) # copy the default output file to the final result file, otherwise the default output file name is "default_output.gv" if resultFileName: shutil.copy(stepT1_output_file, output_file) os.remove(stepT1_output_file) # delete the output file from step T2 os.remove(stepT2_output_path)
def processTemplateT1(self, T2outFileName, resultFileName): ## step T1: apply styling rules to the output of T2 stepT2_output_path = os.path.join(self.output_dir, T2outFileName) self.make_sure_path_exists(stepT2_output_path) lines = self.readFile(stepT2_output_path) output_file = os.path.join(self.output_dir, resultFileName) stepT1_output_file = os.path.join(self.output_dir, "default_output.gv") # Iterate over the lines of the file for line in lines: if not line.startswith("{%"): self.writeOutputFile(stepT1_output_file, line) else: # process the line containing directives content = self.findBetween(line, Constants.constants.STARTTAG, Constants.constants.ENDTAG) fields = re.split(":", content) directCommand = fields[0].strip() directContent = fields[1].strip() if directCommand in Constants.constants.LOADDIRECTIVES: if directCommand == "LoadStyleSheet": full_path = os.path.join(self.inputPath, directContent) styleProcessor = StylesheetYamlProcessor(full_path) styleDict = styleProcessor.readYaml() if directCommand in Constants.constants.STYLEDIRECTIVES: if styleDict[directContent]: contentFields = directContent.split(".") s = "%s[" % (contentFields[0].strip()) strList = list() strList.append(s) # print aline for key, value in styleDict[directContent].iteritems(): # print key, '=', value s = '%s="%s"\t' % (key, value) strList.append(s) strList.append("]") s = "".join(strList) # print s self.writeOutputFile(stepT1_output_file, s) # copy the default output file to the final result file, otherwise the default output file name is "default_output.gv" if resultFileName: shutil.copy(stepT1_output_file, output_file) os.remove(stepT1_output_file) # delete the output file from step T2 os.remove(stepT2_output_path)