Subversion Repositories HomeAutomation

Rev

Rev 1126 | Rev 1259 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1126 Rev 1258
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 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
	pcints = 0
156
	pcints = 0
157
		
157
		
158
	for moduleName, moduleSection in moduleSections.iteritems():
158
	for moduleName, moduleSection in moduleSections.iteritems():
159
		c = 0
159
		c = 0
160
		for line in moduleSection:
160
		for line in moduleSection:
-
 
161
			if line[0] != '#':
161
			if line.find("<ID>") != -1:
162
				if line.find("<ID>") != -1:
162
				line = line.replace("<ID>", getFreeModuleId(moduleName))
163
					line = line.replace("<ID>", getFreeModuleId(moduleName))
163
			elif line.find("<TIMER>") != -1:
164
				elif line.find("<TIMER>") != -1:
164
				line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */"
165
					line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */"
165
				timers += 1
166
					timers += 1
166
			elif line.find("<PCINT>") != -1:
167
				elif line.find("<PCINT>") != -1:
167
				line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */"
168
					line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */"
168
				pcints += 1
169
					pcints += 1
169
	
170
	
170
			moduleSection[c] = line;
171
			moduleSection[c] = line;
171
			c += 1
172
			c += 1
172
	
173
	
173
	c = 0
174
	c = 0
174
	for line in applicationSection:
175
	for line in applicationSection:
-
 
176
		if line[0] != '#':
175
		if line.find("<TIMER>") != -1:
177
			if line.find("<TIMER>") != -1:
176
			line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */"
178
				line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */"
177
			timers += 1
179
				timers += 1
178
		elif line.find("TIMER_NUM_TIMERS=") != -1:
180
			elif line.find("TIMER_NUM_TIMERS=") != -1:
179
			line = "TIMER_NUM_TIMERS=" + hex(timers)
181
				line = "TIMER_NUM_TIMERS=" + hex(timers)
180
		elif line.find("NUMBER_OF_MODULES=") != -1:
182
			elif line.find("NUMBER_OF_MODULES=") != -1:
181
			line = "NUMBER_OF_MODULES=" + hex(len(modules))
183
				line = "NUMBER_OF_MODULES=" + hex(len(modules))
182
		elif line.find("<PCINT>") != -1:
184
			elif line.find("<PCINT>") != -1:
183
			line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */"
185
				line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */"
184
			pcints += 1
186
				pcints += 1
185
		elif line.find("PCINT_NUM_PCINTS=") != -1:
187
			elif line.find("PCINT_NUM_PCINTS=") != -1:
186
			line = "PCINT_NUM_PCINTS=" + hex(pcints)
188
				line = "PCINT_NUM_PCINTS=" + hex(pcints)
187
		applicationSection[c] = line;
189
		applicationSection[c] = line;
188
		c += 1
190
		c += 1
189
		
191
		
190
	config_inc = open('config.inc', 'w')
192
	config_inc = open('config.inc', 'w')
191
	
193
	
192
	for line in applicationSection:
194
	for line in applicationSection:
193
		config_inc.write(line + "\n")
195
		config_inc.write(line + "\n")
194
		
196
		
195
	for moduleName, moduleSection in moduleSections.iteritems():
197
	for moduleName, moduleSection in moduleSections.iteritems():
196
		for line in moduleSection:
198
		for line in moduleSection:
197
			config_inc.write(line + "\n")
199
			config_inc.write(line + "\n")
198
		
200
		
199
	config_inc.close()
201
	config_inc.close()
200
	
202
	
201
	print "Update of config.inc complete"
203
	print "Update of config.inc complete"
202
 
204
 
203
 
205
 
204
def compileSourcesFile():
206
def compileSourcesFile():
205
	print "Compiling sources.inc..."
207
	print "Compiling sources.inc..."
206
	
208
	
207
	uniqueSet = []
209
	uniqueSet = []
208
	
210
	
209
	sources_list_template = open('src/sources.list.template', 'r')
211
	sources_list_template = open('src/sources.list.template', 'r')
210
	sources_list_template_lines = sources_list_template.readlines()
212
	sources_list_template_lines = sources_list_template.readlines()
211
	sources_list_template.close()
