author  Andrey Skvortsov <andrej.skvortzov@gmail.com> 
Mon, 21 Aug 2017 21:55:18 +0300  
changeset 1782  5b6ad7a7fd9d 
parent 1767  c74815729afd 
child 1785  0ff2a45dcefa 
permissions  rwxrxrx 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

1 
#!/usr/bin/env python 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

2 
# * coding: utf8 * 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

3 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

4 
# This file is part of Beremiz, a Integrated Development Environment for 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

5 
# programming IEC 611313 automates supporting plcopen standard and CanFestival. 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

6 
# 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

7 
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

8 
# Copyright (C) 2017: Andrey Skvortsov 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

9 
# 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

10 
# See COPYING file for copyrights details. 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

11 
# 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

12 
# This program is free software; you can redistribute it and/or 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

13 
# modify it under the terms of the GNU General Public License 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

14 
# as published by the Free Software Foundation; either version 2 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

15 
# of the License, or (at your option) any later version. 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

16 
# 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

17 
# This program is distributed in the hope that it will be useful, 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

18 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

19 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

20 
# GNU General Public License for more details. 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

21 
# 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

22 
# You should have received a copy of the GNU General Public License 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

23 
# along with this program; if not, write to the Free Software 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

24 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 021101301, USA. 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

25 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

26 
# Package initialisation 
1782
5b6ad7a7fd9d
cleanup: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset

27 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

28 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

29 
""" 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

30 
Beremiz Targets 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

31 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

32 
 Target are python packages, containing at least one "XSD" file 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

33 
 Target class may inherit from a toolchain_(toolchainname) 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

34 
 The target folder's name must match to name define in the XSD for TargetType 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

35 
""" 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

36 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

37 
from os import listdir, path 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

38 
import util.paths as paths 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

39 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

40 
_base_path = paths.AbsDir(__file__) 
1736
7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

41 

7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

42 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

43 
def _GetLocalTargetClassFactory(name): 
1740
b789b695b5c6
cleanup: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset

44 
return lambda: getattr(__import__(name, globals(), locals()), name+"_target") 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

45 

1749
d73b64672238
cleanup: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset

46 

1767
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

47 
targets = dict([(name, {"xsd": path.join(_base_path, name, "XSD"), 
1740
b789b695b5c6
cleanup: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset

48 
"class": _GetLocalTargetClassFactory(name), 
1767
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

49 
"code": {fname: path.join(_base_path, name, fname) 
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

50 
for fname in listdir(path.join(_base_path, name)) 
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

51 
if (fname.startswith("plc_%s_main" % name) and 
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

52 
fname.endswith(".c"))}}) 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

53 
for name in listdir(_base_path) 
1767
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

54 
if (path.isdir(path.join(_base_path, name)) 
c74815729afd
cleanup: fix PEP8 E127 continuation line overindented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset

55 
and not name.startswith("__"))]) 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

56 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

57 
toolchains = {"gcc": path.join(_base_path, "XSD_toolchain_gcc"), 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

58 
"makefile": path.join(_base_path, "XSD_toolchain_makefile")} 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

59 

1736
7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

60 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

61 
def GetBuilder(targetname): 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

62 
return targets[targetname]["class"]() 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

63 

1736
7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

64 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

65 
def GetTargetChoices(): 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

66 
DictXSD_toolchain = {} 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

67 
targetchoices = "" 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

68 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

69 
# Get all xsd toolchains 
1740
b789b695b5c6
cleanup: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset

70 
for toolchainname, xsdfilename in toolchains.iteritems(): 
1757
0de89da92ee0
cleanup: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset

71 
if path.isfile(xsdfilename): 
0de89da92ee0
cleanup: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset

72 
DictXSD_toolchain["toolchain_"+toolchainname] = open(xsdfilename).read() 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

73 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

74 
# Get all xsd targets 
1740
b789b695b5c6
cleanup: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset

75 
for targetname, nfo in targets.iteritems(): 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

76 
xsd_string = open(nfo["xsd"]).read() 
1758
845ca626db09
cleanup: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1757
diff
changeset

77 
targetchoices += xsd_string % DictXSD_toolchain 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

78 

6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

79 
return targetchoices 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

80 

1736
7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

81 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

82 
def GetTargetCode(targetname): 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

83 
codedesc = targets[targetname]["code"] 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

84 
code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())]) 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

85 
return code 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

86 

1736
7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

87 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

88 
def GetHeader(): 
1740
b789b695b5c6
cleanup: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset

89 
filename = paths.AbsNeighbourFile(__file__, "beremiz.h") 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

90 
return open(filename).read() 
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

91 

1736
7e61baa047f0
cleanup: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset

92 

1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

93 
def GetCode(name): 
1740
b789b695b5c6
cleanup: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset

94 
filename = paths.AbsNeighbourFile(__file__, name) 
1731
6ebd9c40b2be
convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset

95 
return open(filename).read() 