etisserant@203: #!/usr/bin/env python etisserant@203: # -*- coding: utf-8 -*- etisserant@203: # etisserant@203: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@203: # etisserant@203: #See COPYING file for copyrights details. etisserant@203: # etisserant@203: #This library is free software; you can redistribute it and/or etisserant@203: #modify it under the terms of the GNU General Public etisserant@203: #License as published by the Free Software Foundation; either etisserant@203: #version 2.1 of the License, or (at your option) any later version. etisserant@203: # etisserant@203: #This library is distributed in the hope that it will be useful, etisserant@203: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@203: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@203: #General Public License for more details. etisserant@203: # etisserant@203: #You should have received a copy of the GNU General Public etisserant@203: #License along with this library; if not, write to the Free Software etisserant@203: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@203: etisserant@203: # Package initialisation etisserant@203: #import targets etisserant@203: etisserant@203: """ etisserant@203: Beremiz Targets etisserant@203: etisserant@203: - Target are python packages, containing at least one "XSD" file etisserant@203: - Target class may inherit from a toolchain_(toolchainname) etisserant@203: - The target folder's name must match to name define in the XSD for TargetType etisserant@203: """ etisserant@203: etisserant@203: from os import listdir, path etisserant@203: etisserant@203: _base_path = path.split(__file__)[0] etisserant@203: etisserant@203: targets = [name for name in listdir(_base_path) if path.isdir(path.join(_base_path, name)) and name.upper() != "CVS" and not name.startswith("__")] etisserant@203: toolchains = [name for name in listdir(_base_path) if not path.isdir(path.join(_base_path, name)) and name.upper() != "CVS" and name.endswith(".py") and not name.startswith("__") and not name.endswith(".pyc")] etisserant@203: etisserant@203: DictXSD_toolchain = {} etisserant@203: DictXSD_target = {} etisserant@203: etisserant@203: targetchoices = "" etisserant@203: etisserant@203: # Get all xsd toolchains etisserant@203: for toolchain in toolchains : etisserant@203: toolchainname = path.splitext(toolchain)[0] etisserant@203: xsdfilename = path.join(_base_path, "XSD_%s"%(toolchainname)) etisserant@203: if path.isfile(xsdfilename): etisserant@203: xsd_toolchain_string = "" etisserant@203: for line in open(xsdfilename).readlines(): etisserant@203: xsd_toolchain_string += line etisserant@203: DictXSD_toolchain[toolchainname] = xsd_toolchain_string etisserant@203: etisserant@203: # Get all xsd targets etisserant@203: for targetname in targets: etisserant@203: xsdfilename = path.join(_base_path, targetname, "XSD") etisserant@203: if path.isfile(xsdfilename): etisserant@203: xsd_target_string = "" etisserant@203: for line in open(xsdfilename).readlines(): etisserant@203: xsd_target_string += line etisserant@203: DictXSD_target[targetname] = xsd_target_string%DictXSD_toolchain etisserant@203: etisserant@203: for target in DictXSD_target.keys(): etisserant@203: targetchoices += DictXSD_target[target] etisserant@203: greg@205: def code(target_name): greg@205: filename = path.join(path.split(__file__)[0], target_name, "plc_%s_main.c"%target_name) greg@205: if path.exists(filename): greg@205: return open(filename).read() greg@205: else: greg@205: return "#error %s target not implemented !!!\n"%target_name greg@205: etisserant@203: from toolchain_gcc import toolchain_gcc