diff options
author | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-11-21 00:38:05 +0000 |
---|---|---|
committer | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-11-21 00:38:05 +0000 |
commit | 586cc480b8a0206855dd7058eb266a738d4510db (patch) | |
tree | c9e2d90ffbff49050b38d851ad8e2d2853fce918 /shell.py | |
parent | dddcdad519332868c1fcaf34cded5e0117f72536 (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.py | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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) |