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 processTemplateT2(self, path, T2outFileName):
        ## step T2: extend the graph to replace directives (Nodes, Edges) with the selected graph data

        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(path)
        self.make_sure_path_exists(output_dir)
        self.output_dir = output_dir
        stepT2_output_path = os.path.join(output_dir, T2outFileName)

        # Iterate over the lines of the file
        for line in lines:
            if not line.startswith('{%'):
                self.writeOutputFile(stepT2_output_path, 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 == 'LoadData':
                        full_path = os.path.join(self.inputPath, directContent)
                        graphDataProcessor = GraphDataProcessor(full_path)
                        graphDataDict = graphDataProcessor.readYaml()
                    else:
                        self.writeOutputFile(
                            stepT2_output_path,
                            line)  # keep the LoadStyleSheet directive

                if directCommand in Constants.constants.DATADIRECTIVES:
                    if graphDataDict[directContent]:
                        self.writeOutputFile(stepT2_output_path,
                                             str(graphDataDict[directContent]))

                if directCommand in Constants.constants.STYLEDIRECTIVES:
                    self.writeOutputFile(
                        stepT2_output_path,
                        line)  # not process style directives at step T2
    def processTemplateT2(self, path, T2outFileName):
        ## step T2: extend the graph to replace directives (Nodes, Edges) with the selected graph data

        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(path)
        self.make_sure_path_exists(output_dir)
        self.output_dir = output_dir
        stepT2_output_path = os.path.join(output_dir, T2outFileName)

        # Iterate over the lines of the file
        for line in lines:
            if not line.startswith("{%"):
                self.writeOutputFile(stepT2_output_path, 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 == "LoadData":
                        full_path = os.path.join(self.inputPath, directContent)
                        graphDataProcessor = GraphDataProcessor(full_path)
                        graphDataDict = graphDataProcessor.readYaml()
                    else:
                        self.writeOutputFile(stepT2_output_path, line)  # keep the LoadStyleSheet directive

                if directCommand in Constants.constants.DATADIRECTIVES:
                    if graphDataDict[directContent]:
                        self.writeOutputFile(stepT2_output_path, str(graphDataDict[directContent]))

                if directCommand in Constants.constants.STYLEDIRECTIVES:
                    self.writeOutputFile(stepT2_output_path, line)  # not process style directives at step T2