213
	sources_list_template.close()
212
	
214
	
213
	for sources_list_template_line in sources_list_template_lines:
215
	for sources_list_template_line in sources_list_template_lines:
214
		line = sources_list_template_line.strip("\n").strip(" ")
216
		line = sources_list_template_line.strip("\n").strip(" ")
215
		if len(line) > 0:
217
		if len(line) > 0:
216
			if line[0] != '#':
218
			if line[0] != '#':
217
				uniqueSet.append(line)
219
				uniqueSet.append(line)
218
		
220
		
219
	modules = getLocalModules()
221
	modules = getLocalModules()
220
	
222
	
221
	for moduleName in modules:
223
	for moduleName in modules:
222
		sources_list = open(localmoddir + "/" + moduleName + "/sources.list", 'r')
224
		sources_list = open(localmoddir + "/" + moduleName + "/sources.list", 'r')
223
		sources_list_lines = sources_list.readlines()
225
		sources_list_lines = sources_list.readlines()
224
		sources_list.close()
226
		sources_list.close()
225
	
227
	
226
		for sources_list_line in sources_list_lines:
228
		for sources_list_line in sources_list_lines:
227
			line = sources_list_line.strip("\n").strip(" ")
229
			line = sources_list_line.strip("\n").strip(" ")
228
			if len(line) > 0:
230
			if len(line) > 0:
229
				if line[0] != '#':
231
				if line[0] != '#':
230
					uniqueSet.append(line)
232
					uniqueSet.append(line)
231
			
233
			
232
	
234
	
233
	sourcesString = "SOURCES = "
235
	sourcesString = "SOURCES = "
234
	
236
	
235
	#FIXME: Make uniqueSet actually unique
237
	#FIXME: Make uniqueSet actually unique
236
	
238
	
237
	for line in uniqueSet:
239
	for line in uniqueSet:
238
		sourcesString += line + " "
240
		sourcesString += line + " "
239
		
241
		
240
	sources_inc = open('sources.inc', 'w')
242
	sources_inc = open('sources.inc', 'w')
241
	sources_inc.write(sourcesString.strip(" ") + "\n")
243
	sources_inc.write(sourcesString.strip(" ") + "\n")
242
	sources_inc.close()
244
	sources_inc.close()
243
	
245
	
244
	print "Creation of sources.inc complete"
246
	print "Creation of sources.inc complete"
245
 
247
 
246
 
248
 
247
def regenerateModules():
249
def regenerateModules():
248
	print "Regenerating modules..."
250
	print "Regenerating modules..."
249
	print ""
251
	print ""
250
	compileSourcesFile()
252
	compileSourcesFile()
251
	print ""
253
	print ""
252
	compileMainFile()
254
	compileMainFile()
253
	print ""
255
	print ""
254
	updateConfigFile()
256
	updateConfigFile()
255
	print ""
257
	print ""
256
	print "Regenerating modules complete"
258
	print "Regenerating modules complete"
257
	print ""
259
	print ""
258
 
260
 
259
 
261
 
260
def addModule(moduleName):
262
def addModule(moduleName):
261
	print "Trying to add module " + moduleName
263
	print "Trying to add module " + moduleName
262
	
264
	
263
	try:
265
	try:
264
		os.symlink(moddir + "/" + moduleName, localmoddir + "/" + moduleName)
266
		os.symlink(moddir + "/" + moduleName, localmoddir + "/" + moduleName)
265
		print "Added module successfully"
267
		print "Added module successfully"
266
	except OSError, (errno, strerror):
268
	except OSError, (errno, strerror):
267
		if errno == 17:
269
		if errno == 17:
268
			print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking"
270
			print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking"
269
		else:
271
		else:
270
			raise
272
			raise
271
	
273
	
272
	print ""
274
	print ""
273
	
275
	
274
	regenerateModules()
276
	regenerateModules()
275
 
277
 
276
 
278
 
277
def delModule(moduleName):
279
def delModule(moduleName):
278
	print "Trying to remove module " + moduleName
280
	print "Trying to remove module " + moduleName
279
	
281
	
280
	try:
282
	try:
281
		os.unlink(localmoddir + "/" + moduleName)
