31 """ |
31 """ |
32 |
32 |
33 from os import listdir, path |
33 from os import listdir, path |
34 |
34 |
35 _base_path = path.split(__file__)[0] |
35 _base_path = path.split(__file__)[0] |
|
36 def _GetLocalTargetClassFactory(name): |
|
37 return lambda:getattr(__import__(name,globals(),locals()), name+"_target") |
36 |
38 |
37 targets = [name for name in listdir(_base_path) |
39 targets = {name: {"xsd":path.join(_base_path, name, "XSD"), |
38 if path.isdir(path.join(_base_path, name)) |
40 "class":_GetLocalTargetClassFactory(name), |
39 and not name.startswith("__")] |
41 "code": path.join(path.split(__file__)[0],name,"plc_%s_main.c"%name)} |
|
42 for name in listdir(_base_path) |
|
43 if path.isdir(path.join(_base_path, name)) |
|
44 and not name.startswith("__")} |
|
45 |
40 toolchains = [name for name in listdir(_base_path) |
46 toolchains = [name for name in listdir(_base_path) |
41 if not path.isdir(path.join(_base_path, name)) |
47 if not path.isdir(path.join(_base_path, name)) |
42 and name.endswith(".py") |
48 and name.endswith(".py") |
43 and not name.startswith("__") |
49 and not name.startswith("__")] |
44 and not name.endswith(".pyc")] |
|
45 |
50 |
46 DictXSD_toolchain = {} |
51 def GetBuilder(targetname): |
47 DictXSD_target = {} |
52 return targets[targetname]["class"]() |
48 |
53 |
49 targetchoices = "" |
54 def GetTargetChoices(): |
|
55 DictXSD_toolchain = {} |
|
56 targetchoices = "" |
50 |
57 |
51 # Get all xsd toolchains |
58 # Get all xsd toolchains |
52 for toolchain in toolchains : |
59 for toolchain in toolchains : |
53 toolchainname = path.splitext(toolchain)[0] |
60 toolchainname = path.splitext(toolchain)[0] |
54 xsdfilename = path.join(_base_path, "XSD_%s"%(toolchainname)) |
61 xsdfilename = path.join(_base_path, "XSD_%s"%(toolchainname)) |
55 if path.isfile(xsdfilename): |
62 if path.isfile(xsdfilename): |
56 xsd_toolchain_string = "" |
63 xsd_toolchain_string = "" |
57 for line in open(xsdfilename).readlines(): |
64 for line in open(xsdfilename).readlines(): |
58 xsd_toolchain_string += line |
65 xsd_toolchain_string += line |
59 DictXSD_toolchain[toolchainname] = xsd_toolchain_string |
66 DictXSD_toolchain[toolchainname] = xsd_toolchain_string |
60 |
67 |
61 # Get all xsd targets |
68 # Get all xsd targets |
62 for targetname in targets: |
69 for targetname,nfo in targets.iteritems(): |
63 xsdfilename = path.join(_base_path, targetname, "XSD") |
70 xsd_string = open(nfo["xsd"]).read() |
64 if path.isfile(xsdfilename): |
71 targetchoices += xsd_string%DictXSD_toolchain |
65 xsd_target_string = "" |
|
66 for line in open(xsdfilename).readlines(): |
|
67 xsd_target_string += line |
|
68 DictXSD_target[targetname] = xsd_target_string%DictXSD_toolchain |
|
69 |
72 |
70 for target in DictXSD_target.keys(): |
73 return targetchoices |
71 targetchoices += DictXSD_target[target] |
|
72 |
74 |
73 def targetcode(target_name, code_name=None): |
75 def GetTargetCode(targetname): |
74 if code_name is None: |
76 return open(targets[targetname]["code"]).read() |
75 code_name="plc_%s_main.c"%target_name |
|
76 filename = path.join(path.split(__file__)[0], target_name, code_name) |
|
77 return open(filename).read() |
|
78 |
77 |
79 def code(name): |
78 def GetCode(name): |
80 filename = path.join(path.split(__file__)[0],name + ".c") |
79 filename = path.join(path.split(__file__)[0],name + ".c") |
81 return open(filename).read() |
80 return open(filename).read() |
82 |
81 |