py_ext/PythonFileCTNMixin.py
author Edouard Tisserant
Tue, 14 May 2013 18:41:33 +0900
changeset 1132 28f96aa9c070
parent 1124 b1705000eba1
child 1144 21475ee0e688
permissions -rw-r--r--
Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     1
import os
654
9f6c091c316c Removing multiple definition of UndoBuffer
laurent
parents: 430
diff changeset
     2
from PLCControler import UndoBuffer
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
     3
from PythonEditor import PythonEditor
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     4
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     5
from xml.dom import minidom
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
     6
from xmlclass import GenerateClassesFromXSD
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     7
import cPickle
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
     8
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
     9
from CodeFileTreeNode import CodeFile
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    10
721
ecf4d203c4d4 refactoring
Edouard Tisserant
parents: 718
diff changeset
    11
PythonClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "py_ext_xsd.xsd")) 
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    12
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    13
class PythonFileCTNMixin(CodeFile):
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    14
    
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    15
    CODEFILE_NAME = "PyFile"
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    16
    SECTIONS_NAMES = [
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    17
        "globals",
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    18
        "init",
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    19
        "cleanup",
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    20
        "start",
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    21
        "stop"]
657
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
    22
    EditorType = PythonEditor
340c0b9caeca Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents: 654
diff changeset
    23
    
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    24
    def __init__(self):
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    25
        CodeFile.__init__(self)
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    26
        
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    27
        filepath = self.PythonFileName()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    28
        
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    29
        python_code = PythonClasses["Python"]()
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    30
        if os.path.isfile(filepath):
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    31
            xmlfile = open(filepath, 'r')
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    32
            tree = minidom.parse(xmlfile)
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    33
            xmlfile.close()
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    34
            
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    35
            for child in tree.childNodes:
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    36
                if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "Python":
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    37
                    python_code.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"])
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    38
                    self.CodeFile.globals.settext(python_code.gettext())
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    39
                    os.remove(filepath)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    40
                    self.CreateCodeFileBuffer(False)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    41
                    self.OnCTNSave()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    42
    
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    43
    def CodeFileName(self):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    44
        return os.path.join(self.CTNPath(), "pyfile.xml")
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    45
    
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    46
    def PythonFileName(self):
721
ecf4d203c4d4 refactoring
Edouard Tisserant
parents: 718
diff changeset
    47
        return os.path.join(self.CTNPath(), "py_ext.xml")
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    48
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    49
    PreSectionsTexts = {}
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    50
    PostSectionsTexts = {}
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    51
    def GetSection(self,section):
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    52
        return self.PreSectionsTexts.get(section,"") + "\n" + \
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    53
               getattr(self.CodeFile, section).gettext() + "\n" + \
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    54
               self.PostSectionsTexts.get(section,"")
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    55
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    56
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    57
    def CTNGenerate_C(self, buildpath, locations):
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    58
        current_location = self.GetCurrentLocation()
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    59
        # define a unique name for the generated C file
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    60
        location_str = "_".join(map(lambda x:str(x), current_location))
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    61
        
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    62
        
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    63
        # Generate Beremiz python runtime variables code
1103
2fc1eef45bda Fixed python global variable declaration example in generated runtime python file
Laurent Bessard
parents: 1097
diff changeset
    64
        config = self.GetCTRoot().GetProjectConfigNames()[0]
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    65
        variables_str = ""
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1061
diff changeset
    66
        for variable in self.CodeFile.variables.variable:
1103
2fc1eef45bda Fixed python global variable declaration example in generated runtime python file
Laurent Bessard
parents: 1097
diff changeset
    67
            global_name = "%s_%s" % (config.upper(), variable.getname().upper())
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    68
            variables_str += "# global_var:%s python_var:%s type:%s initial:%s\n" % (
1103
2fc1eef45bda Fixed python global variable declaration example in generated runtime python file
Laurent Bessard
parents: 1097
diff changeset
    69
                global_name,
2fc1eef45bda Fixed python global variable declaration example in generated runtime python file
Laurent Bessard
parents: 1097
diff changeset
    70
                variable.getname(),
2fc1eef45bda Fixed python global variable declaration example in generated runtime python file
Laurent Bessard
parents: 1097
diff changeset
    71
                variable.gettype(),
2fc1eef45bda Fixed python global variable declaration example in generated runtime python file
Laurent Bessard
parents: 1097
diff changeset
    72
                str(variable.getinitial()))
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    73
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    74
        # Runtime calls (start, stop, init, and cleanup)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    75
        rtcalls = ""
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    76
        for section in self.SECTIONS_NAMES:
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1120
diff changeset
    77
            if section != "globals":
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    78
                rtcalls += "def _runtime_%s_%s():\n" % (location_str, section)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    79
                sectiontext = self.GetSection(section).strip()
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    80
                if sectiontext:
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    81
                    rtcalls += '    ' + \
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    82
                        sectiontext.strip().replace('\n', '\n    ')+"\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    83
                else:
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    84
                    rtcalls += "    pass\n\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    85
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    86
        text = """\
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    87
#!/usr/bin/env python
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    88
# -*- coding: utf-8 -*-
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    89
## Code generated by Beremiz python mixin confnode
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    90
##        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    91
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    92
## Code for PLC global variable access
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    93
%s
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    94
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    95
## User code in "global" scope
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    96
%s
366
cd90e4c10261 Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff changeset
    97
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    98
## Beremiz python runtime calls
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
    99
%s
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   100
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   101
"""%(   # variables
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   102
        variables_str,
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   103
        # globals
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   104
        self.GetSection("globals"),
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   105
        # Beremiz python runtime functions
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   106
        rtcalls)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   107
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   108
        runtimefile_path = os.path.join(buildpath, 
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   109
            "runtime_%s.py"%location_str)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   110
        runtimefile = open(runtimefile_path, 'w')
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   111
        runtimefile.write(text.encode('utf-8'))
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   112
        runtimefile.close()
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   113
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   114
        text = """\
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   115
/* 
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   116
 * Code generated by Beremiz py_ext confnode 
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   117
 * for safe global variables access
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   118
 */
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   119
#include "iec_types_all.h"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   120
"""
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   121
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   122
        # Adding variables
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   123
        text += "/* User variables reference */\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   124
        for variable in self.CodeFile.variables.variable:
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   125
            var_infos = {
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   126
                "name": variable.getname(),
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   127
                "global": "%s__%s" % (config.upper(),
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   128
                                      variable.getname().upper()),
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   129
                "type": "__IEC_%s_t" % variable.gettype()}
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   130
            text += "extern %(type)s %(global)s;\n" % var_infos
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   131
            text += "%(type)s __buffer_%(name)s;\n" % var_infos
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   132
        text += "\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   133
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   134
        # Adding Beremiz confnode functions
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   135
        text += "/* Beremiz confnode functions */\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   136
        text += "int __init_%s(int argc,char **argv)\n{\n"%location_str
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   137
        text += "/*TODO*/\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   138
        text += "  return 0;\n}\n\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   139
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   140
        text += "void __cleanup_%s(void)\n{\n"%location_str
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   141
        text += "/*TODO*/\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   142
        text += "\n}\n\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   143
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   144
        text += "void __retrieve_%s(void)\n{\n"%location_str
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   145
        text += "/*TODO*/\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   146
        text += "\n}\n\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   147
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   148
        text += "void __publish_%s(void)\n{\n"%location_str
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   149
        text += "/*TODO*/\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   150
        text += "\n}\n\n"
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   151
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   152
        Gen_PyCfile_path = os.path.join(buildpath, "PyCFile_%s.c"%location_str)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   153
        pycfile = open(Gen_PyCfile_path,'w')
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   154
        pycfile.write(text)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   155
        pycfile.close()
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   156
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   157
        matiec_flags = '"-I%s"'%os.path.abspath(
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   158
            self.GetCTRoot().GetIECLibPath())
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   159
        
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   160
        return ([(Gen_PyCfile_path, matiec_flags)],
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   161
                "",
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   162
                False,
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   163
                ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")))
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1124
diff changeset
   164