283
		os.unlink(localmoddir + "/" + moduleName)
282
		print "Removed module successfully"
284
		print "Removed module successfully"
283
	except OSError, (errno, strerror):
285
	except OSError, (errno, strerror):
284
		if errno == 2:
286
		if errno == 2:
285
			print "No such " + moduleName + " present in the modules directory, not unlinking"
287
			print "No such " + moduleName + " present in the modules directory, not unlinking"
286
		else:
288
		else:
287
			raise
289
			raise
288
	
290
	
289
	print ""
291
	print ""
290
	
292
	
291
	regenerateModules()
293
	regenerateModules()
292
 
294
 
293
def createFile(moduleName, templateFileName, moduleFileName):
295
def createFile(moduleName, templateFileName, moduleFileName):
294
	print "Creating " + moduleName + "/" + templateFileName + "..."
296
	print "Creating " + moduleName + "/" + templateFileName + "..."
295
	template_file = open(moddir + "/template/" + templateFileName, 'r')
297
	template_file = open(moddir + "/template/" + templateFileName, 'r')
296
	lines = template_file.readlines()
298
	lines = template_file.readlines()
297
	template_file.close()
299
	template_file.close()
298
 
300
 
299
	module_file = open(moddir + "/" + moduleName + "/" + moduleFileName, 'w')
301
	module_file = open(moddir + "/" + moduleName + "/" + moduleFileName, 'w')
300
	
302
	
301
	for line in lines:
303
	for line in lines:
302
		line = line.replace("<template>", moduleName)
304
		line = line.replace("<template>", moduleName)
303
		line = line.replace("<TEMPLATE>", moduleName.upper())
305
		line = line.replace("<TEMPLATE>", moduleName.upper())
304
 
306
 
305
		module_file.write(line)
307
		module_file.write(line)
306
 
308
 
307
	module_file.close()
309
	module_file.close()
308
	
310
	
309
def newModule(moduleName):
311
def newModule(moduleName):
310
	print "Creating " + moddir + "/" + moduleName + " directory..."
312
	print "Creating " + moddir + "/" + moduleName + " directory..."
311
	os.mkdir(moddir + "/" + moduleName + "/")
313
	os.mkdir(moddir + "/" + moduleName + "/")
312
 
314
 
313
	createFile(moduleName, "config.inc.template", "config.inc.template")
315
	createFile(moduleName, "config.inc.template", "config.inc.template")
314
	createFile(moduleName, "sources.list", "sources.list")
316
	createFile(moduleName, "sources.list", "sources.list")
315
	createFile(moduleName, "template.h", moduleName + ".h")
317
	createFile(moduleName, "template.h", moduleName + ".h")
316
	createFile(moduleName, "template.c", moduleName + ".c")
318
	createFile(moduleName, "template.c", moduleName + ".c")
317
	createFile(moduleName, "template_eeprom.h", moduleName + "_eeprom.h")
319
	createFile(moduleName, "template_eeprom.h", moduleName + "_eeprom.h")
318
 
320
 
319
def usage():
321
def usage():
320
	print "Syntax: ./ModuleManager [options]"
322
	print "Syntax: ./ModuleManager [options]"
321
	print "Options:"
323
	print "Options:"
322
	print "  --help               Print this help"
324
	print "  --help               Print this help"
323
	print "  --regenerate         Regenarate modules and files"
325
	print "  --regenerate         Regenarate modules and files"
324
	print "  --list               List avalible and installed modules"
326
	print "  --list               List avalible and installed modules"
325
	print "  --add=<module name>  Adds a module to the application"
327
	print "  --add=<module name>  Adds a module to the application"
326
	print "  --del=<module name>  Removes a module from the application"
328
	print "  --del=<module name>  Removes a module from the application"
327
	print "  --new=<module name>  Creates a new module from the module template"
329
	print "  --new=<module name>  Creates a new module from the module template"
328
	print ""
330
	print ""
329
 
331
 
330
 
332
 
331
def main():
333
def main():
332
	try:
334
	try:
333
		opts, args = getopt.getopt(sys.argv[1:], "hlrc", ["help", "list", "regenerate", "add=", "del=", "new="])
