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] Edouard@733: def _GetLocalTargetClassFactory(name): Edouard@733: return lambda:getattr(__import__(name,globals(),locals()), name+"_target") etisserant@203: Edouard@742: targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"), laurent@762: "class":_GetLocalTargetClassFactory(name), laurent@762: "code": path.join(path.split(__file__)[0],name,"plc_%s_main.c"%name)}) Edouard@733: for name in listdir(_base_path) Edouard@733: if path.isdir(path.join(_base_path, name)) Edouard@742: and not name.startswith("__")]) Edouard@733: Edouard@734: toolchains = {"gcc": path.join(_base_path, "XSD_toolchain_gcc")} etisserant@203: Edouard@733: def GetBuilder(targetname): Edouard@733: return targets[targetname]["class"]() etisserant@203: Edouard@733: def GetTargetChoices(): Edouard@733: DictXSD_toolchain = {} Edouard@733: targetchoices = "" etisserant@203: Edouard@733: # Get all xsd toolchains Edouard@734: for toolchainname,xsdfilename in toolchains.iteritems() : Edouard@733: if path.isfile(xsdfilename): Edouard@733: xsd_toolchain_string = "" Edouard@733: for line in open(xsdfilename).readlines(): Edouard@733: xsd_toolchain_string += line Edouard@734: DictXSD_toolchain["toolchain_"+toolchainname] = xsd_toolchain_string etisserant@203: Edouard@733: # Get all xsd targets Edouard@733: for targetname,nfo in targets.iteritems(): Edouard@733: xsd_string = open(nfo["xsd"]).read() Edouard@733: targetchoices += xsd_string%DictXSD_toolchain etisserant@203: Edouard@733: return targetchoices etisserant@203: Edouard@733: def GetTargetCode(targetname): Edouard@733: return open(targets[targetname]["code"]).read() etisserant@209: Edouard@733: def GetCode(name): etisserant@209: filename = path.join(path.split(__file__)[0],name + ".c") etisserant@209: return open(filename).read() greg@205: