~bzr/ubuntu/jaunty/bzrtools/beta-ppa

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Max Bowsher
  • Date: 2011-05-15 07:35:36 UTC
  • mfrom: (18.3.6 lucid)
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: maxb@f2s.com-20110515073536-6r2ii53bj4vqroog
Tags: 2.4.0~bzr767-2~bazaar1~karmic1
MergeĀ 2.4.0~bzr767-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import cmd
19
19
from itertools import chain
20
20
import os
21
 
import readline
 
21
try:
 
22
    import readline
 
23
except ImportError:
 
24
    _has_readline = False
 
25
else:
 
26
    _has_readline = True
22
27
import shlex
23
28
import stat
24
29
import string
25
30
import sys
26
31
 
27
 
from bzrlib import osutils
 
32
from bzrlib import osutils, trace
28
33
from bzrlib.branch import Branch
29
34
from bzrlib.config import config_dir, ensure_config_dir_exists
30
35
from bzrlib.commands import get_cmd_object, all_command_names, get_alias
100
105
        ensure_config_dir_exists()
101
106
        self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
102
107
        whitespace = ''.join(c for c in string.whitespace if c < chr(127))
103
 
        readline.set_completer_delims(whitespace)
104
 
        if os.access(self.history_file, os.R_OK) and \
105
 
            os.path.isfile(self.history_file):
106
 
            readline.read_history_file(self.history_file)
 
108
        if _has_readline:
 
109
            readline.set_completer_delims(whitespace)
 
110
            if os.access(self.history_file, os.R_OK) and \
 
111
                os.path.isfile(self.history_file):
 
112
                readline.read_history_file(self.history_file)
107
113
        self.cwd = os.getcwd()
108
114
 
109
115
    def write_history(self):
110
 
        readline.write_history_file(self.history_file)
 
116
        if _has_readline:
 
117
            readline.write_history_file(self.history_file)
111
118
 
112
119
    def do_quit(self, args):
113
120
        self.write_history()
198
205
            else:
199
206
                return (cmd_obj.run_argv_aliases(args, alias_args) or 0)
200
207
        except BzrError, e:
 
208
            trace.log_exception_quietly()
201
209
            print e
202
210
        except KeyboardInterrupt, e:
203
211
            print "Interrupted"
204
212
        except Exception, e:
205
 
#            print "Unhandled error:\n%s" % errors.exception_str(e)
 
213
            trace.log_exception_quietly()
206
214
            print "Unhandled error:\n%s" % (e)
207
215
 
208
216