# Path: Turbine/file_parser/turbine_parser.py
# def read_tur_file(filename):
#     open_file = open(filename, "r")
#     name, dataflow_type = __readline(open_file).replace("\n", "").split(" ")
#     if dataflow_type == "SDF" or dataflow_type == "SDFG":
#         dataflow = SDF(name)
#     elif dataflow_type == "CSDF" or dataflow_type == "CSDFG":
#         dataflow = CSDF(name)
#     elif dataflow_type == "PCG":
#         dataflow = PCG(name)
# 
#     task_nb, arc_nb = __readline(open_file).split(" ")
#     for i in xrange(int(task_nb)):
#         line = __readline(open_file).replace("\n", "")
#         task_name, repetition_factor, str_duration = line.split(" ")
#         task = dataflow.add_task(task_name)
#         dataflow.set_repetition_factor(task, int(repetition_factor))
#         if ";" in str_duration:
#             str_ini_duration, str_duration = str_duration.split(";")
#             ini_duration_list = [float(i) for i in str_ini_duration.split(",")]
#             dataflow.set_ini_phase_count(task, len(ini_duration_list))
#             dataflow.set_ini_phase_duration_list(task, ini_duration_list)
# 
#         duration_list = [float(i) for i in str_duration.split(",")]
#         if isinstance(dataflow, SDF):
#             dataflow.set_task_duration(task, duration_list[0])
#         if isinstance(dataflow, CSDF):
#             dataflow.set_phase_count(task, len(duration_list))
#             dataflow.set_phase_duration_list(task, duration_list)
# 
#     for i in xrange(int(arc_nb)):
#         line = __readline(open_file).replace("\n", "")
#         str_arc, str_m0, str_prod, str_cons = line.split(" ")
#         source = dataflow.get_task_by_name(str_arc.split(",")[0][1:])
#         target = dataflow.get_task_by_name(str_arc.split(",")[1][:-1])
#         m0 = int(str_m0)
#         arc = dataflow.add_arc(source, target)
#         dataflow.set_initial_marking(arc, m0)
# 
#         if "PCG" in dataflow_type:
#             if dataflow.get_ini_phase_count(source) == 0:
#                 dataflow.set_ini_prod_rate_list(arc, [])
#             if dataflow.get_ini_phase_count(target) == 0:
#                 dataflow.set_ini_cons_rate_list(arc, [])
#                 dataflow.set_ini_threshold_list(arc, [])
# 
#         if ";" in str_prod:
#             str_prod_ini, str_prod = str_prod.split(";")
#             prod_ini = [int(i) for i in str_prod_ini.split(",")]
#             dataflow.set_ini_prod_rate_list(arc, prod_ini)
# 
#         prod = [int(i) for i in str_prod.split(",")]
#         if isinstance(dataflow, SDF):
#             dataflow.set_prod_rate(arc, prod[0])
#         if isinstance(dataflow, CSDF):
#             dataflow.set_prod_rate_list(arc, prod)
# 
#         if ";" in str_cons:
#             str_cons_ini, str_cons = str_cons.split(";")
#             str_cons_ini = str_cons_ini.split(",")
#             cons_ini = []
#             ini_threshold = []
#             for value in str_cons_ini:
#                 if ":" in value:
#                     value, threshold = value.split(":")
#                     ini_threshold.append(int(threshold))
#                 else:
#                     ini_threshold.append(int(value))
#                 cons_ini.append(int(value))
# 
#             dataflow.set_ini_cons_rate_list(arc, cons_ini)
#             if isinstance(dataflow, PCG):
#                 dataflow.set_ini_threshold_list(arc, ini_threshold)
# 
#         str_cons = str_cons.split(",")
#         cons = []
#         threshold = []
#         for value in str_cons:
#             if ":" in value:
#                 value, threshold_str = value.split(":")
#                 threshold.append(int(threshold_str))
#             else:
#                 threshold.append(int(value))
#             cons.append(int(value))
# 
#         if isinstance(dataflow, SDF):
#             dataflow.set_cons_rate(arc, cons[0])
#         if isinstance(dataflow, CSDF):
#             dataflow.set_cons_rate_list(arc, cons)
#         if isinstance(dataflow, PCG):
#             dataflow.set_threshold_list(arc, threshold)
# 
#     return dataflow


import pydot
from Turbine.file_parser.turbine_parser import read_tur_file
                self._dotGraph.add_node(dot_buf)

                if self.dataflow.is_sdf:
                    self._dotGraph.add_edge(pydot.Edge(dot_prod, dot_buf, headlabel=self.dataflow.get_prod_rate(arc)))
                    self._dotGraph.add_edge(pydot.Edge(dot_buf, dot_cons, headlabel=self.dataflow.get_cons_rate(arc)))
                if self.dataflow.is_csdf:
                    self._dotGraph.add_edge(
                        pydot.Edge(dot_prod, dot_buf, headlabel=str(self.dataflow.get_prod_rate_list(arc))))
                    self._dotGraph.add_edge(
                        pydot.Edge(dot_buf, dot_cons, headlabel=str(self.dataflow.get_cons_rate_list(arc))))

    def write_dot(self, name=None):
        if name is None:
            name = self.dataflow.name
        self._dotGraph.write_dot(name + '.dot')

    def write_pdf(self, name=None):
        if name is None:
            name = self.dataflow.name
        self._dotGraph.write_pdf(name + '.pdf')

    def write_jpeg(self, name=None):
        if name is None:
            name = self.dataflow.name
        self._dotGraph.write_jpeg(name + '.jpeg')


if __name__ == "__main__":
    file_path_bs = "simpl_BlackScholes.tur"
    # file_path_jpeg = "../../experimentations/indus/JPEG2000.tur"

