1
1
#! /usr/bin/env python
3
# Copyright (C) 2005 by Canonical Ltd
3
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License as published by
7
7
# the Free Software Foundation; either version 2 of the License, or
8
8
# (at your option) any later version.
10
10
# This program is distributed in the hope that it will be useful,
11
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
# GNU General Public License for more details.
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""Bazaar -- a free distributed version-control tool"""
24
# update this on each release
25
_script_version = (1, 17, 0)
28
print "bzr does not support python -OO."
22
31
version_info = sys.version_info
23
32
except AttributeError:
24
33
version_info = 1, 5 # 1.5 or older
27
REINVOKE = "__BZR_REINVOKE"
35
REINVOKE = "__BZR_REINVOKE"
29
KNOWN_PYTHONS = ('python2.4',)
37
KNOWN_PYTHONS = ('python2.4', 'python2.5')
31
39
if version_info < NEED_VERS:
32
40
if not os.environ.has_key(REINVOKE):
37
45
os.execvp(python, [python] + sys.argv)
40
print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
41
print >>sys.stderr, " (need %d.%d or later)" % NEED_VERS
48
sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
49
sys.stderr.write(" (need %d.%d or later)\n" % NEED_VERS)
45
import bzrlib, bzrlib.commands
51
if hasattr(os, "unsetenv"):
56
if '--profile-imports' in sys.argv:
57
sys.argv.remove('--profile-imports')
58
import profile_imports
59
profile_imports.install()
62
if sys.platform == 'darwin':
63
# jameinel says this hack is to force python to honor the LANG setting,
64
# even on Darwin. Otherwise it is apparently hardcoded to Mac-Roman,
65
# which is incorrect for the normal Terminal.app which wants UTF-8.
67
# "It might be that I should be setting the "system locale" somewhere else
68
# on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
69
# Switching to 'posix' and setting LANG worked for me."
71
# So we can remove this if someone works out the right way to tell Mac
72
# Python which encoding to use. -- mbp 20080703
73
sys.platform = 'posix'
77
sys.platform = 'darwin'
82
locale.setlocale(locale.LC_ALL, '')
83
except locale.Error, e:
84
sys.stderr.write('bzr: warning: %s\n'
85
' bzr could not set the application locale.\n'
86
' Although this should be no problem for bzr itself,\n'
87
' it might cause problems with some plugins.\n'
88
' To investigate the issue, look at the output\n'
89
' of the locale(1p) tool available on POSIX systems.\n'
92
# instruct bzrlib/__init__.py to install lazy_regex
93
sys._bzr_lazy_regex = True
96
except ImportError, e:
97
sys.stderr.write("bzr: ERROR: "
98
"Couldn't import bzrlib and dependencies.\n"
99
"Please check the directory containing bzrlib is on your PYTHONPATH.\n"
103
if bzrlib.version_info[:3] != _script_version:
104
sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
105
"This may indicate an installation problem.\n"
106
"bzrlib from %s is version %r\n"
107
% (bzrlib.__path__, bzrlib.version_info))
109
import bzrlib.inspect_for_copy
110
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
112
import bzrlib.breakin
113
bzrlib.breakin.hook_sigquit()
115
import bzrlib.decorators
116
if ('--lsprof' in sys.argv
117
or '--lsprof-file' in sys.argv
118
or '--profile' in sys.argv
119
or '--lsprof-timed' in sys.argv):
120
bzrlib.decorators.use_pretty_decorators()
122
bzrlib.decorators.use_fast_decorators()
124
import bzrlib.commands
47
128
if __name__ == '__main__':
48
sys.exit(bzrlib.commands.main(sys.argv))
129
bzrlib.trace.enable_default_logging()
130
exit_val = bzrlib.commands.main()
133
profile_imports.log_stack_info(sys.stderr)
135
# run anything registered by atexit, because it won't be run in the normal
139
# By this point we really have completed everything we want to do, and
140
# there's no point doing any additional cleanup. Abruptly exiting here
141
# stops any background threads getting into trouble as code is unloaded,
142
# and it may also be slightly faster, through avoiding gc of objects that
143
# are just about to be discarded anyhow. This does mean that atexit hooks
144
# won't run but we don't use them. Also file buffers won't be flushed,
145
# but our policy is to always close files from a finally block. -- mbp 20070215
151
if e.errno in [errno.EINVAL, errno.EPIPE]:
155
if bzrlib.trace._trace_file:
156
# this is also _bzr_log
157
bzrlib.trace._trace_file.flush()
160
raise ImportError("The bzr script cannot be imported.")