author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 05 Jul 2017 12:59:43 +0300 | |
changeset 1714 | 64ea7c86a74c |
parent 1680 | 6db967480b7d |
child 1730 | 64d8f52bc8c8 |
permissions | -rwxr-xr-x |
203 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
3 |
|
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
203 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
203 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
203 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
203 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
20 |
# GNU General Public License for more details. |
203 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1457
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
203 | 25 |
|
26 |
# Package initialisation |
|
27 |
#import targets |
|
28 |
||
29 |
""" |
|
30 |
Beremiz Targets |
|
31 |
||
32 |
- Target are python packages, containing at least one "XSD" file |
|
33 |
- Target class may inherit from a toolchain_(toolchainname) |
|
34 |
- The target folder's name must match to name define in the XSD for TargetType |
|
35 |
""" |
|
36 |
||
37 |
from os import listdir, path |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
38 |
import util.paths as paths |
203 | 39 |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
40 |
_base_path = paths.AbsDir(__file__) |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
41 |
def _GetLocalTargetClassFactory(name): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
42 |
return lambda:getattr(__import__(name,globals(),locals()), name+"_target") |
203 | 43 |
|
742
41a4a560406c
Fixed runtime problems with python 2.6 without wx installed
Edouard Tisserant
parents:
734
diff
changeset
|
44 |
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
|
45 |
"class":_GetLocalTargetClassFactory(name), |
1456
e723c1dd6faa
Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents:
1430
diff
changeset
|
46 |
"code": { fname: path.join(_base_path, name, fname) |
1457
ff7cfce737ca
Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents:
1456
diff
changeset
|
47 |
for fname in listdir(path.join(_base_path, name)) |
ff7cfce737ca
Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents:
1456
diff
changeset
|
48 |
if fname.startswith("plc_%s_main"%name) and |
ff7cfce737ca
Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents:
1456
diff
changeset
|
49 |
fname.endswith(".c")}}) |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
50 |
for name in listdir(_base_path) |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
51 |
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
|
52 |
and not name.startswith("__")]) |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
53 |
|
1387
435965ca8b63
Re-introduced toolchain_makefile.py. This time, it comes with a 'Generic' target, and a 'genericmake' example
Edouard Tisserant
parents:
1001
diff
changeset
|
54 |
toolchains = {"gcc": path.join(_base_path, "XSD_toolchain_gcc"), |
435965ca8b63
Re-introduced toolchain_makefile.py. This time, it comes with a 'Generic' target, and a 'genericmake' example
Edouard Tisserant
parents:
1001
diff
changeset
|
55 |
"makefile": path.join(_base_path, "XSD_toolchain_makefile")} |
203 | 56 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
57 |
def GetBuilder(targetname): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
58 |
return targets[targetname]["class"]() |
203 | 59 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
60 |
def GetTargetChoices(): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
61 |
DictXSD_toolchain = {} |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
62 |
targetchoices = "" |
203 | 63 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
64 |
# Get all xsd toolchains |
734 | 65 |
for toolchainname,xsdfilename in toolchains.iteritems() : |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
66 |
if path.isfile(xsdfilename): |
1387
435965ca8b63
Re-introduced toolchain_makefile.py. This time, it comes with a 'Generic' target, and a 'genericmake' example
Edouard Tisserant
parents:
1001
diff
changeset
|
67 |
DictXSD_toolchain["toolchain_"+toolchainname] = \ |
435965ca8b63
Re-introduced toolchain_makefile.py. This time, it comes with a 'Generic' target, and a 'genericmake' example
Edouard Tisserant
parents:
1001
diff
changeset
|
68 |
open(xsdfilename).read() |
203 | 69 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
70 |
# Get all xsd targets |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
71 |
for targetname,nfo in targets.iteritems(): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
72 |
xsd_string = open(nfo["xsd"]).read() |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
73 |
targetchoices += xsd_string%DictXSD_toolchain |
203 | 74 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
75 |
return targetchoices |
203 | 76 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
77 |
def GetTargetCode(targetname): |
1456
e723c1dd6faa
Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents:
1430
diff
changeset
|
78 |
codedesc = targets[targetname]["code"] |
e723c1dd6faa
Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents:
1430
diff
changeset
|
79 |
code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())]) |
e723c1dd6faa
Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents:
1430
diff
changeset
|
80 |
return code |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
81 |
|
1001
3f966bbb3fba
Added beremiz.h header file for extensions
Edouard Tisserant
parents:
762
diff
changeset
|
82 |
def GetHeader(): |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
83 |
filename = paths.AbsNeighbourFile(__file__,"beremiz.h") |
1001
3f966bbb3fba
Added beremiz.h header file for extensions
Edouard Tisserant
parents:
762
diff
changeset
|
84 |
return open(filename).read() |
3f966bbb3fba
Added beremiz.h header file for extensions
Edouard Tisserant
parents:
762
diff
changeset
|
85 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
642
diff
changeset
|
86 |
def GetCode(name): |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
87 |
filename = paths.AbsNeighbourFile(__file__,name) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
205
diff
changeset
|
88 |
return open(filename).read() |
205
ee8d1f4528ef
move specific target runtimes to their targets directory
greg
parents:
203
diff
changeset
|
89 |