# Path: Turbine/file_parser/turbine_parser.py
# def read_tur_file(filename):
#     open_file = open(filename, "r")
#     name, dataflow_type = __readline(open_file).replace("\n", "").split(" ")
#     if dataflow_type == "SDF" or dataflow_type == "SDFG":
#         dataflow = SDF(name)
#     elif dataflow_type == "CSDF" or dataflow_type == "CSDFG":
#         dataflow = CSDF(name)
#     elif dataflow_type == "PCG":
#         dataflow = PCG(name)
# 
#     task_nb, arc_nb = __readline(open_file).split(" ")
#     for i in xrange(int(task_nb)):
#         line = __readline(open_file).replace("\n", "")
#         task_name, repetition_factor, str_duration = line.split(" ")
#         task = dataflow.add_task(task_name)
#         dataflow.set_repetition_factor(task, int(repetition_factor))
#         if ";" in str_duration:
#             str_ini_duration, str_duration = str_duration.split(";")
#             ini_duration_list = [float(i) for i in str_ini_duration.split(",")]
#             dataflow.set_ini_phase_count(task, len(ini_duration_list))
#             dataflow.set_ini_phase_duration_list(task, ini_duration_list)
# 
#         duration_list = [float(i) for i in str_duration.split(",")]
#         if isinstance(dataflow, SDF):
#             dataflow.set_task_duration(task, duration_list[0])
#         if isinstance(dataflow, CSDF):
#             dataflow.set_phase_count(task, len(duration_list))
#             dataflow.set_phase_duration_list(task, duration_list)
# 
#     for i in xrange(int(arc_nb)):
#         line = __readline(open_file).replace("\n", "")
#         str_arc, str_m0, str_prod, str_cons = line.split(" ")
#         source = dataflow.get_task_by_name(str_arc.split(",")[0][1:])
#         target = dataflow.get_task_by_name(str_arc.split(",")[1][:-1])
#         m0 = int(str_m0)
#         arc = dataflow.add_arc(source, target)
#         dataflow.set_initial_marking(arc, m0)
# 
#         if "PCG" in dataflow_type:
#             if dataflow.get_ini_phase_count(source) == 0:
#                 dataflow.set_ini_prod_rate_list(arc, [])
#             if dataflow.get_ini_phase_count(target) == 0:
#                 dataflow.set_ini_cons_rate_list(arc, [])
#                 dataflow.set_ini_threshold_list(arc, [])
# 
#         if ";" in str_prod:
#             str_prod_ini, str_prod = str_prod.split(";")
#             prod_ini = [int(i) for i in str_prod_ini.split(",")]
#             dataflow.set_ini_prod_rate_list(arc, prod_ini)
# 
#         prod = [int(i) for i in str_prod.split(",")]
#         if isinstance(dataflow, SDF):
#             dataflow.set_prod_rate(arc, prod[0])
#         if isinstance(dataflow, CSDF):
#             dataflow.set_prod_rate_list(arc, prod)
# 
#         if ";" in str_cons:
#             str_cons_ini, str_cons = str_cons.split(";")
#             str_cons_ini = str_cons_ini.split(",")
#             cons_ini = []
#             ini_threshold = []
#             for value in str_cons_ini:
#                 if ":" in value:
#                     value, threshold = value.split(":")
#                     ini_threshold.append(int(threshold))
#                 else:
#                     ini_threshold.append(int(value))
#                 cons_ini.append(int(value))
# 
#             dataflow.set_ini_cons_rate_list(arc, cons_ini)
#             if isinstance(dataflow, PCG):
#                 dataflow.set_ini_threshold_list(arc, ini_threshold)
# 
#         str_cons = str_cons.split(",")
#         cons = []
#         threshold = []
#         for value in str_cons:
#             if ":" in value:
#                 value, threshold_str = value.split(":")
#                 threshold.append(int(threshold_str))
#             else:
#                 threshold.append(int(value))
#             cons.append(int(value))
# 
#         if isinstance(dataflow, SDF):
#             dataflow.set_cons_rate(arc, cons[0])
#         if isinstance(dataflow, CSDF):
#             dataflow.set_cons_rate_list(arc, cons)
#         if isinstance(dataflow, PCG):
#             dataflow.set_threshold_list(arc, threshold)
# 
#     return dataflow


# Path: Turbine/draw/draw_dot.py
import pydot
from Turbine.file_parser.turbine_parser import read_tur_file

                self._dotGraph.add_node(dot_buf)

                if self.dataflow.is_sdf:
                    self._dotGraph.add_edge(pydot.Edge(dot_prod, dot_buf, headlabel=self.dataflow.get_prod_rate(arc)))
                    self._dotGraph.add_edge(pydot.Edge(dot_buf, dot_cons, headlabel=self.dataflow.get_cons_rate(arc)))
                if self.dataflow.is_csdf:
                    self._dotGraph.add_edge(
                        pydot.Edge(dot_prod, dot_buf, headlabel=str(self.dataflow.get_prod_rate_list(arc))))
                    self._dotGraph.add_edge(
                        pydot.Edge(dot_buf, dot_cons, headlabel=str(self.dataflow.get_cons_rate_list(arc))))

    def write_dot(self, name=None):
        if name is None:
            name = self.dataflow.name
        self._dotGraph.write_dot(name + '.dot')

    def write_pdf(self, name=None):
        if name is None:
            name = self.dataflow.name
        self._dotGraph.write_pdf(name + '.pdf')

    def write_jpeg(self, name=None):
        if name is None:
            name = self.dataflow.name
        self._dotGraph.write_jpeg(name + '.jpeg')


if __name__ == "__main__":
    file_path_bs = "simpl_BlackScholes.tur"
    # file_path_jpeg = "../../experimentations/indus/JPEG2000.tur"

    dataflow = read_tur_file(file_path_bs)