From 3ef9283d6f3ef40a33d112a9c30313d8f57314ae Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 23 Apr 2015 08:35:09 -0400 Subject: [PATCH] simulator: Add a function for reloading the simulator This lets me update the doors.py file without needing to exit the Python interpreter. Signed-off-by: Anna Schumaker --- simulator.sh | 3 ++- simulator/__init__.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/simulator.sh b/simulator.sh index 592defe..b70f01f 100755 --- a/simulator.sh +++ b/simulator.sh @@ -1,2 +1,3 @@ #!/bin/bash -python -ic "from simulator import *" +python -ic "from simulator import * +def reload(): reload_sim(globals())" diff --git a/simulator/__init__.py b/simulator/__init__.py index 1921bf5..3529614 100644 --- a/simulator/__init__.py +++ b/simulator/__init__.py @@ -1,4 +1,5 @@ +import importlib import os import sys ####################################################### @@ -9,7 +10,18 @@ import sys sys.path.insert(0, os.path.join(os.getcwd(), "simulator")) - -print("Welcome to the Workantile Door System Simulator!") import doors from doors import * + + +def reload_sim(namespace): + importlib.reload(GPIO) + importlib.reload(request) + importlib.reload(serial) + importlib.reload(doors) + namespace.update(doors.__dict__) + + +print("") +print("Welcome to the Workantile Door System Simulator!") +print("Hint: call reload() to reload the simulator with updated code.")