Subversion Repositories HomeAutomation

Rev

Rev 824 | Rev 826 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 824 Rev 825
Line -... Line 1...
-
 
1
#!/bin/env python
-
 
2
 
1
# Written by Mattias Runge 2008-05-13
3
# Written by Mattias Runge 2008-05-13
2
 
4
 
3
import os
5
import os
4
import sys
6
import sys
5
import getopt
7
import getopt
Line 67... Line 69...
67
	print "Compiling new main.c..."
69
	print "Compiling new main.c..."
68
	main_c_template = open('src/main.c.template', 'r') 
70
	main_c_template = open('src/main.c.template', 'r') 
69
	main_c_template_lines = main_c_template.readlines()
71
	main_c_template_lines = main_c_template.readlines()
70
	main_c_template.close()
72
	main_c_template.close()
71
	
73
	
72
	modules = getLocalModules()
74
	modules = getLocalModules()
73
	
75
	
74
	main_c = open('src/main.c', 'w') 
76
	main_c = open('src/main.c', 'w') 
75
	
77
	
76
	for main_c_template_line in main_c_template_lines:
78
	for main_c_template_line in main_c_template_lines:
77
		pos_include = main_c_template_line.find('%INCLUDE')
79
		pos_include = main_c_template_line.find('%INCLUDE')
78
		pos_init = main_c_template_line.find('%INIT')
80
		pos_init = main_c_template_line.find('%INIT')
Line 139... Line 141...
139
		
141
		
140
		for moduleName in modules:
142
		for moduleName in modules:
141
			moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
143
			moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
142
	else:
144
	else:
143
		applicationSection = readConfigSection("config.inc", "application")
145
		applicationSection = readConfigSection("config.inc", "application")
144
		
146
		
145
		for moduleName in modules:
147
		for moduleName in modules:
146
			moduleSections[moduleName] = readConfigSection("config.inc", moduleName)
148
			moduleSections[moduleName] = readConfigSection("config.inc", moduleName)
147
			
149
			
148
			if len(moduleSections[moduleName]) <= 1:
150
			if len(moduleSections[moduleName]) <= 1:
149
				moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
151
				moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
Line 242... Line 244...
242
		os.symlink("../" + moddir + "/" + moduleName, localmoddir + "/" + moduleName)
244
		os.symlink("../" + moddir + "/" + moduleName, localmoddir + "/" + moduleName)
243
		print "Added module successfully"
245
		print "Added module successfully"
244
	except OSError, (errno, strerror):
246
	except OSError, (errno, strerror):
245
		if errno == 17:
247
		if errno == 17:
246
			print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking"
248
			print "A link, file or directory named " + moduleName + " is already present in the modules directory, not linking"
247
		else:
249
		else:
248
			raise
250
			raise
249
	
251
	
250
	print ""
252
	print ""
251
	
253
	
252
	regenerateModules()
254
	regenerateModules()
253
 
255
 
254
 
256
 
255
def delModule(moduleName):
257
def delModule(moduleName):
256
	print "Trying to remove module " + moduleName
258
	print "Trying to remove module " + moduleName
257
	
259
	
258
	try:
260
	try:
259
		os.unlink(localmoddir + "/" + moduleName)
261
		os.unlink(localmoddir + "/" + moduleName)
260
		print "Removed module successfully"
262
		print "Removed module successfully"
261
	except OSError, (errno, strerror):
263
	except OSError, (errno, strerror):
262
		if errno == 2:
264
		if errno == 2:
263
			print "No such " + moduleName + " present in the modules directory, not unlinking"
265
			print "No such " + moduleName + " present in the modules directory, not unlinking"
264
		else:
266
		else:
265
			raise
267
			raise
266
	
268
	
267
	print ""
269
	print ""
268
	
270
	
269
	regenerateModules()
271
	regenerateModules()
270
 
272
 
271
 
273
 
272
def usage():
274
def usage():
273
	print "Options:"
275
	print "Options:"
274
	print "\t--regenare\t\tRegenarate modules and files"
276
	print "\t--regenare\t\tRegenarate modules and files"
275
	print "\t--list\t\t\tList avalible modules"
277
	print "\t--list\t\t\tList avalible modules"
276
	print "\t--help\t\t\tPrint this help"
278
	print "\t--help\t\t\tPrint this help"
277
	print "\t--add=<module name>\tAdds a module to the application"
279
	print "\t--add=<module name>\tAdds a module to the application"
278
	print ""
280
	print ""
279
 
281
 
280
 
282
 
281
def main():
283
def main():
282
	try:
284
	try:
283
		opts, args = getopt.getopt(sys.argv[1:], "hlrd", ["help", "list", "regenerate", "add=", "del="])
285
		opts, args = getopt.getopt(sys.argv[1:], "hlrd", ["help", "list", "regenerate", "add=", "del="])
284
	except getopt.GetoptError, err:
286
	except getopt.GetoptError, err:
285
		# print help information and exit:
287
		# print help information and exit:
286
		print str(err) # will print something like "option -a not recognized"
288
		print str(err) # will print something like "option -a not recognized"
287
		usage()
289
		usage()
288
		sys.exit(2)
290
		sys.exit(2)
-
 
291
	
-
 
292
	if len(sys.argv) == 1:
-
 
293
		usage()
-
 
294
		sys.exit()
289
		
295
	
290
	for o, a in opts:
296
	for o, a in opts:
291
		if o in ("-l", "--list"):
297
		if o in ("-l", "--list"):
292
			print getModules()
298
			print getModules()
293
			
299