author | Edouard Tisserant |
Thu, 06 Sep 2012 00:32:45 +0200 | |
changeset 810 | 707e2be17a43 |
parent 762 | aaacc83aa86b |
child 1001 | 3f966bbb3fba |
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] |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
36 |
def _GetLocalTargetClassFactory(name): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
37 |
return lambda:getattr(__import__(name,globals(),locals()), name+"_target") |
203 | 38 |
|
742
41a4a560406c
Fixed runtime problems with python 2.6 without wx installed
Edouard Tisserant
parents:
734
diff
changeset
|
39 |
targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"), |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
742
diff
changeset
|
40 |
"class":_GetLocalTargetClassFactory(name), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
742
diff
changeset
|
41 |
"code": path.join(path.split(__file__)[0],name,"plc_%s_main.c"%name)}) |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
42 |
for name in listdir(_base_path) |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
43 |
if path.isdir(path.join(_base_path, name)) |
742
41a4a560406c
Fixed runtime problems with python 2.6 without wx installed
Edouard Tisserant
parents:
734
diff
changeset
|
44 |
and not name.startswith("__")]) |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
45 |
|
734 | 46 |
toolchains = {"gcc": path.join(_base_path, "XSD_toolchain_gcc")} |
203 | 47 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
48 |
def GetBuilder(targetname): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
49 |
return targets[targetname]["class"]() |
203 | 50 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
51 |
def GetTargetChoices(): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
52 |
DictXSD_toolchain = {} |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
53 |
targetchoices = "" |
203 | 54 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
55 |
# Get all xsd toolchains |
734 | 56 |
for toolchainname,xsdfilename in toolchains.iteritems() : |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
57 |
if path.isfile(xsdfilename): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
58 |
xsd_toolchain_string = "" |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
59 |
for line in open(xsdfilename).readlines(): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
60 |
xsd_toolchain_string += line |
734 | 61 |
DictXSD_toolchain["toolchain_"+toolchainname] = xsd_toolchain_string |
203 | 62 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
63 |
# Get all xsd targets |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
64 |
for targetname,nfo in targets.iteritems(): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
65 |
xsd_string = open(nfo["xsd"]).read() |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
66 |
targetchoices += xsd_string%DictXSD_toolchain |
203 | 67 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
68 |
return targetchoices |
203 | 69 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
70 |
def GetTargetCode(targetname): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
71 |
return open(targets[targetname]["code"]).read() |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
72 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
73 |
def GetCode(name): |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
74 |
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
|
75 |
return open(filename).read() |
205
ee8d1f4528ef
move specific target runtimes to their targets directory
greg
parents:
203
diff
changeset
|
76 |