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