Rev 847 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 847 | Rev 852 | ||
|---|---|---|---|
| 1 | #!/bin/env python |
1 | #!/bin/env 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 = |
9 | moddir = sys.path[0] + "/../../EmbeddedSoftware/AVR/module" |
| 10 | localmoddir = |
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] != '.': |
15 | if fileName[0] != '.': |
| 16 | modules.append(fileName) |
16 | modules.append(fileName) |
| 17 | 17 | ||
| 18 | return modules |
18 | return 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 modules |
27 | return 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 | 34 | ||
| 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 | return parts[1].strip(" ") |
40 | return parts[1].strip(" ") |
| 41 | 41 | ||
| 42 | return -1; |
42 | return -1; |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | def getFreeModuleId(moduleName): |
45 | def getFreeModuleId(moduleName): |
| 46 | takenIds = [] |
46 | takenIds = [] |
| 47 | 47 | ||
| 48 | for applicationName in os.listdir("../"): |
48 | for applicationName in os.listdir("../"): |
| 49 | 49 | ||
| 50 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
50 | if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"): |
| 51 | takenId = parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc") |
51 | takenId = parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc") |
| 52 | if takenId != -1 and takenId != "<ID>": |
52 | if takenId != -1 and takenId != "<ID>": |
| 53 | takenIds.append(int(takenId, 16)) |
53 | takenIds.append(int(takenId, 16)) |
| 54 | 54 | ||
| 55 | if len(takenIds) == 0: |
55 | if len(takenIds) == 0: |
| 56 | return "0x01" |
56 | return "0x01" |
| 57 | 57 | ||
| 58 | takenIds.sort() |
58 | takenIds.sort() |
| 59 | 59 | ||
| 60 | lastId = 0 |
60 | lastId = 0 |
| 61 | 61 | ||
| 62 | for takenId in takenIds: |
62 | for takenId in takenIds: |
| 63 | if takenId != lastId+1: |
63 | if takenId != lastId+1: |
| 64 | return hex(lastId+1) |
64 | return hex(lastId+1) |
| 65 | lastId = takenId |
65 | lastId = takenId |
| 66 | 66 | ||
| 67 | return hex(lastId+1) |
67 | return hex(lastId+1) |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | def compileMainFile(): |
70 | def compileMainFile(): |
| 71 | print "Compiling new main.c..." |
71 | print "Compiling new main.c..." |
| 72 | main_c_template = open('src/main.c.template', 'r') |
72 | main_c_template = open('src/main.c.template', 'r') |
| 73 | main_c_template_lines = main_c_template.readlines() |
73 | main_c_template_lines = main_c_template.readlines() |
| 74 | main_c_template.close() |
74 | main_c_template.close() |
| 75 | 75 | ||
| 76 | modules = getLocalModules() |
76 | modules = getLocalModules() |
| 77 | 77 | ||
| 78 | main_c = open('src/main.c', 'w') |
78 | main_c = open('src/main.c', 'w') |
| 79 | 79 | ||
| 80 | for main_c_template_line in main_c_template_lines: |
80 | for main_c_template_line in main_c_template_lines: |
| 81 | pos_include = main_c_template_line.find('%INCLUDE') |
81 | pos_include = main_c_template_line.find('%INCLUDE') |
| 82 | pos_init = main_c_template_line.find('%INIT') |
82 | pos_init = main_c_template_line.find('%INIT') |
| 83 | pos_process = main_c_template_line.find('%PROCESS') |
83 | pos_process = main_c_template_line.find('%PROCESS') |
| 84 | pos_list = main_c_template_line.find('%LIST') |
84 | pos_list = main_c_template_line.find('%LIST') |
| 85 | pos_handlemsg = main_c_template_line.find('%HANDLEMSG') |
85 | pos_handlemsg = main_c_template_line.find('%HANDLEMSG') |
| 86 | 86 | ||
| 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();\n") |
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();\n") |
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) + ");\n") |
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(&rxMsg);\n") |
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 | ||
| 109 | print "Creation of main.c complete" |
109 | print "Creation of main.c complete" |
| 110 | 110 | ||
| 111 | def readConfigSection(fileName, sectionName): |
111 | def readConfigSection(fileName, sectionName): |
| 112 | fileInstance = open(fileName, 'r') |
112 | fileInstance = open(fileName, 'r') |
| 113 | lines = fileInstance.readlines() |
113 | lines = fileInstance.readlines() |
| 114 | fileInstance.close() |
114 | fileInstance.close() |
| 115 | 115 | ||
| 116 | sectionLines = [] |
116 | sectionLines = [] |
| 117 | 117 | ||
| 118 | inSection = False |
118 | inSection = False |
| 119 | 119 | ||
| 120 | for line in lines: |
120 | for line in lines: |
| 121 | if not inSection: |
121 | if not inSection: |
| 122 | if line.find("## Section " + sectionName) != -1: |
122 | if line.find("## Section " + sectionName) != -1: |
| 123 | inSection = True |
123 | inSection = True |
| 124 | sectionLines.append(line.strip("\n")) |
124 | sectionLines.append(line.strip("\n")) |
| 125 | else: |
125 | else: |
| 126 | if line.find("## End section " + sectionName) != -1: |
126 | if line.find("## End section " + sectionName) != -1: |
| 127 | inSection = False |
127 | inSection = False |
| 128 | 128 | ||
| 129 | sectionLines.append(line.strip("\n")) |
129 | sectionLines.append(line.strip("\n")) |
| 130 | 130 | ||
| 131 | return sectionLines |
131 | return sectionLines |
| 132 | 132 | ||
| 133 | 133 | ||
| 134 | def updateConfigFile(): |
134 | def updateConfigFile(): |
| 135 | print "Updating config.inc..." |
135 | print "Updating config.inc..." |
| 136 | 136 | ||
| 137 | modules = getLocalModules() |
137 | modules = getLocalModules() |
| 138 | moduleSections = {} |
138 | moduleSections = {} |
| 139 | applicationSection = [] |
139 | applicationSection = [] |
| 140 | 140 | ||
| 141 | if not os.path.exists("config.inc"): |
141 | if not os.path.exists("config.inc"): |
| 142 | applicationSection = readConfigSection("src/config.inc.template", "application") |
142 | applicationSection = readConfigSection("src/config.inc.template", "application") |
| 143 | 143 | ||
| 144 | for moduleName in modules: |
144 | for moduleName in modules: |
| 145 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
145 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
| 146 | else: |
146 | else: |
| 147 | applicationSection = readConfigSection("config.inc", "application") |
147 | applicationSection = readConfigSection("config.inc", "application") |
| 148 | 148 | ||
| 149 | for moduleName in modules: |
149 | for moduleName in modules: |
| 150 | moduleSections[moduleName] = readConfigSection("config.inc", moduleName) |
150 | moduleSections[moduleName] = readConfigSection("config.inc", moduleName) |
| 151 | 151 | ||
| 152 | if len(moduleSections[moduleName]) <= 1: |
152 | if len(moduleSections[moduleName]) <= 1: |
| 153 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
153 | moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName) |
| 154 | 154 | ||
| 155 | timers = 0 |
155 | timers = 0 |
| 156 | 156 | ||
| 157 | for moduleName, moduleSection in moduleSections.iteritems(): |
157 | for moduleName, moduleSection in moduleSections.iteritems(): |
| 158 | c = 0 |
158 | c = 0 |
| 159 | for line in moduleSection: |
159 | for line in moduleSection: |
| 160 | if line.find("<ID>") != -1: |
160 | if line.find("<ID>") != -1: |
| 161 | line = line.replace("<ID>", getFreeModuleId(moduleName)) |
161 | line = line.replace("<ID>", getFreeModuleId(moduleName)) |
| 162 | elif line.find("<TIMER>") != -1: |
162 | elif line.find("<TIMER>") != -1: |
| 163 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
163 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
| 164 | timers += 1 |
164 | timers += 1 |
| 165 | 165 | ||
| 166 | moduleSection[c] = line; |
166 | moduleSection[c] = line; |
| 167 | c += 1 |
167 | c += 1 |
| 168 | 168 | ||
| 169 | c = 0 |
169 | c = 0 |
| 170 | for line in applicationSection: |
170 | for line in applicationSection: |
| 171 | if line.find("<TIMER>") != -1: |
171 | if line.find("<TIMER>") != -1: |
| 172 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
172 | line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */" |
| 173 | timers += 1 |
173 | timers += 1 |
| 174 | elif line.find("TIMER_NUM_TIMERS=") != -1: |
174 | elif line.find("TIMER_NUM_TIMERS=") != -1: |
| 175 | line = "TIMER_NUM_TIMERS=" + hex(timers) |
175 | line = "TIMER_NUM_TIMERS=" + hex(timers) |
| 176 | elif line.find("NUMBER_OF_MODULES=") != -1: |
176 | elif line.find("NUMBER_OF_MODULES=") != -1: |
| 177 | line = "NUMBER_OF_MODULES=" + hex(len(modules)) |
177 | line = "NUMBER_OF_MODULES=" + hex(len(modules)) |
| 178 | 178 | ||
| 179 | applicationSection[c] = line; |
179 | applicationSection[c] = line; |
| 180 | c += 1 |
180 | c += 1 |
| 181 | 181 | ||
| 182 | config_inc = open('config.inc', 'w') |
182 | config_inc = open('config.inc', 'w') |
| 183 | 183 | ||
| 184 | for line in applicationSection: |
184 | for line in applicationSection: |
| 185 | config_inc.write(line + "\n") |
185 | config_inc.write(line + "\n") |
| 186 | 186 | ||
| 187 | for moduleName, moduleSection in moduleSections.iteritems(): |
187 | for moduleName, moduleSection in moduleSections.iteritems(): |
| 188 | for line in moduleSection: |
188 | for line in moduleSection: |
| 189 | config_inc.write(line + "\n") |
189 | config_inc.write(line + "\n") |
| 190 | 190 | ||
| 191 | config_inc.close() |
191 | config_inc.close() |
| 192 | 192 | ||
| 193 | print "Update of config.inc complete" |
193 | print "Update of config.inc complete" |
| 194 | 194 | ||
| 195 | 195 | ||
| 196 | def compileSourcesFile(): |
196 | def compileSourcesFile(): |
| 197 | print "Compiling sources.inc..." |
197 | print "Compiling sources.inc..." |
| 198 | 198 | ||
| 199 | uniqueSet = [] |
199 | uniqueSet = [] |
| 200 | 200 | ||
| 201 | sources_list_template = open('src/sources.list.template', 'r') |
201 | sources_list_template = open('src/sources.list.template', 'r') |
| 202 | sources_list_template_lines = sources_list_template.readlines() |
202 | sources_list_template_lines = sources_list_template.readlines() |
| 203 | sources_list_template.close() |
203 | sources_list_template.close() |
| 204 | 204 | ||
| 205 | for sources_list_template_line in sources_list_template_lines: |
205 | for sources_list_template_line in sources_list_template_lines: |
| 206 | line = sources_list_template_line.strip("\n").strip(" ") |
206 | line = sources_list_template_line.strip("\n").strip(" ") |
| 207 | if len(line) > 0: |
207 | if len(line) > 0: |
| 208 | if line[0] != '#': |
208 | if line[0] != '#': |
| 209 | uniqueSet.append(line) |
209 | uniqueSet.append(line) |
| 210 | 210 | ||
| 211 | modules = getLocalModules() |
211 | modules = getLocalModules() |
| 212 | 212 | ||
| 213 | for moduleName in modules: |
213 | for moduleName in modules: |
| 214 | sources_list = open(localmoddir + "/" + moduleName + "/sources.list", 'r') |
214 | sources_list = open(localmoddir + "/" + moduleName + "/sources.list", 'r') |
| 215 | sources_list_lines = sources_list.readlines() |
215 | sources_list_lines = sources_list.readlines() |
| 216 | sources_list.close() |
216 | sources_list.close() |
| 217 | 217 | ||
| 218 | for sources_list_line in sources_list_lines: |
218 | for sources_list_line in sources_list_lines: |
| 219 | line = sources_list_line.strip("\n").strip(" ") |
219 | line = sources_list_line.strip("\n").strip(" ") |
| 220 | if len(line) > 0: |
220 | if len(line) > 0: |
| 221 | if line[0] != '#': |
221 | if line[0] != '#': |
| 222 | uniqueSet.append(line) |
222 | uniqueSet.append(line) |
| 223 | 223 | ||
| 224 | 224 | ||
| 225 | sourcesString = "SOURCES = " |
225 | sourcesString = "SOURCES = " |
| 226 | 226 | ||
| 227 | #FIXME: Make uniqueSet actually unique |
227 | #FIXME: Make uniqueSet actually unique |
| 228 | 228 | ||
| 229 | for line in uniqueSet: |
229 | for line in uniqueSet: |
| 230 | sourcesString += line + " " |
230 | sourcesString += line + " " |
| 231 | 231 | ||
| 232 | sources_inc = open('sources.inc', 'w') |
232 | sources_inc = open('sources.inc', 'w') |
| 233 | sources_inc.write(sourcesString.strip(" ") + "\n") |
233 | sources_inc.write(sourcesString.strip(" ") + "\n") |
| 234 | sources_inc.close() |
234 | sources_inc.close() |
| 235 | 235 | ||
| 236 | print "Creation of sources.inc complete" |
236 | print "Creation of sources.inc complete" |
| 237 | 237 | ||
| 238 | 238 | ||
| 239 | def regenerateModules(): |
239 | def regenerateModules(): |
| 240 | print "Regenerating modules..." |
240 | print "Regenerating modules..." |
| 241 | print "" |
241 | print "" |
| 242 | compileSourcesFile() |
242 | compileSourcesFile() |
| 243 | print "" |
243 | print "" |
| 244 | compileMainFile() |
244 | compileMainFile() |
| 245 | print "" |
245 | print "" |
| 246 | updateConfigFile() |
246 | updateConfigFile() |
| 247 | print "" |
247 | print "" |
| 248 | print "Regenerating modules complete" |
248 | print "Regenerating modules complete" |
| 249 | print "" |
249 | print "" |
| 250 | 250 | ||
| 251 | 251 | ||
| 252 | def addModule(moduleName): |
252 | def addModule(moduleName): |
| 253 | print "Trying to add module " + moduleName |
253 | print "Trying to add module " + moduleName |
| 254 | 254 | ||
| 255 | try: |
255 | try: |
| 256 | os.symlink( |
256 | os.symlink(moddir + "/" + moduleName, localmoddir + "/" + moduleName) |
| 257 | print "Added module successfully" |
257 | print "Added module successfully" |
| 258 | except OSError, (errno, strerror): |
258 | except OSError, (errno, strerror): |
| 259 | if errno == 17: |
259 | if errno == 17: |
| 260 | print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking" |
260 | print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking" |
| 261 | else: |
261 | else: |
| 262 | raise |
262 | raise |
| 263 | 263 | ||
| 264 | print "" |
264 | print "" |
| 265 | 265 | ||
| 266 | regenerateModules() |
266 | regenerateModules() |
| 267 | 267 | ||
| 268 | 268 | ||
| 269 | def delModule(moduleName): |
269 | def delModule(moduleName): |
| 270 | print "Trying to remove module " + moduleName |
270 | print "Trying to remove module " + moduleName |
| 271 | 271 | ||
| 272 | try: |
272 | try: |
| 273 | os.unlink(localmoddir + "/" + moduleName) |
273 | os.unlink(localmoddir + "/" + moduleName) |
| 274 | print "Removed module successfully" |
274 | print "Removed module successfully" |
| 275 | except OSError, (errno, strerror): |
275 | except OSError, (errno, strerror): |
| 276 | if errno == 2: |
276 | if errno == 2: |
| 277 | print "No such " + moduleName + " present in the modules directory, not unlinking" |
277 | print "No such " + moduleName + " present in the modules directory, not unlinking" |
| 278 | else: |
278 | else: |
| 279 | raise |
279 | raise |
| 280 | 280 | ||
| 281 | print "" |
281 | print "" |
| 282 | 282 | ||
| 283 | regenerateModules() |
283 | regenerateModules() |
| 284 | 284 | ||
| - | 285 | def createFile(moduleName, templateFileName, moduleFileName): |
|
| - | 286 | print "Creating " + moduleName + "/" + templateFileName + "..." |
|
| - | 287 | template_file = open(moddir + "/template/" + templateFileName, 'r') |
|
| - | 288 | lines = template_file.readlines() |
|
| - | 289 | template_file.close() |
|
| - | 290 | ||
| - | 291 | module_file = open(moddir + "/" + moduleName + "/" + moduleFileName, 'w') |
|
| - | 292 | ||
| - | 293 | for line in lines: |
|
| - | 294 | line = line.replace("<template>", moduleName) |
|
| - | 295 | line = line.replace("<TEMPLATE>", moduleName.upper()) |
|
| - | 296 | ||
| - | 297 | module_file.write(line) |
|
| - | 298 | ||
| - | 299 | module_file.close() |
|
| - | 300 | ||
| - | 301 | def newModule(moduleName): |
|
| - | 302 | print "Creating " + moddir + "/" + moduleName + " directory..." |
|
| - | 303 | os.mkdir(moddir + "/" + moduleName + "/") |
|
| - | 304 | ||
| - | 305 | createFile(moduleName, "config.inc.template", "config.inc.template") |
|
| - | 306 | createFile(moduleName, "protocol.h", "protocol.h") |
|
| - | 307 | createFile(moduleName, "sources.list", "sources.list") |
|
| - | 308 | createFile(moduleName, "template.h", moduleName + ".h") |
|
| - | 309 | createFile(moduleName, "template.c", moduleName + ".c") |
|
| 285 | 310 | ||
| 286 | def usage(): |
311 | def usage(): |
| 287 | print "Syntax: ./ModuleManager [options]" |
312 | print "Syntax: ./ModuleManager [options]" |
| 288 | print "Options:" |
313 | print "Options:" |
| 289 | print " --help Print this help" |
314 | print " --help Print this help" |
| 290 | print " --regenerate Regenarate modules and files" |
315 | print " --regenerate Regenarate modules and files" |
| 291 | print " --list List avalible and installed modules" |
316 | print " --list List avalible and installed modules" |
| 292 | print " --add=<module name> Adds a module to the application" |
317 | print " --add=<module name> Adds a module to the application" |
| 293 | print " --del=<module name> Removes a module from the application" |
318 | print " --del=<module name> Removes a module from the application" |
| - | 319 | print " --new=<module name> Creates a new module from the module template" |
|
| 294 | print "" |
320 | print "" |
| 295 | 321 | ||
| 296 | 322 | ||
| 297 | def main(): |
323 | def main(): |
| 298 | try: |
324 | try: |
| 299 | opts, args = getopt.getopt(sys.argv[1:], "hlr", ["help", "list", "regenerate", "add=", "del="]) |
325 | opts, args = getopt.getopt(sys.argv[1:], "hlr", ["help", "list", "regenerate", "add=", "del=", "new="]) |
| 300 | except getopt.GetoptError, err: |
326 | except getopt.GetoptError, err: |
| 301 | # print help information and exit: |
327 | # print help information and exit: |
| 302 | print str(err) # will print something like "option -a not recognized" |
328 | print str(err) # will print something like "option -a not recognized" |
| 303 | usage() |
329 | usage() |
| 304 | sys.exit(2) |
330 | sys.exit(2) |
| 305 | 331 | ||
| 306 | if len(sys.argv) == 1: |
332 | if len(sys.argv) == 1: |
| 307 | usage() |
333 | usage() |
| 308 | sys.exit() |
334 | sys.exit() |
| 309 | 335 | ||
| 310 | for o, a in opts: |
336 | for o, a in opts: |
| 311 | if o in ("-l", "--list"): |
337 | if o in ("-l", "--list"): |
| 312 | modules = getModules() |
338 | modules = getModules() |
| 313 | 339 | ||
| 314 | print "Available modules" |
340 | print "Available modules" |
| 315 | print "=================" |
341 | print "=================" |
| 316 | for module in modules: |
342 | for module in modules: |
| 317 | print module |
343 | print module |
| 318 | 344 | ||
| 319 | print "" |
345 | print "" |
| 320 | 346 | ||
| 321 | modules = getLocalModules() |
347 | modules = getLocalModules() |
| 322 | 348 | ||
| 323 | print "Modules used in this application" |
349 | print "Modules used in this application" |
| 324 | print "================================" |
350 | print "================================" |
| 325 | for module in modules: |
351 | for module in modules: |
| 326 | print module |
352 | print module |
| 327 | 353 | ||
| 328 | elif o in ("-h", "--help"): |
354 | elif o in ("-h", "--help"): |
| 329 | usage() |
355 | usage() |
| 330 | sys.exit() |
356 | sys.exit() |
| 331 | 357 | ||
| 332 | elif o in ("-r", "--regenerate"): |
358 | elif o in ("-r", "--regenerate"): |
| 333 | regenerateModules() |
359 | regenerateModules() |
| 334 | 360 | ||
| 335 | elif o in ("--add"): |
361 | elif o in ("--add"): |
| 336 | if len(a) == 0: |
362 | if len(a) == 0: |
| - | 363 | print "No modulename specified" |
|
| - | 364 | usage() |
|
| - | 365 | sys.exit() |
|
| - | 366 | ||
| - | 367 | if a not in getModules(): |
|
| - | 368 | print a + " is not a recognized module name" |
|
| - | 369 | sys.exit() |
|
| - | 370 | ||
| - | 371 | addModule(a) |
|
| - | 372 | ||
| - | 373 | elif o in ("--del"): |
|
| - | 374 | if len(a) == 0: |
|
| 337 | print "No modulename specified" |
375 | print "No modulename specified" |
| 338 | usage() |
376 | usage() |
| 339 | sys.exit() |
377 | sys.exit() |
| 340 | 378 | ||
| 341 | if a not in getModules(): |
379 | if a not in getModules(): |
| 342 | print a + " is not a recognized module name" |
380 | print a + " is not a recognized module name" |
| 343 | sys.exit() |
381 | sys.exit() |
| 344 | 382 | ||
| 345 |
|
383 | delModule(a) |
| 346 | 384 | ||
| 347 | elif o in ("-- |
385 | elif o in ("--new"): |
| 348 | if len(a) == 0: |
386 | if len(a) == 0: |
| 349 | print "No modulename specified" |
387 | print "No modulename specified" |
| 350 | usage() |
388 | usage() |
| 351 | sys.exit() |
389 | sys.exit() |
| 352 | 390 | ||
| 353 | if a |
391 | if a in getModules(): |
| 354 | print a + " |
392 | print a + " already exists" |
| 355 | sys.exit() |
393 | sys.exit() |
| 356 | 394 | ||
| 357 |
|
395 | newModule(a) |
| 358 | 396 | ||
| 359 | else: |
397 | else: |
| 360 | assert False, "unhandled option" |
398 | assert False, "unhandled option" |
| 361 | 399 | ||
| 362 | 400 | ||
| 363 | if __name__ == "__main__": |
401 | if __name__ == "__main__": |
| 364 | main() |
402 | main() |
| 365 | 403 | ||