targets/__init__.py
changeset 1740 b789b695b5c6
parent 1739 ec153828ded2
child 1747 6046ffa2280f
equal deleted inserted replaced
1739:ec153828ded2 1740:b789b695b5c6
    39 
    39 
    40 _base_path = paths.AbsDir(__file__)
    40 _base_path = paths.AbsDir(__file__)
    41 
    41 
    42 
    42 
    43 def _GetLocalTargetClassFactory(name):
    43 def _GetLocalTargetClassFactory(name):
    44     return lambda:getattr(__import__(name,globals(),locals()), name+"_target")
    44     return lambda: getattr(__import__(name, globals(), locals()), name+"_target")
    45 
    45 
    46 targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"),
    46 targets = dict([(name, {"xsd": path.join(_base_path, name, "XSD"),
    47                         "class":_GetLocalTargetClassFactory(name),
    47                         "class": _GetLocalTargetClassFactory(name),
    48                         "code": { fname: path.join(_base_path, name, fname)
    48                         "code": { fname: path.join(_base_path, name, fname)
    49                            for fname in listdir(path.join(_base_path, name))
    49                            for fname in listdir(path.join(_base_path, name))
    50                              if fname.startswith("plc_%s_main" % name) and
    50                              if fname.startswith("plc_%s_main" % name) and
    51                                fname.endswith(".c")}})
    51                                fname.endswith(".c")}})
    52                 for name in listdir(_base_path)
    52                 for name in listdir(_base_path)
    64 def GetTargetChoices():
    64 def GetTargetChoices():
    65     DictXSD_toolchain = {}
    65     DictXSD_toolchain = {}
    66     targetchoices = ""
    66     targetchoices = ""
    67 
    67 
    68     # Get all xsd toolchains
    68     # Get all xsd toolchains
    69     for toolchainname,xsdfilename in toolchains.iteritems():
    69     for toolchainname, xsdfilename in toolchains.iteritems():
    70          if path.isfile(xsdfilename):
    70          if path.isfile(xsdfilename):
    71              DictXSD_toolchain["toolchain_"+toolchainname] = \
    71              DictXSD_toolchain["toolchain_"+toolchainname] = \
    72                 open(xsdfilename).read()
    72                 open(xsdfilename).read()
    73 
    73 
    74     # Get all xsd targets
    74     # Get all xsd targets
    75     for targetname,nfo in targets.iteritems():
    75     for targetname, nfo in targets.iteritems():
    76         xsd_string = open(nfo["xsd"]).read()
    76         xsd_string = open(nfo["xsd"]).read()
    77         targetchoices +=  xsd_string % DictXSD_toolchain
    77         targetchoices +=  xsd_string % DictXSD_toolchain
    78 
    78 
    79     return targetchoices
    79     return targetchoices
    80 
    80 
    84     code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())])
    84     code = "\n".join([open(fpath).read() for fname, fpath in sorted(codedesc.items())])
    85     return code
    85     return code
    86 
    86 
    87 
    87 
    88 def GetHeader():
    88 def GetHeader():
    89     filename = paths.AbsNeighbourFile(__file__,"beremiz.h")
    89     filename = paths.AbsNeighbourFile(__file__, "beremiz.h")
    90     return open(filename).read()
    90     return open(filename).read()
    91 
    91 
    92 
    92 
    93 def GetCode(name):
    93 def GetCode(name):
    94     filename = paths.AbsNeighbourFile(__file__,name)
    94     filename = paths.AbsNeighbourFile(__file__, name)
    95     return open(filename).read()
    95     return open(filename).read()