Commits

German Larrain  committed a8da730

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

  • Participants
  • Parent commits ac1d541

Comments (0)

Files changed (1)

File demo_runner.py

 	('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