Commits

German Larrain committed a8da730

demo_runner: refactored code into 'run_demo'; added INTRODUCTION_MSG and INSTRUCTIONS.

Comments (0)

Files changed (1)

 	('sensors.velometer1', 'Velometer'),
 ]
 
+INTRODUCTION_MSG = """
+This executable can run all the demos included in ARS.
+"""
+INSTRUCTIONS = """
+Enter one of the following values:
+   d:         print demo list
+   (number):  run a demo (patience, the first time takes it takes a while)
+   q:         quit
+"""
+
 QUIT_STR = 'q'
 
 
 		print('%s: %s' % (i, option))
 
 
+def run_demo(selection):
+	try:
+		selected_demo_index = int(selection)
+	except ValueError:
+		print('Error, invalid input')
+		return 1
+
+	try:
+		selected_demo = DEMOS[selected_demo_index]  # (module, class_name)
+	except IndexError:
+		print('Error, option number is out of range')
+		return 2
+	module = import_module(DEMOS_PACKAGE_PREFIX + '.' + selected_demo[0])
+	klass = getattr(module, selected_demo[1])
+
+	sim_program = klass()
+	sim_program.start()
+	try:
+		sim_program.print_final_data()
+	except AttributeError:
+		pass
+	sim_program.finalize()
+
+
 def main():
 	user_input = None
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.