Rev 828 | Rev 839 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 828 | Rev 836 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | 4 | ||
| 5 | import os |
5 | import os |
| 6 | import sys |
6 | import sys |
| 7 | import getopt |
7 | import getopt |
| 8 | 8 | ||
| 9 | moddir = '../../module' |
9 | moddir = '../../module' # FIXME: This is ugly |
| 10 | localmoddir = 'modules' |
10 | localmoddir = 'modules' # FIXME: This is ugly |
| 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] != '.': |
15 | if fileName[0] != '.': |
| Line 87... | Line 87... | ||
| 87 | if pos_include != -1: |
87 | if pos_include != -1: |
| 88 | for moduleName in modules: |
88 | for moduleName in modules: |
| 89 | main_c.write(main_c_template_line[:pos_include] + "#include \"../modules/" + moduleName + "/" + moduleName + ".h\"\n") |
89 | main_c.write(main_c_template_line[:pos_include] + "#include \"../modules/" + moduleName + "/" + moduleName + ".h\"\n") |
| 90 | elif pos_init != -1: |
90 | elif pos_init != -1: |
| 91 | for moduleName in modules: |
91 | for moduleName in modules: |
| 92 | main_c.write(main_c_template_line[:pos_init] + moduleName + "_Init( |
92 | main_c.write(main_c_template_line[:pos_init] + moduleName + "_Init(\n") |
| 93 | elif pos_process != -1: |
93 | elif pos_process != -1: |
| 94 | for moduleName in modules: |
94 | for moduleName in modules: |
| 95 | main_c.write(main_c_template_line[:pos_process] + moduleName + "_Process( |
95 | main_c.write(main_c_template_line[:pos_process] + moduleName + "_Process(\n") |
| 96 | elif pos_list != -1: |
96 | elif pos_list != -1: |
| 97 | count = 1 |
97 | count = 1 |
| 98 | for moduleName in modules: |
98 | for moduleName in modules: |
| 99 | main_c.write(main_c_template_line[:pos_list] + moduleName + "_List(" + str(count) + " |
99 | main_c.write(main_c_template_line[:pos_list] + moduleName + "_List(" + str(count) + "\n") |
| 100 | count += 1 |
100 | count += 1 |
| 101 | elif pos_handlemsg != -1: |
101 | elif pos_handlemsg != -1: |
| 102 | for moduleName in modules: |
102 | for moduleName in modules: |
| 103 | main_c.write(main_c_template_line[:pos_handlemsg] + moduleName + "_HandleMessage(& |
103 | main_c.write(main_c_template_line[:pos_handlemsg] + moduleName + "_HandleMessage(&rxMsg\n") |
| 104 | else: |
104 | else: |
| 105 | main_c.write(main_c_template_line) |
105 | main_c.write(main_c_template_line) |
| 106 | 106 | ||
| 107 | main_c.close() |
107 | main_c.close() |
| 108 | 108 | ||
| Line 231... | Line 231... | ||
| 231 | print "Creation of sources.inc complete" |
231 | print "Creation of sources.inc complete" |
| 232 | 232 | ||
| 233 | 233 | ||
| 234 | def regenerateModules(): |
234 | def regenerateModules(): |
| 235 | print "Regenerating modules..." |
235 | print "Regenerating modules..." |
| - | 236 | print "" |
|
| 236 | compileSourcesFile() |
237 | compileSourcesFile() |
| - | 238 | print "" |
|
| 237 | compileMainFile() |
239 | compileMainFile() |
| - | 240 | print "" |
|
| 238 | updateConfigFile() |
241 | updateConfigFile() |
| - | 242 | print "" |
|
| 239 | print "Regenerating modules complete" |
243 | print "Regenerating modules complete" |
| - | 244 | print "" |
|
| 240 | 245 | ||
| 241 | 246 | ||
| 242 | def addModule(moduleName): |
247 | def addModule(moduleName): |
| 243 | print "Trying to add module " + moduleName |
248 | print "Trying to add module " + moduleName |
| 244 | 249 | ||
| Line 246... | Line 251... | ||
| 246 | os.symlink("../" + moddir + "/" + moduleName, localmoddir + "/" + moduleName) |
251 | os.symlink("../" + moddir + "/" + moduleName, localmoddir + "/" + moduleName) |
| 247 | print "Added module successfully" |
252 | print "Added module successfully" |
| 248 | except OSError, (errno, strerror): |
253 | except OSError, (errno, strerror): |
| 249 | if errno == 17: |
254 | if errno == 17: |
| 250 | print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking" |
255 | print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking" |
| 251 | else: |
256 | else: |
| 252 | raise |
257 | raise |
| 253 | 258 | ||
| 254 | print "" |
259 | print "" |
| 255 | 260 | ||
| 256 | regenerateModules() |
261 | regenerateModules() |
| 257 | 262 | ||
| 258 | 263 | ||
| 259 | def delModule(moduleName): |
264 | def delModule(moduleName): |
| 260 | print "Trying to remove module " + moduleName |
265 | print "Trying to remove module " + moduleName |
| 261 | 266 | ||
| 262 | try: |
267 | try: |
| 263 | os.unlink(localmoddir + "/" + moduleName) |
268 | os.unlink(localmoddir + "/" + moduleName) |
| Line 265... | Line 270... | ||
| 265 | except OSError, (errno, strerror): |
270 | except OSError, (errno, strerror): |
| 266 | if errno == 2: |
271 | if errno == 2: |
| 267 | print "No such " + moduleName + " present in the modules directory, not unlinking" |
272 | print "No such " + moduleName + " present in the modules directory, not unlinking" |
| 268 | else: |
273 | else: |
| 269 | raise |
274 | raise |
| 270 | 275 | ||
| 271 | print "" |
276 | print "" |
| 272 | 277 | ||
| 273 | regenerateModules() |
278 | regenerateModules() |
| 274 | 279 | ||
| 275 | 280 | ||
| 276 | def usage(): |
281 | def usage(): |
| - | 282 | print "Syntax: ./ModuleManager [options]" |
|
| 277 | print "Options:" |
283 | print "Options:" |
| - | 284 | print " --help Print this help" |
|
| 278 | print " |
285 | print " --regenerate Regenarate modules and files" |
| 279 | print " |
286 | print " --list List avalible and installed modules" |
| 280 | print " |
287 | print " --add=<module name> Adds a module to the application" |
| 281 | print " |
288 | print " --del=<module name> Removes a module from the application" |
| 282 | print "" |
289 | print "" |
| 283 | 290 | ||
| 284 | 291 | ||
| 285 | def main(): |
292 | def main(): |
| 286 | try: |
293 | try: |
| 287 | opts, args = getopt.getopt(sys.argv[1:], " |
294 | opts, args = getopt.getopt(sys.argv[1:], "hlr", ["help", "list", "regenerate", "add=", "del="]) |
| 288 | except getopt.GetoptError, err: |
295 | except getopt.GetoptError, err: |
| 289 | # print help information and exit: |
296 | # print help information and exit: |
| 290 | print str(err) # will print something like "option -a not recognized" |
297 | print str(err) # will print something like "option -a not recognized" |
| 291 | usage() |
298 | usage() |
| 292 | sys.exit(2) |
299 | sys.exit(2) |
| Line 295... | Line 302... | ||
| 295 | usage() |
302 | usage() |
| 296 | sys.exit() |
303 | sys.exit() |
| 297 | 304 | ||
| 298 | for o, a in opts: |
305 | for o, a in opts: |
| 299 | if o in ("-l", "--list"): |
306 | if o in ("-l", "--list"): |
| 300 | 307 | modules = getModules() |
|
| - | 308 | ||
| - | 309 | print "Available modules" |
|
| - | 310 | print "=================" |
|
| - | 311 | for module in modules: |
|
| - | 312 | print module |
|
| - | 313 | ||
| - | 314 | print "" |
|
| - | 315 | ||
| - | 316 | modules = getLocalModules() |
|
| - | 317 | ||
| - | 318 | print "Modules used in this application" |
|
| - | 319 | print "================================" |
|
| - | 320 | for module in modules: |
|
| - | 321 | print module |
|
| 301 | 322 | ||
| 302 | elif o in ("-h", "--help"): |
323 | elif o in ("-h", "--help"): |
| 303 | usage() |
324 | usage() |
| 304 | sys.exit() |
325 | sys.exit() |
| 305 | 326 | ||