etisserant@203: #!/usr/bin/env python etisserant@203: # -*- coding: utf-8 -*- andrej@1571: andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. etisserant@203: # andrej@1571: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@203: # andrej@1571: # See COPYING file for copyrights details. etisserant@203: # andrej@1571: # This program is free software; you can redistribute it and/or andrej@1571: # modify it under the terms of the GNU General Public License andrej@1571: # as published by the Free Software Foundation; either version 2 andrej@1571: # of the License, or (at your option) any later version. etisserant@203: # andrej@1571: # This program is distributed in the hope that it will be useful, andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1571: # GNU General Public License for more details. etisserant@203: # andrej@1571: # You should have received a copy of the GNU General Public License andrej@1571: # along with this program; if not, write to the Free Software andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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), Edouard@1456: "code": { fname: path.join(_base_path, name, fname) Edouard@1457: for fname in listdir(path.join(_base_path, name)) Edouard@1457: if fname.startswith("plc_%s_main"%name) and Edouard@1457: fname.endswith(".c")}}) 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@1387: toolchains = {"gcc": path.join(_base_path, "XSD_toolchain_gcc"), Edouard@1387: "makefile": path.join(_base_path, "XSD_toolchain_makefile")} 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@1387: DictXSD_toolchain["toolchain_"+toolchainname] = \ Edouard@1387: open(xsdfilename).read() 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@1456: codedesc = targets[targetname]["code"] Edouard@1456: code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())]) Edouard@1456: return code etisserant@209: Edouard@1001: def GetHeader(): Edouard@1001: filename = path.join(path.split(__file__)[0],"beremiz.h") Edouard@1001: return open(filename).read() Edouard@1001: Edouard@733: def GetCode(name): Edouard@1430: filename = path.join(path.split(__file__)[0],name) etisserant@209: return open(filename).read() greg@205: