targets/__init__.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 05 Oct 2016 18:11:52 +0300
changeset 1539 8e5c03798abc
parent 1457 ff7cfce737ca
child 1571 486f94a8032c
permissions -rwxr-xr-x
fix syncronization issue during killing ProcessLoggers on IDE close
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     3
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     4
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     5
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     6
#See COPYING file for copyrights details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     7
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     8
#This library is free software; you can redistribute it and/or
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     9
#modify it under the terms of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    10
#License as published by the Free Software Foundation; either
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    11
#version 2.1 of the License, or (at your option) any later version.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    12
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    13
#This library is distributed in the hope that it will be useful,
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    14
#but WITHOUT ANY WARRANTY; without even the implied warranty of
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    15
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    16
#General Public License for more details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    17
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    18
#You should have received a copy of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    19
#License along with this library; if not, write to the Free Software
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    20
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    21
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    22
# Package initialisation
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    23
#import targets
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    24
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    25
"""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    26
Beremiz Targets
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    27
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
- Target are python packages, containing at least one "XSD" file
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    29
- Target class may inherit from a toolchain_(toolchainname)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    30
- The target folder's name must match to name define in the XSD for TargetType
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    31
"""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    32
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    33
from os import listdir, path
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    34
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    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
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    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),
1456
e723c1dd6faa Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents: 1430
diff changeset
    41
                        "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
    42
                           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
    43
                             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
    44
                               fname.endswith(".c")}})
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    45
                for name in listdir(_base_path) 
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    46
                    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
    47
                       and not name.startswith("__")])
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    48
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
    49
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
    50
              "makefile":  path.join(_base_path, "XSD_toolchain_makefile")}
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    51
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    52
def GetBuilder(targetname):
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    53
    return targets[targetname]["class"]()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    54
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    55
def GetTargetChoices():
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    56
    DictXSD_toolchain = {}
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    57
    targetchoices = ""
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    58
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    59
    # Get all xsd toolchains
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 733
diff changeset
    60
    for toolchainname,xsdfilename in toolchains.iteritems() :
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    61
         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
    62
             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
    63
                open(xsdfilename).read()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    64
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    65
    # Get all xsd targets 
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    66
    for targetname,nfo in targets.iteritems():
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    67
        xsd_string = open(nfo["xsd"]).read()
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    68
        targetchoices +=  xsd_string%DictXSD_toolchain
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    69
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    70
    return targetchoices
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    71
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    72
def GetTargetCode(targetname):
1456
e723c1dd6faa Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents: 1430
diff changeset
    73
    codedesc = targets[targetname]["code"]
e723c1dd6faa Splitted plc_Xenomai_main.c to enable further customization
Edouard Tisserant
parents: 1430
diff changeset
    74
    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
    75
    return code
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    76
1001
3f966bbb3fba Added beremiz.h header file for extensions
Edouard Tisserant
parents: 762
diff changeset
    77
def GetHeader():
3f966bbb3fba Added beremiz.h header file for extensions
Edouard Tisserant
parents: 762
diff changeset
    78
    filename = path.join(path.split(__file__)[0],"beremiz.h")
3f966bbb3fba Added beremiz.h header file for extensions
Edouard Tisserant
parents: 762
diff changeset
    79
    return open(filename).read()
3f966bbb3fba Added beremiz.h header file for extensions
Edouard Tisserant
parents: 762
diff changeset
    80
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 642
diff changeset
    81
def GetCode(name):
1430
754fa90c8b27 minor cleanup
Edouard Tisserant
parents: 1387
diff changeset
    82
    filename = path.join(path.split(__file__)[0],name)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents: 205
diff changeset
    83
    return open(filename).read()
205
ee8d1f4528ef move specific target runtimes to their targets directory
greg
parents: 203
diff changeset
    84