targets/__init__.py
changeset 1680 6db967480b7d
parent 1571 486f94a8032c
child 1730 64d8f52bc8c8
equal deleted inserted replaced
1679:2fcea15858a5 1680:6db967480b7d
     3 
     3 
     4 # This file is part of Beremiz, a Integrated Development Environment for
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 # Copyright (C) 2017: Andrey Skvortsov
     8 #
     9 #
     9 # See COPYING file for copyrights details.
    10 # See COPYING file for copyrights details.
    10 #
    11 #
    11 # This program is free software; you can redistribute it and/or
    12 # This program is free software; you can redistribute it and/or
    12 # modify it under the terms of the GNU General Public License
    13 # modify it under the terms of the GNU General Public License
    32 - Target class may inherit from a toolchain_(toolchainname)
    33 - Target class may inherit from a toolchain_(toolchainname)
    33 - The target folder's name must match to name define in the XSD for TargetType
    34 - The target folder's name must match to name define in the XSD for TargetType
    34 """
    35 """
    35 
    36 
    36 from os import listdir, path
    37 from os import listdir, path
       
    38 import util.paths as paths
    37 
    39 
    38 _base_path = path.split(__file__)[0]
    40 _base_path = paths.AbsDir(__file__)
    39 def _GetLocalTargetClassFactory(name):
    41 def _GetLocalTargetClassFactory(name):
    40     return lambda:getattr(__import__(name,globals(),locals()), name+"_target")
    42     return lambda:getattr(__import__(name,globals(),locals()), name+"_target")
    41 
    43 
    42 targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"), 
    44 targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"), 
    43                         "class":_GetLocalTargetClassFactory(name),
    45                         "class":_GetLocalTargetClassFactory(name),
    76     codedesc = targets[targetname]["code"]
    78     codedesc = targets[targetname]["code"]
    77     code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())])
    79     code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())])
    78     return code
    80     return code
    79 
    81 
    80 def GetHeader():
    82 def GetHeader():
    81     filename = path.join(path.split(__file__)[0],"beremiz.h")
    83     filename = paths.AbsNeighbourFile(__file__,"beremiz.h")
    82     return open(filename).read()
    84     return open(filename).read()
    83 
    85 
    84 def GetCode(name):
    86 def GetCode(name):
    85     filename = path.join(path.split(__file__)[0],name)
    87     filename = paths.AbsNeighbourFile(__file__,name)
    86     return open(filename).read()
    88     return open(filename).read()
    87 
    89