Rev 2006 | Rev 2137 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2006 | Rev 2127 | ||
|---|---|---|---|
| 1 | #!/usr/bin/python |
1 | #!/usr/bin/python |
| 2 | 2 | ||
| 3 | # Written by Mattias Runge 2008-05-13 |
3 | # Written by Mattias Runge 2008-05-13 |
| 4 | 4 | ||
| 5 | import os |
5 | import os |
| 6 | import sys |
6 | import sys |
| 7 | import getopt |
7 | import getopt |
| 8 | 8 | ||
| 9 | moddir = sys.path[0] + "/../../EmbeddedSoftware/AVR/module" |
9 | moddir = sys.path[0] + "/../../EmbeddedSoftware/AVR/module" |
| 10 | localmoddir = os.getcwd() + "/modules" |
10 | localmoddir = os.getcwd() + "/modules" |
| 11 | 11 | ||
| 12 | def getModules(): |
12 | def getModules(): |
| 13 | modules = [] |
13 | modules = [] |
| 14 | for fileName in os.listdir(moddir): |
14 | for fileName in os.listdir(moddir): |
| 15 | if fileName[0] != '.' and fileName != "template": |
15 | if fileName[0] != '.' and fileName != "template": |
| 16 | modules.append(fileName) |
16 | modules.append(fileName) |
| 17 | 17 | ||
| 18 | return sorted(modules, key=str.lower) |
18 | return sorted(modules, key=str.lower) |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | def getLocalModules(): |
21 | def getLocalModules(): |
| 22 | modules = [] |
22 | modules = [] |
| 23 | for fileName in os.listdir(localmoddir): |
23 | for fileName in os.listdir(localmoddir): |
| 24 | if fileName[0] != '.': |
24 | if fileName[0] != '.': |
| 25 | modules.append(fileName) |
25 | modules.append(fileName) |
| 26 | 26 | ||
| 27 | return sorted(modules, key=str.lower) |
27 | return sorted(modules, key=str.lower) |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | def parseModuleIdFromFile(moduleName, fileName): |
30 | def parseModuleIdFromFile(moduleName, fileName): |
| 31 | config_inc = open(fileName, 'r') |
31 | config_inc = open(fileName, 'r') |
| 32 | config_inc_lines = config_inc.readlines() |
32 | config_inc_lines = config_inc.readlines() |
| 33 | config_inc.close() |
33 | config_inc.close() |
| 34 | takenIds = [] |
34 | takenIds = [] |
| 35 | for line in config_inc_lines: |
35 | for line in config_inc_lines: |
| 36 | line = line.strip("\n").strip(" ") |
36 | line = line.strip("\n").strip(" ") |
| 37 | 37 | ||
| 38 | if line.find(moduleName + "_ID") != -1: |
38 | if line.find(moduleName + "_ID") != -1: |
| 39 | parts = line.split("=") |
39 | parts = line.split("=") |
| 40 | if parts[1].strip(" ") != -1 and parts[1].strip(" ") != "<ID>": |
40 | if parts[1].strip(" ") != -1 and parts[1].strip(" ") != "<ID>": |
| 41 | takenIds.append(int(parts[1].strip(" "), 16)) |
41 | takenIds.append(int(parts[1].strip(" "), 16)) |
| 42 | print "Found id: "+parts[1].strip(" ")+" in file: "+fileName+" for module: "+moduleName |
42 | print "Found id: "+parts[1].strip(" ")+" in file: "+fileName+" for module: "+moduleName |
| - | 43 | ||
| 43 | return takenIds |
44 | return takenIds |
| 44 | 45 | ||
| 45 | 46 | ||
| 46 | def getModuleIdsFromFile(moduleName): |
47 | def getModuleIdsFromFile(moduleName): |
| 47 | takenIds = [] |
48 | takenIds = [] |
| 48 | for applicationName in os.listdir("../"): |
49 | for applicationName in os.listdir("../"): |
| 49 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
50 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
| 50 | takenIds = parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc") |
51 | takenIds += parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc") |
| 51 | - | ||
| 52 | return takenIds |
52 | return takenIds |
| 53 | 53 | ||
| 54 | def parseAllModuleIdFromFile(fileName, foundModules): |
54 | def parseAllModuleIdFromFile(fileName, foundModules): |
| 55 | index = 0 |
55 | index = 0 |
| 56 | modules = getModules() |
56 | modules = getModules() |
| 57 | config_inc = open(fileName, 'r') |
57 | config_inc = open(fileName, 'r') |
| 58 | config_inc_lines = config_inc.readlines() |
58 | config_inc_lines = config_inc.readlines() |
| 59 | config_inc.close() |
59 | config_inc.close() |
| 60 | parts = fileName.split("/") |
60 | parts = fileName.split("/") |
| 61 | node = parts[1] |
61 | node = parts[1] |
| 62 | for line in config_inc_lines: |
62 | for line in config_inc_lines: |
| 63 | line = line.strip("\n").strip(" ") |
63 | line = line.strip("\n").strip(" ") |
| 64 | 64 | ||
| 65 | if line.find("_ID") != -1: |
65 | if line.find("_ID") != -1: |
| 66 | parts = line.split("=") |
66 | parts = line.split("=") |
| 67 | if (parts[0][:-3] in modules): |
67 | if (parts[0][:-3] in modules): |
| 68 | if parts[1].strip(" ") != -1 and parts[1].strip(" ") != "<ID>": |
68 | if parts[1].strip(" ") != -1 and parts[1].strip(" ") != "<ID>": |
| 69 | if (foundModules == 0): |
69 | if (foundModules == 0): |
| 70 | print "\tModule: "+parts[0][:-3]+"\t"+parts[1].strip(" ") |
70 | print "\tModule: "+parts[0][:-3]+"\t"+parts[1].strip(" ") |
| 71 | else: |
71 | else: |
| 72 | foundModules.append(parts[0][:-3]+"$"+node+"$"+parts[1].strip(" ")) |
72 | foundModules.append(parts[0][:-3]+"$"+node+"$"+parts[1].strip(" ")) |
| 73 | 73 | ||
| 74 | return foundModules |
74 | return foundModules |
| 75 | 75 | ||
| 76 | def getAllModuleIdsFromFile(): |
76 | def getAllModuleIdsFromFile(): |
| 77 | foundModules = [] |
77 | foundModules = [] |
| 78 | for applicationName in os.listdir("../"): |
78 | for applicationName in os.listdir("../"): |
| 79 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
79 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
| 80 | parseAllModuleIdFromFile("../" + applicationName + "/config.inc", foundModules) |
80 | parseAllModuleIdFromFile("../" + applicationName + "/config.inc", foundModules) |
| 81 | 81 | ||
| 82 | foundModulesSorted = sorted(foundModules, key=str.lower) |
82 | foundModulesSorted = sorted(foundModules, key=str.lower) |
| 83 | lastModule = "" |
83 | lastModule = "" |
| 84 | for x in foundModulesSorted: |
84 | for x in foundModulesSorted: |
| 85 | splitted = x.split("$") |
85 | splitted = x.split("$") |
| 86 | if (lastModule != splitted[0]): |
86 | if (lastModule != splitted[0]): |
| 87 | lastModule = splitted[0] |
87 | lastModule = splitted[0] |
| 88 | print lastModule |
88 | print lastModule |
| 89 | print "%20s :" % splitted[1], |
89 | print "%20s :" % splitted[1], |
| 90 | print splitted[2] |
90 | print splitted[2] |
| 91 | 91 | ||
| 92 | def getAllNodesFromFile(): |
92 | def getAllNodesFromFile(): |
| 93 | files = sorted(os.listdir("../"), key=str.lower) |
93 | files = sorted(os.listdir("../"), key=str.lower) |
| 94 | for applicationName in files: |
94 | for applicationName in files: |
| 95 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
95 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
| 96 | print "Found node: "+applicationName |
96 | print "Found node: "+applicationName |
| 97 | parseAllModuleIdFromFile("../" + applicationName + "/config.inc", 0) |
97 | parseAllModuleIdFromFile("../" + applicationName + "/config.inc", 0) |
| 98 | 98 | ||
| 99 | def getFreeModuleId(takenIds): |
99 | def getFreeModuleId(takenIds): |
| 100 | if len(takenIds) == 0: |
100 | if len(takenIds) == 0: |
| 101 | return 1 |
101 | return 1 |
| 102 | takenIds.sort() |
102 | takenIds.sort() |
| 103 | - | ||
| 104 | lastId = 0 |
103 | lastId = 0 |
| 105 | 104 | ||
| 106 | for takenId in takenIds: |
105 | for takenId in takenIds: |
| 107 | if takenId != lastId+1: |
106 | if ((takenId != lastId+1) & (takenId != lastId)): |
| 108 | return lastId+1 |
107 | return lastId+1 |
| 109 | lastId = takenId |
108 | lastId = takenId |
| 110 | 109 | ||
| 111 | return lastId+1 |
110 | return lastId+1 |
| 112 | - | ||
| 113 | 111 | ||
| 114 | 112 | ||
| 115 | def compileMainFile(): |
113 | def compileMainFile(): |
| 116 | print "Compiling new main.c..." |
114 | print "Compiling new main.c..." |
| 117 | main_c_template = open('src/main.c.template', 'r') |
115 | main_c_template = open('src/main.c.template', 'r') |
| 118 | main_c_template_lines = main_c_template.readlines() |
116 | main_c_template_lines = main_c_template.readlines() |
| 119 | main_c_template.close() |
117 | main_c_template.close() |
| 120 | 118 | ||
| 121 | modules = getLocalModules() |
119 | modules = getLocalModules() |
| 122 | 120 | ||
| 123 | main_c = open('src/main.c', 'w') |
121 | main_c = open('src/main.c', 'w') |
| 124 | 122 | ||
| 125 | for main_c_template_line in main_c_template_lines: |
123 | for main_c_template_line in main_c_template_lines: |
| 126 | pos_include = main_c_template_line.find('%INCLUDE') |
124 | pos_include = main_c_template_line.find('%INCLUDE') |
| 127 | pos_init = main_c_template_line.find('%INIT') |
125 | pos_init = main_c_template_line.find('%INIT') |
| 128 | pos_process = main_c_template_line.find('%PROCESS') |
126 | pos_process = main_c_template_line.find('%PROCESS') |
| 129 | pos_list = main_c_template_line.find('%LIST') |
127 | pos_list = main_c_template_line.find('%LIST') |
| 130 | pos_handlemsg = main_c_template_line.find('%HANDLEMSG') |
128 | pos_handlemsg = main_c_template_line.find('%HANDLEMSG') |
| 131 | 129 | ||
| 132 | if pos_include != -1: |
130 | if pos_include != -1: |
| 133 | for moduleName in modules: |
131 | for moduleName in modules: |
| 134 | main_c.write(main_c_template_line[:pos_include] + "#include \"../modules/" + moduleName + "/" + moduleName + ".h\"\n") |
132 | main_c.write(main_c_template_line[:pos_include] + "#include \"../modules/" + moduleName + "/" + moduleName + ".h\"\n") |
| 135 | elif pos_init != -1: |
133 | elif pos_init != -1: |
| 136 | for moduleName in modules: |
134 | for moduleName in modules: |
| 137 | main_c.write(main_c_template_line[:pos_init] + moduleName + "_Init();\n") |
135 | main_c.write(main_c_template_line[:pos_init] + moduleName + "_Init();\n") |
| 138 | elif pos_process != -1: |
136 | elif pos_process != -1: |
| 139 | for moduleName in modules: |
137 | for moduleName in modules: |
| 140 | main_c.write(main_c_template_line[:pos_process] + moduleName + "_Process();\n") |
138 | main_c.write(main_c_template_line[:pos_process] + moduleName + "_Process();\n") |
| 141 | elif pos_list != -1: |
139 | elif pos_list != -1: |
| 142 | count = 1 |
140 | count = 1 |
| 143 | for moduleName in modules: |
141 | for moduleName in modules: |
| 144 | main_c.write(main_c_template_line[:pos_list] + moduleName + "_List(" + str(count) + ");\n") |
142 | main_c.write(main_c_template_line[:pos_list] + moduleName + "_List(" + str(count) + ");\n") |
| 145 | count += 1 |
143 | count += 1 |
| 146 | elif pos_handlemsg != -1: |
144 | elif pos_handlemsg != -1: |
| 147 | for moduleName in modules: |
145 | for moduleName in modules: |
| 148 | main_c.write(main_c_template_line[:pos_handlemsg] + moduleName + "_HandleMessage(&rxMsg);\n") |
146 | main_c.write(main_c_template_line[:pos_handlemsg] + moduleName + "_HandleMessage(&rxMsg);\n") |
| 149 | else: |
147 | else: |
| 150 | main_c.write(main_c_template_line) |
148 | main_c.write(main_c_template_line) |
| 151 | 149 | ||
| 152 | main_c.close() |
150 | main_c.close() |
| 153 | 151 | ||
| 154 | print "Creation of main.c complete" |
152 | print "Creation of main.c complete" |
| 155 | 153 | ||
| 156 | def readConfigSection(fileName, sectionName): |
154 | def readConfigSection(fileName, sectionName): |
| 157 | fileInstance = open(fileName, 'r') |
155 | fileInstance = open(fileName, 'r') |
| 158 | lines = fileInstance.readlines() |
156 | lines = fileInstance.readlines() |
| 159 | fileInstance.close() |
157 | fileInstance.close() |
| 160 | 158 | ||
| 161 | sectionLines = [] |
159 | sectionLines = [] |
| 162 | 160 | ||
| 163 | inSection = False |
161 | inSection = False |
| 164 | 162 | ||
| 165 | for line in lines: |
163 | for line in lines: |
| 166 | if not inSection: |
164 | if not inSection: |
| 167 | if line.find("## Section " + sectionName + " --") != -1: |
165 | if line.find("## Section " + sectionName + " --") != -1: |
| 168 | inSection = True |
166 | inSection = True |
| 169 | sectionLines.append(line.strip("\n")) |
167 | sectionLines.append(line.strip("\n")) |
| 170 | else: |
168 | else: |
| 171 | if line.find("## End section " + sectionName + " --") != -1: |
169 | if line.find("## End section " + sectionName + " --") != -1: |
| 172 | inSection = False |
170 | inSection = False |
| 173 | 171 | ||
| 174 | sectionLines.append(line.strip("\n")) |
172 | sectionLines.append(line.strip("\n")) |
| 175 | 173 | ||
| 176 | return sectionLines |
174 | return sectionLines |
| 177 | 175 | ||
| 178 | 176 | ||
| 179 | def updateConfigFile(): |
177 | def updateConfigFile(): |
| 180 | print "Updating config.inc..." |
178 | print "Updating config.inc..." |
| 181 | modules = getLocalModules() |
179 | modules = getLocalModules() |
| 182 | moduleSections = {} |
180 | moduleSections = {} |
| 183 | applicationSection = [] |
181 | applicationSection = [] |
| 184 | moduleName="none" |
182 | moduleName="none" |
| 185 | if not os.path.exists("config.inc"): |
183 | if not os.path.exists("config.inc"): |
| 186 | applicationSection = readConfigSection("src/config.inc.template", "application") |
184 | applicationSection = readConfigSection("src/config.inc.template", "application") |
| 187 | 185 | ||
| 188 | for moduleName in modules: |
186 | for moduleName in modules: |
| 189 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
187 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
| 190 | else: |
188 | else: |
| 191 | applicationSection = readConfigSection("config.inc", "application") |
189 | applicationSection = readConfigSection("config.inc", "application") |
| 192 | 190 | ||
| 193 | for moduleName in modules: |
191 | for moduleName in modules: |
| 194 | moduleSections[moduleName] = readConfigSection("config.inc", moduleName) |
192 | moduleSections[moduleName] = readConfigSection("config.inc", moduleName) |
| 195 | 193 | ||
| 196 | if len(moduleSections[moduleName]) <= 1: |
194 | if len(moduleSections[moduleName]) <= 1: |
| 197 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
195 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
| 198 | 196 | ||
| 199 | timers = 0 |
197 | timers = 0 |
| 200 | pcints = 0 |
198 | pcints = 0 |
| 201 | 199 | ||
| 202 | moduleIds = getModuleIdsFromFile(moduleName) |
200 | moduleIds = getModuleIdsFromFile(moduleName) |
| 203 | 201 | ||
| 204 | for moduleName, moduleSection in moduleSections.iteritems(): |
202 | for moduleName, moduleSection in moduleSections.iteritems(): |
| 205 | c = 0 |
203 | c = 0 |
| 206 | for line in moduleSection: |
204 | for line in moduleSection: |
| 207 | if len(line) > 0: |
205 | if len(line) > 0: |
| 208 | if line[0] != '#': |
206 | if line[0] != '#': |
| 209 | if line.find("<ID>") != -1: |
207 | if line.find("<ID>") != -1: |
| 210 | new_ID = getFreeModuleId(moduleIds) |
208 | new_ID = getFreeModuleId(moduleIds) |
| 211 | print " |
209 | print "\nNew module id set to: "+hex(new_ID)+"\n" |
| 212 | moduleIds.append(new_ID) |
210 | moduleIds.append(new_ID) |
| 213 | line = line.replace("<ID>", hex(new_ID)) |
211 | line = line.replace("<ID>", hex(new_ID)) |
| 214 | elif line.find("<TIMER>") != -1: |
212 | elif line.find("<TIMER>") != -1: |
| 215 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
213 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
| 216 | timers += 1 |
214 | timers += 1 |
| 217 | elif line.find("<PCINT>") != -1: |
215 | elif line.find("<PCINT>") != -1: |
| 218 | line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */" |
216 | line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */" |
| 219 | pcints += 1 |
217 | pcints += 1 |
| 220 | 218 | ||
| 221 | moduleSection[c] = line; |
219 | moduleSection[c] = line; |
| 222 | c += 1 |
220 | c += 1 |
| 223 | 221 | ||
| 224 | c = 0 |
222 | c = 0 |
| 225 | for line in applicationSection: |
223 | for line in applicationSection: |
| 226 | if len(line) > 0: |
224 | if len(line) > 0: |
| 227 | if line[0] != '#': |
225 | if line[0] != '#': |
| 228 | if line.find("<TIMER>") != -1: |
226 | if line.find("<TIMER>") != -1: |
| 229 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
227 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
| 230 | timers += 1 |
228 | timers += 1 |
| 231 | elif line.find("TIMER_NUM_TIMERS=") != -1: |
229 | elif line.find("TIMER_NUM_TIMERS=") != -1: |
| 232 | line = "TIMER_NUM_TIMERS=" + hex(timers) |
230 | line = "TIMER_NUM_TIMERS=" + hex(timers) |
| 233 | elif line.find("NUMBER_OF_MODULES=") != -1: |
231 | elif line.find("NUMBER_OF_MODULES=") != -1: |
| 234 | line = "NUMBER_OF_MODULES=" + hex(len(modules)) |
232 | line = "NUMBER_OF_MODULES=" + hex(len(modules)) |
| 235 | elif line.find("<PCINT>") != -1: |
233 | elif line.find("<PCINT>") != -1: |
| 236 | line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */" |
234 | line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */" |
| 237 | pcints += 1 |
235 | pcints += 1 |
| 238 | elif line.find("PCINT_NUM_PCINTS=") != -1: |
236 | elif line.find("PCINT_NUM_PCINTS=") != -1: |
| 239 | line = "PCINT_NUM_PCINTS=" + hex(pcints) |
237 | line = "PCINT_NUM_PCINTS=" + hex(pcints) |
| 240 | applicationSection[c] = line; |
238 | applicationSection[c] = line; |
| 241 | c += 1 |
239 | c += 1 |
| 242 | 240 | ||
| 243 | config_inc = open('config.inc', 'w') |
241 | config_inc = open('config.inc', 'w') |
| 244 | 242 | ||
| 245 | for line in applicationSection: |
243 | for line in applicationSection: |
| 246 | config_inc.write(line + "\n") |
244 | config_inc.write(line + "\n") |
| 247 | 245 | ||
| 248 | for moduleName, moduleSection in moduleSections.iteritems(): |
246 | for moduleName, moduleSection in moduleSections.iteritems(): |
| 249 | for line in moduleSection: |
247 | for line in moduleSection: |
| 250 | config_inc.write(line + "\n") |
248 | config_inc.write(line + "\n") |
| 251 | 249 | ||
| 252 | config_inc.close() |
250 | config_inc.close() |
| 253 | 251 | ||
| 254 | print "Update of config.inc complete" |
252 | print "Update of config.inc complete" |
| 255 | 253 | ||
| 256 | 254 | ||
| 257 | def compileSourcesFile(): |
255 | def compileSourcesFile(): |
| 258 | print "Compiling sources.inc..." |
256 | print "Compiling sources.inc..." |
| 259 | 257 | ||
| 260 | uniqueSet = [] |
258 | uniqueSet = [] |
| 261 | uniqueSet2 = [] |
259 | uniqueSet2 = [] |
| 262 | if os.path.isfile("src/libraries.list.template"): |
260 | if os.path.isfile("src/libraries.list.template"): |
| 263 | libraries_list_template = open('src/libraries.list.template', 'r') |
261 | libraries_list_template = open('src/libraries.list.template', 'r') |
| 264 | libraries_list_template_lines = libraries_list_template.readlines() |
262 | libraries_list_template_lines = libraries_list_template.readlines() |
| 265 | libraries_list_template.close() |
263 | libraries_list_template.close() |
| 266 | 264 | ||
| 267 | sources_list_template = open('src/sources.list.template', 'r') |
265 | sources_list_template = open('src/sources.list.template', 'r') |
| 268 | sources_list_template_lines = sources_list_template.readlines() |
266 | sources_list_template_lines = sources_list_template.readlines() |
| 269 | sources_list_template.close() |
267 | sources_list_template.close() |
| 270 | if os.path.isfile("src/libraries.list.template"): |
268 | if os.path.isfile("src/libraries.list.template"): |
| 271 | for libraries_list_template_line in libraries_list_template_lines: |
269 | for libraries_list_template_line in libraries_list_template_lines: |
| 272 | line =libraries_list_template_line.strip("\n").strip(" ") |
270 | line =libraries_list_template_line.strip("\n").strip(" ") |
| 273 | if len(line) > 0: |
271 | if len(line) > 0: |
| 274 | if line[0] != '#': |
272 | if line[0] != '#': |
| 275 | uniqueSet2.append(line) |
273 | uniqueSet2.append(line) |
| 276 | 274 | ||
| 277 | for sources_list_template_line in sources_list_template_lines: |
275 | for sources_list_template_line in sources_list_template_lines: |
| 278 | line = sources_list_template_line.strip("\n").strip(" ") |
276 | line = sources_list_template_line.strip("\n").strip(" ") |
| 279 | if len(line) > 0: |
277 | if len(line) > 0: |
| 280 | if line[0] != '#': |
278 | if line[0] != '#': |
| 281 | uniqueSet.append(line) |
279 | uniqueSet.append(line) |
| 282 | 280 | ||
| 283 | modules = getLocalModules() |
281 | modules = getLocalModules() |
| 284 | 282 | ||
| 285 | for moduleName in modules: |
283 | for moduleName in modules: |
| 286 | sources_list = open(localmoddir + "/" + moduleName + "/sources.list", 'r') |
284 | sources_list = open(localmoddir + "/" + moduleName + "/sources.list", 'r') |
| 287 | sources_list_lines = sources_list.readlines() |
285 | sources_list_lines = sources_list.readlines() |
| 288 | sources_list.close() |
286 | sources_list.close() |
| 289 | 287 | ||
| 290 | if os.path.isfile(localmoddir + "/" + moduleName + "/libraries.list"): |
288 | if os.path.isfile(localmoddir + "/" + moduleName + "/libraries.list"): |
| 291 | libraries_list = open(localmoddir + "/" + moduleName + "/libraries.list", 'r') |
289 | libraries_list = open(localmoddir + "/" + moduleName + "/libraries.list", 'r') |
| 292 | libraries_list_lines = libraries_list.readlines() |
290 | libraries_list_lines = libraries_list.readlines() |
| 293 | libraries_list.close() |
291 | libraries_list.close() |
| 294 | 292 | ||
| 295 | for libraries_list_line in libraries_list_lines: |
293 | for libraries_list_line in libraries_list_lines: |
| 296 | line = libraries_list_line.strip("\n").strip(" ") |
294 | line = libraries_list_line.strip("\n").strip(" ") |
| 297 | if len(line) > 0: |
295 | if len(line) > 0: |
| 298 | if line[0] != '#': |
296 | if line[0] != '#': |
| 299 | uniqueSet2.append("../../../module/" + moduleName + line) |
297 | uniqueSet2.append("../../../module/" + moduleName + line) |
| 300 | for sources_list_line in sources_list_lines: |
298 | for sources_list_line in sources_list_lines: |
| 301 | line = sources_list_line.strip("\n").strip(" ") |
299 | line = sources_list_line.strip("\n").strip(" ") |
| 302 | if len(line) > 0: |
300 | if len(line) > 0: |
| 303 | if line[0] != '#': |
301 | if line[0] != '#': |
| 304 | uniqueSet.append(line) |
302 | uniqueSet.append(line) |
| 305 | 303 | ||
| 306 | 304 | ||
| 307 | sourcesString = "SOURCES = " |
305 | sourcesString = "SOURCES = " |
| 308 | 306 | ||
| 309 | #FIXME: Make uniqueSet actually unique |
307 | #FIXME: Make uniqueSet actually unique |
| 310 | 308 | ||
| 311 | for line in uniqueSet: |
309 | for line in uniqueSet: |
| 312 | sourcesString += line + " " |
310 | sourcesString += line + " " |
| 313 | sourcesString += "\n" |
311 | sourcesString += "\n" |
| 314 | sourcesString += "LDLIBS = " |
312 | sourcesString += "LDLIBS = " |
| 315 | for line in uniqueSet2: |
313 | for line in uniqueSet2: |
| 316 | sourcesString += line + " " |
314 | sourcesString += line + " " |
| 317 | sources_inc = open('sources.inc', 'w') |
315 | sources_inc = open('sources.inc', 'w') |
| 318 | sources_inc.write(sourcesString.strip(" ") + "\n") |
316 | sources_inc.write(sourcesString.strip(" ") + "\n") |
| 319 | sources_inc.close() |
317 | sources_inc.close() |
| 320 | 318 | ||
| 321 | print "Creation of sources.inc complete" |
319 | print "Creation of sources.inc complete" |
| 322 | 320 | ||
| 323 | def regenerateModules(): |
321 | def regenerateModules(): |
| 324 | print "Regenerating modules..." |
322 | print "Regenerating modules..." |
| 325 | print "" |
323 | print "" |
| 326 | compileSourcesFile() |
324 | compileSourcesFile() |
| 327 | print "" |
325 | print "" |
| 328 | compileMainFile() |
326 | compileMainFile() |
| 329 | print "" |
327 | print "" |
| 330 | updateConfigFile() |
328 | updateConfigFile() |
| 331 | print "" |
329 | print "" |
| 332 | print "Regenerating modules complete" |
330 | print "Regenerating modules complete" |
| 333 | print "" |
331 | print "" |
| 334 | 332 | ||
| 335 | def listUsedModules(): |
333 | def listUsedModules(): |
| 336 | print "Listing modules..." |
334 | print "Listing modules..." |
| 337 | print "" |
335 | print "" |
| 338 | getAllModuleIdsFromFile() |
336 | getAllModuleIdsFromFile() |
| 339 | print "" |
337 | print "" |
| 340 | print "Listing modules complete" |
338 | print "Listing modules complete" |
| 341 | print "" |
339 | print "" |
| 342 | 340 | ||
| 343 | def listUsedNodes(): |
341 | def listUsedNodes(): |
| 344 | print "Listing nodes..." |
342 | print "Listing nodes..." |
| 345 | print "" |
343 | print "" |
| 346 | getAllNodesFromFile() |
344 | getAllNodesFromFile() |
| 347 | print "" |
345 | print "" |
| 348 | print "Listing nodes complete" |
346 | print "Listing nodes complete" |
| 349 | print "" |
347 | print "" |
| 350 | 348 | ||
| 351 | def addModule(moduleName): |
349 | def addModule(moduleName): |
| 352 | print "Trying to add module " + moduleName |
350 | print "Trying to add module " + moduleName |
| 353 | 351 | ||
| 354 | try: |
352 | try: |
| 355 | # the following creates symlinks to <path to modulemanager>/../../EmbeddedSoftware/AVR/module |
353 | # the following creates symlinks to <path to modulemanager>/../../EmbeddedSoftware/AVR/module |
| 356 | # and <path to modulemanager> is an absolute path which makes the symlink similar to this: |
354 | # and <path to modulemanager> is an absolute path which makes the symlink similar to this: |
| 357 | # act_dimmer230 -> /home/arune/Documents/HomeAutomation/PcSoftware/scripts/../../EmbeddedSoftware/AVR/module/act_dimmer230 |
355 | # act_dimmer230 -> /home/arune/Documents/HomeAutomation/PcSoftware/scripts/../../EmbeddedSoftware/AVR/module/act_dimmer230 |
| 358 | #os.symlink(moddir + "/" + moduleName, localmoddir + "/" + moduleName) |
356 | #os.symlink(moddir + "/" + moduleName, localmoddir + "/" + moduleName) |
| 359 | # instead symlink to relative path instead |
357 | # instead symlink to relative path instead |
| 360 | os.symlink("../../../module/" + moduleName, localmoddir + "/" + moduleName) |
358 | os.symlink("../../../module/" + moduleName, localmoddir + "/" + moduleName) |
| 361 | print "Added module successfully" |
359 | print "Added module successfully" |
| 362 | except OSError, (errno, strerror): |
360 | except OSError, (errno, strerror): |
| 363 | if errno == 17: |
361 | if errno == 17: |
| 364 | print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking" |
362 | print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking" |
| 365 | else: |
363 | else: |
| 366 | raise |
364 | raise |
| 367 | 365 | ||
| 368 | print "" |
366 | print "" |
| 369 | 367 | ||
| 370 | regenerateModules() |
368 | regenerateModules() |
| 371 | 369 | ||
| 372 | 370 | ||
| 373 | def delModule(moduleName): |
371 | def delModule(moduleName): |
| 374 | print "Trying to remove module " + moduleName |
372 | print "Trying to remove module " + moduleName |
| 375 | 373 | ||
| 376 | try: |
374 | try: |
| 377 | os.unlink(localmoddir + "/" + moduleName) |
375 | os.unlink(localmoddir + "/" + moduleName) |
| 378 | print "Removed module successfully" |
376 | print "Removed module successfully" |
| 379 | except OSError, (errno, strerror): |
377 | except OSError, (errno, strerror): |
| 380 | if errno == 2: |
378 | if errno == 2: |
| 381 | print "No such " + moduleName + " present in the modules directory, not unlinking" |
379 | print "No such " + moduleName + " present in the modules directory, not unlinking" |
| 382 | else: |
380 | else: |
| 383 | raise |
381 | raise |
| 384 | 382 | ||
| 385 | print "" |
383 | print "" |
| 386 | 384 | ||
| 387 | regenerateModules() |
385 | regenerateModules() |
| 388 | 386 | ||
| 389 | def createFile(moduleName, templateFileName, moduleFileName): |
387 | def createFile(moduleName, templateFileName, moduleFileName): |
| 390 | print "Creating " + moduleName + "/" + templateFileName + "..." |
388 | print "Creating " + moduleName + "/" + templateFileName + "..." |
| 391 | template_file = open(moddir + "/template/" + templateFileName, 'r') |
389 | template_file = open(moddir + "/template/" + templateFileName, 'r') |
| 392 | lines = template_file.readlines() |
390 | lines = template_file.readlines() |
| 393 | template_file.close() |
391 | template_file.close() |
| 394 | 392 | ||
| 395 | module_file = open(moddir + "/" + moduleName + "/" + moduleFileName, 'w') |
393 | module_file = open(moddir + "/" + moduleName + "/" + moduleFileName, 'w') |
| 396 | 394 | ||
| 397 | for line in lines: |
395 | for line in lines: |
| 398 | line = line.replace("<template>", moduleName) |
396 | line = line.replace("<template>", moduleName) |
| 399 | line = line.replace("<TEMPLATE>", moduleName.upper()) |
397 | line = line.replace("<TEMPLATE>", moduleName.upper()) |
| 400 | 398 | ||
| 401 | module_file.write(line) |
399 | module_file.write(line) |
| 402 | 400 | ||
| 403 | module_file.close() |
401 | module_file.close() |
| 404 | 402 | ||
| 405 | def newModule(moduleName): |
403 | def newModule(moduleName): |
| 406 | print "Creating " + moddir + "/" + moduleName + " directory..." |
404 | print "Creating " + moddir + "/" + moduleName + " directory..." |
| 407 | os.mkdir(moddir + "/" + moduleName + "/") |
405 | os.mkdir(moddir + "/" + moduleName + "/") |
| 408 | 406 | ||
| 409 | createFile(moduleName, "config.inc.template", "config.inc.template") |
407 | createFile(moduleName, "config.inc.template", "config.inc.template") |
| 410 | createFile(moduleName, "sources.list", "sources.list") |
408 | createFile(moduleName, "sources.list", "sources.list") |
| 411 | createFile(moduleName, "template.h", moduleName + ".h") |
409 | createFile(moduleName, "template.h", moduleName + ".h") |
| 412 | createFile(moduleName, "template.c", moduleName + ".c") |
410 | createFile(moduleName, "template.c", moduleName + ".c") |
| 413 | createFile(moduleName, "template_eeprom.h", moduleName + "_eeprom.h") |
411 | createFile(moduleName, "template_eeprom.h", moduleName + "_eeprom.h") |
| 414 | 412 | ||
| 415 | def usage(): |
413 | def usage(): |
| 416 | print "Syntax: ./ModuleManager [options]" |
414 | print "Syntax: ./ModuleManager [options]" |
| 417 | print "Options:" |
415 | print "Options:" |
| 418 | print " --help Print this help" |
416 | print " --help Print this help" |
| 419 | print " --regenerate Regenarate modules and files" |
417 | print " --regenerate Regenarate modules and files" |
| 420 | print " --list List avalible and installed modules" |
418 | print " --list List avalible and installed modules" |
| 421 | print " --add=<module name> Adds a module to the application" |
419 | print " --add=<module name> Adds a module to the application" |
| 422 | print " --del=<module name> Removes a module from the application" |
420 | print " --del=<module name> Removes a module from the application" |
| 423 | print " --new=<module name> Creates a new module from the module template" |
421 | print " --new=<module name> Creates a new module from the module template" |
| 424 | print " --modules Lists all used modules in your personal folder" |
422 | print " --modules Lists all used modules in your personal folder" |
| 425 | print " --nodes Lists all nodes in your personal folder" |
423 | print " --nodes Lists all nodes in your personal folder" |
| 426 | print "" |
424 | print "" |
| 427 | 425 | ||
| 428 | 426 | ||
| 429 | def main(): |
427 | def main(): |
| 430 | try: |
428 | try: |
| 431 | opts, args = getopt.getopt(sys.argv[1:], "hlrcmn", ["help", "list", "modules", "nodes", "regenerate", "add=", "del=", "new="]) |
429 | opts, args = getopt.getopt(sys.argv[1:], "hlrcmn", ["help", "list", "modules", "nodes", "regenerate", "add=", "del=", "new="]) |
| 432 | except getopt.GetoptError, err: |
430 | except getopt.GetoptError, err: |
| 433 | # print help information and exit: |
431 | # print help information and exit: |
| 434 | print str(err) # will print something like "option -a not recognized" |
432 | print str(err) # will print something like "option -a not recognized" |
| 435 | usage() |
433 | usage() |
| 436 | sys.exit(2) |
434 | sys.exit(2) |
| 437 | 435 | ||
| 438 | if len(sys.argv) == 1: |
436 | if len(sys.argv) == 1: |
| 439 | usage() |
437 | usage() |
| 440 | sys.exit() |
438 | sys.exit() |
| 441 | 439 | ||
| 442 | for o, a in opts: |
440 | for o, a in opts: |
| 443 | if o in ("-c"): |
441 | if o in ("-c"): |
| 444 | modules = getModules() |
442 | modules = getModules() |
| 445 | 443 | ||
| 446 | for module in modules: |
444 | for module in modules: |
| 447 | print module |
445 | print module |
| 448 | 446 | ||
| 449 | elif o in ("-l", "--list"): |
447 | elif o in ("-l", "--list"): |
| 450 | modules = getModules() |
448 | modules = getModules() |
| 451 | print "Available modules" |
449 | print "Available modules" |
| 452 | print "=================" |
450 | print "=================" |
| 453 | for module in modules: |
451 | for module in modules: |
| 454 | print module |
452 | print module |
| 455 | 453 | ||
| 456 | 454 | ||
| 457 | if os.path.exists(localmoddir): |
455 | if os.path.exists(localmoddir): |
| 458 | print "" |
456 | print "" |
| 459 | 457 | ||
| 460 | modules = getLocalModules() |
458 | modules = getLocalModules() |
| 461 | 459 | ||
| 462 | print "Modules used in this application" |
460 | print "Modules used in this application" |
| 463 | print "================================" |
461 | print "================================" |
| 464 | for module in modules: |
462 | for module in modules: |
| 465 | print module |
463 | print module |
| 466 | 464 | ||
| 467 | elif o in ("-h", "--help"): |
465 | elif o in ("-h", "--help"): |
| 468 | usage() |
466 | usage() |
| 469 | sys.exit() |
467 | sys.exit() |
| 470 | 468 | ||
| 471 | elif o in ("-r", "--regenerate"): |
469 | elif o in ("-r", "--regenerate"): |
| 472 | regenerateModules() |
470 | regenerateModules() |
| 473 | 471 | ||
| 474 | elif o in ("-m", "--modules"): |
472 | elif o in ("-m", "--modules"): |
| 475 | listUsedModules() |
473 | listUsedModules() |
| 476 | 474 | ||
| 477 | elif o in ("-n", "--nodes"): |
475 | elif o in ("-n", "--nodes"): |
| 478 | listUsedNodes() |
476 | listUsedNodes() |
| 479 | 477 | ||
| 480 | elif o in ("--add"): |
478 | elif o in ("--add"): |
| 481 | if len(a) == 0: |
479 | if len(a) == 0: |
| 482 | print "No modulename specified" |
480 | print "No modulename specified" |
| 483 | usage() |
481 | usage() |
| 484 | sys.exit() |
482 | sys.exit() |
| 485 | 483 | ||
| 486 | if a not in getModules(): |
484 | if a not in getModules(): |
| 487 | print a + " is not a recognized module name" |
485 | print a + " is not a recognized module name" |
| 488 | sys.exit() |
486 | sys.exit() |
| 489 | 487 | ||
| 490 | addModule(a) |
488 | addModule(a) |
| 491 | 489 | ||
| 492 | elif o in ("--del"): |
490 | elif o in ("--del"): |
| 493 | if len(a) == 0: |
491 | if len(a) == 0: |
| 494 | print "No modulename specified" |
492 | print "No modulename specified" |
| 495 | usage() |
493 | usage() |
| 496 | sys.exit() |
494 | sys.exit() |
| 497 | 495 | ||
| 498 | if a not in getModules(): |
496 | if a not in getModules(): |
| 499 | print a + " is not a recognized module name" |
497 | print a + " is not a recognized module name" |
| 500 | sys.exit() |
498 | sys.exit() |
| 501 | 499 | ||
| 502 | delModule(a) |
500 | delModule(a) |
| 503 | 501 | ||
| 504 | elif o in ("--new"): |
502 | elif o in ("--new"): |
| 505 | if len(a) == 0: |
503 | if len(a) == 0: |
| 506 | print "No modulename specified" |
504 | print "No modulename specified" |
| 507 | usage() |
505 | usage() |
| 508 | sys.exit() |
506 | sys.exit() |
| 509 | 507 | ||
| 510 | if a in getModules(): |
508 | if a in getModules(): |
| 511 | print a + " already exists" |
509 | print a + " already exists" |
| 512 | sys.exit() |
510 | sys.exit() |
| 513 | 511 | ||
| 514 | newModule(a) |
512 | newModule(a) |
| 515 | 513 | ||
| 516 | else: |
514 | else: |
| 517 | assert False, "unhandled option" |
515 | assert False, "unhandled option" |
| 518 | 516 | ||
| 519 | 517 | ||
| 520 | if __name__ == "__main__": |
518 | if __name__ == "__main__": |
| 521 | main() |
519 | main() |
| 522 | 520 | ||