335
		opts, args = getopt.getopt(sys.argv[1:], "hlrc", ["help", "list", "regenerate", "add=", "del=", "new="])
334
	except getopt.GetoptError, err:
336
	except getopt.GetoptError, err:
335
		# print help information and exit:
337
		# print help information and exit:
336
		print str(err) # will print something like "option -a not recognized"
338
		print str(err) # will print something like "option -a not recognized"
337
		usage()
339
		usage()
338
		sys.exit(2)
340
		sys.exit(2)
339
	
341
	
340
	if len(sys.argv) == 1:
342
	if len(sys.argv) == 1:
341
		usage()
343
		usage()
342
		sys.exit()
344
		sys.exit()
343
	
345
	
344
	for o, a in opts:
346
	for o, a in opts:
345
		if o in ("-c"):
347
		if o in ("-c"):
346
			modules = getModules()
348
			modules = getModules()
347
			
349
			
348
			for module in modules:
350
			for module in modules:
349
				print module
351
				print module
350
 
352
 
351
		elif o in ("-l", "--list"):
353
		elif o in ("-l", "--list"):
352
			modules = getModules()
354
			modules = getModules()
353
			
355
			
354
			print "Available modules"
356
			print "Available modules"
355
			print "================="
357
			print "================="
356
			for module in modules:
358
			for module in modules:
357
				print module
359
				print module
358
			
360
			
359
 
361
 
360
			if os.path.exists(localmoddir):
362
			if os.path.exists(localmoddir):
361
				print ""
363
				print ""
362
			
364
			
363
				modules = getLocalModules()
365
				modules = getLocalModules()
364
			
366
			
365
				print "Modules used in this application"
367
				print "Modules used in this application"
366
				print "================================"
368
				print "================================"
367
				for module in modules:
369
				for module in modules:
368
					print module
370
					print module
369
			
371
			
370
		elif o in ("-h", "--help"):
372
		elif o in ("-h", "--help"):
371
			usage()
373
			usage()
372
			sys.exit()
374
			sys.exit()
373
			
375
			
374
		elif o in ("-r", "--regenerate"):
376
		elif o in ("-r", "--regenerate"):
375
			regenerateModules()
377
			regenerateModules()
376
			
378
			
377
		elif o in ("--add"):
379
		elif o in ("--add"):
378
			if len(a) == 0:
380
			if len(a) == 0:
379
				print "No modulename specified"
381
				print "No modulename specified"
380
				usage()
382
				usage()
381
				sys.exit()
383
				sys.exit()
382
			
384
			
383
			if a not in getModules():
385
			if a not in getModules():
384
				print a + " is not a recognized module name"
386
				print a + " is not a recognized module name"
385
				sys.exit()
387
				sys.exit()
386
				
388
				
387
			addModule(a)
389
			addModule(a)
388
			
390
			
389
		elif o in ("--del"):
391
		elif o in ("--del"):
390
			if len(a) == 0:
392
			if len(a) == 0:
391
				print "No modulename specified"
393
				print "No modulename specified"
392
				usage()
394
				usage()
393
				sys.exit()
395
				sys.exit()
394
			
396
			
395
			if a not in getModules():
397
			if a not in getModules():
396
				print a + " is not a recognized module name"
398
				print a + " is not a recognized module name"
397
				sys.exit()
399
				sys.exit()
398
				
400
				
399
			delModule(a)
401
			delModule(a)
400
			
402
			
401
		elif o in ("--new"):
403
		elif o in ("--new"):
402
			if len(a) == 0:
404
			if len(a) == 0:
403
				print "No modulename specified"
405
				print "No modulename specified"
404
				usage()
406
				usage()
405
				sys.exit()
407
				sys.exit()
406
			
408
			
407
			if a in getModules():
409
			if a in getModules():
408
				print a + " already exists"
410
				print a + " already exists"
409
				sys.exit()
411
				sys.exit()
410
				
412
				
411
			newModule(a)
413
			newModule(a)
412
			
414
			
413
		else:
415
		else:
414
			assert False, "unhandled option"
416
			assert False, "unhandled option"
415
 
417
 
416
 
418
 
417
if __name__ == "__main__":
419
if __name__ == "__main__":
418
	main()
420
	main()
419
 
421