aboutsummaryrefslogtreecommitdiffstats
path: root/shell.py
diff options
context:
space:
mode:
authorhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-11-21 00:38:05 +0000
committerhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-11-21 00:38:05 +0000
commit586cc480b8a0206855dd7058eb266a738d4510db (patch)
treec9e2d90ffbff49050b38d851ad8e2d2853fce918 /shell.py
parentdddcdad519332868c1fcaf34cded5e0117f72536 (diff)
Separate rc file and main loop
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@133 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'shell.py')
-rw-r--r--shell.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/shell.py b/shell.py
index faf695f..0567461 100644
--- a/shell.py
+++ b/shell.py
@@ -45,6 +45,7 @@ class Shell:
self.env = {"print_backtrace": "true"}
self.register_commands(self)
+ self.startup_ran = False
self.fallback = None
self.pre_hook = []
self.post_hook = []
@@ -67,27 +68,37 @@ class Shell:
def unregister_post_hook(self, function):
self.post_hook.remove(function)
-
-
def run(self):
"""Runs a loop to read commands and execute them. This function does
not (normally) return."""
- line = ""
+ if not self.startup_ran:
+ self.run_startup()
+
+ self._run()
+
+ def run_startup(self):
lines = []
+ self.startup_ran = True
try:
fp = file(os.path.join(os.environ["HOME"], ".%src" % self.basename))
lines = fp.readlines()
fp.close()
except IOError:
- pass
+ return
+
+ self._run(lines)
+
+ def _run(self, lines = None):
+
+ line = ""
- while True:
+ while lines is None or len(lines) > 0:
try:
for function in self.pre_hook:
function()
- if len(lines) > 0:
+ if lines is not None and len(lines) > 0:
line = lines.pop(0)
else:
line = raw_input("%s> " % self.prompt)