targets/__init__.py
author Edouard Tisserant
Mon, 21 Nov 2011 11:40:29 +0100
changeset 644 b511cab580eb
parent 642 cd7ccbbbf471
child 733 915be999f3f0
permissions -rwxr-xr-x
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
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]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    36
642
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    37
targets = [name for name in listdir(_base_path) 
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    38
                   if path.isdir(path.join(_base_path, name)) 
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    39
                       and not name.startswith("__")]
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    40
toolchains = [name for name in listdir(_base_path) 
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    41
                       if not path.isdir(path.join(_base_path, name)) 
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    42
                            and name.endswith(".py") 
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    43
                            and not name.startswith("__") 
cd7ccbbbf471 various cleanups in /targets
Edouard Tisserant
parents: 425
diff changeset
    44
                            and not name.endswith(".pyc")]
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    45
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    46
DictXSD_toolchain = {}
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    47
DictXSD_target = {}
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    48
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    49
targetchoices = ""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    50
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    51
# Get all xsd toolchains
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    52
for toolchain in toolchains :
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    53
     toolchainname = path.splitext(toolchain)[0]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    54
     xsdfilename = path.join(_base_path, "XSD_%s"%(toolchainname))
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    55
     if path.isfile(xsdfilename):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    56
         xsd_toolchain_string = ""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    57
         for line in open(xsdfilename).readlines():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    58
             xsd_toolchain_string += line
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    59
         DictXSD_toolchain[toolchainname] = xsd_toolchain_string
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    60
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    61
# Get all xsd targets 
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    62
for targetname in targets:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    63
    xsdfilename = path.join(_base_path, targetname, "XSD")
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    64
    if path.isfile(xsdfilename):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    65
        xsd_target_string = ""
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    66
        for line in open(xsdfilename).readlines():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    67
            xsd_target_string += line
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    68
        DictXSD_target[targetname] = xsd_target_string%DictXSD_toolchain
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    69
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    70
for target in DictXSD_target.keys():
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    71
    targetchoices += DictXSD_target[target]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    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