author | Edouard Tisserant |
Mon, 21 Nov 2011 11:40:29 +0100 | |
changeset 644 | b511cab580eb |
parent 642 | cd7ccbbbf471 |
child 733 | 915be999f3f0 |
permissions | -rwxr-xr-x |
203 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
# |
|
4 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
5 |
# |
|
6 |
#See COPYING file for copyrights details. |
|
7 |
# |
|
8 |
#This library is free software; you can redistribute it and/or |
|
9 |
#modify it under the terms of the GNU General Public |
|
10 |
#License as published by the Free Software Foundation; either |
|
11 |
#version 2.1 of the License, or (at your option) any later version. |
|
12 |
# |
|
13 |
#This library is distributed in the hope that it will be useful, |
|
14 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
#General Public License for more details. |
|
17 |
# |
|
18 |
#You should have received a copy of the GNU General Public |
|
19 |
#License along with this library; if not, write to the Free Software |
|
20 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
||
22 |
# Package initialisation |
|
23 |
#import targets |
|
24 |
||
25 |
""" |
|
26 |
Beremiz Targets |
|
27 |
||
28 |
- Target are python packages, containing at least one "XSD" file |
|
29 |
- Target class may inherit from a toolchain_(toolchainname) |
|
30 |
- The target folder's name must match to name define in the XSD for TargetType |
|
31 |
""" |
|
32 |
||
33 |
from os import listdir, path |
|
34 |
||
35 |
_base_path = path.split(__file__)[0] |
|
36 |
||
642 | 37 |
targets = [name for name in listdir(_base_path) |
38 |
if path.isdir(path.join(_base_path, name)) |
|
39 |
and not name.startswith("__")] |
|
40 |
toolchains = [name for name in listdir(_base_path) |
|
41 |
if not path.isdir(path.join(_base_path, name)) |
|
42 |
and name.endswith(".py") |
|
43 |
and not name.startswith("__") |
|
44 |
and not name.endswith(".pyc")] |
|
203 | 45 |
|
46 |
DictXSD_toolchain = {} |
|
47 |
DictXSD_target = {} |
|
48 |
||
49 |
targetchoices = "" |
|
50 |
||
51 |
# Get all xsd toolchains |
|
52 |
for toolchain in toolchains : |
|
53 |
toolchainname = path.splitext(toolchain)[0] |
|
54 |
xsdfilename = path.join(_base_path, "XSD_%s"%(toolchainname)) |
|
55 |
if path.isfile(xsdfilename): |
|
56 |
xsd_toolchain_string = "" |
|
57 |
for line in open(xsdfilename).readlines(): |
|
58 |
xsd_toolchain_string += line |
|
59 |
DictXSD_toolchain[toolchainname] = xsd_toolchain_string |
|
60 |
||
61 |
# Get all xsd targets |
|
62 |
for targetname in targets: |
|
63 |
xsdfilename = path.join(_base_path, targetname, "XSD") |
|
64 |
if path.isfile(xsdfilename): |
|
65 |
xsd_target_string = "" |
|
66 |
for line in open(xsdfilename).readlines(): |
|
67 |
xsd_target_string += line |
|
68 |
DictXSD_target[targetname] = xsd_target_string%DictXSD_toolchain |
|
69 |
||
70 |
for target in DictXSD_target.keys(): |
|
71 |
targetchoices += DictXSD_target[target] |
|
72 |
||
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
73 |
def targetcode(target_name, code_name=None): |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
74 |
if code_name is None: |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
75 |
code_name="plc_%s_main.c"%target_name |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
76 |
filename = path.join(path.split(__file__)[0], target_name, code_name) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
77 |
return open(filename).read() |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
78 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
79 |
def code(name): |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
80 |
filename = path.join(path.split(__file__)[0],name + ".c") |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
81 |
return open(filename).read() |
205
ee8d1f4528ef
move specific target runtimes to their targets directory
greg
parents:
203
diff
changeset
|
82 |