36 def CTNGenerate_C(self, buildpath, locations): |
36 def CTNGenerate_C(self, buildpath, locations): |
37 current_location = self.GetCurrentLocation() |
37 current_location = self.GetCurrentLocation() |
38 # define a unique name for the generated C file |
38 # define a unique name for the generated C file |
39 location_str = "_".join(map(lambda x:str(x), current_location)) |
39 location_str = "_".join(map(lambda x:str(x), current_location)) |
40 |
40 |
|
41 sections_code = self.GetSectionsCode() |
|
42 |
|
43 text = "## Code generated by Beremiz python mixin confnode\n\n" |
|
44 |
|
45 # Adding variables |
|
46 text += "## User variables reference\n" |
|
47 text += sections_code["variables"] |
|
48 text += "\n" |
|
49 |
|
50 # Adding user global variables and routines |
|
51 text += "## User internal user variables and routines\n" |
|
52 text += sections_code["globals"] |
|
53 text += "\n" |
|
54 |
|
55 # Adding Beremiz python runtime functions |
|
56 text += "## Beremiz python runtime functions\n" |
|
57 for section in self.SECTIONS_NAMES: |
|
58 if section != "globals": |
|
59 code_object = getattr(self.CodeFile, section) |
|
60 text += "def _runtime_%s_%s():\n" % (location_str, section) |
|
61 section_code = sections_code.get(section) |
|
62 if section_code: |
|
63 text += section_code |
|
64 else: |
|
65 text += " pass\n\n" |
|
66 |
41 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
67 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
42 runtimefile = open(runtimefile_path, 'w') |
68 runtimefile = open(runtimefile_path, 'w') |
43 runtimefile.write(self.GetPythonCode()) |
69 runtimefile.write(text) |
44 runtimefile.close() |
70 runtimefile.close() |
45 |
71 |
46 return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |
72 return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |
47 |
73 |