1
1
#! /usr/bin/env python
3
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
3
# Copyright (C) 2005 by 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""Bazaar -- a free distributed version-control tool"""
25
# update this on each release
26
_script_version = (1, 17, 0)
29
print "bzr does not support python -OO."
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
22
version_info = sys.version_info
33
23
except AttributeError:
34
24
version_info = 1, 5 # 1.5 or older
36
REINVOKE = "__BZR_REINVOKE"
27
REINVOKE = "__BZR_REINVOKE"
38
KNOWN_PYTHONS = ('python2.4', 'python2.5', 'python2.6')
29
KNOWN_PYTHONS = ('python2.4',)
40
31
if version_info < NEED_VERS:
41
32
if not os.environ.has_key(REINVOKE):
46
37
os.execvp(python, [python] + sys.argv)
49
sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
50
sys.stderr.write(" (need %d.%d or later)\n" % NEED_VERS)
40
print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
41
print >>sys.stderr, " (need %d.%d or later)" % NEED_VERS
52
if hasattr(os, "unsetenv"):
57
if '--profile-imports' in sys.argv:
58
sys.argv.remove('--profile-imports')
59
import profile_imports
60
profile_imports.install()
63
if sys.platform == 'darwin':
64
# jameinel says this hack is to force python to honor the LANG setting,
65
# even on Darwin. Otherwise it is apparently hardcoded to Mac-Roman,
66
# which is incorrect for the normal Terminal.app which wants UTF-8.
68
# "It might be that I should be setting the "system locale" somewhere else
69
# on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
70
# Switching to 'posix' and setting LANG worked for me."
72
# So we can remove this if someone works out the right way to tell Mac
73
# Python which encoding to use. -- mbp 20080703
74
sys.platform = 'posix'
78
sys.platform = 'darwin'
83
# The python2.6 release includes some libraries that have deprecation warnings
84
# against the interpreter - see https://bugs.launchpad.net/bzr/+bug/387139
85
warnings.filterwarnings('ignore',
86
r"(struct integer overflow masking is deprecated|"
87
r"'L' format requires 0 <= number <= 4294967295)",
94
locale.setlocale(locale.LC_ALL, '')
95
except locale.Error, e:
96
sys.stderr.write('bzr: warning: %s\n'
97
' bzr could not set the application locale.\n'
98
' Although this should be no problem for bzr itself,\n'
99
' it might cause problems with some plugins.\n'
100
' To investigate the issue, look at the output\n'
101
' of the locale(1p) tool available on POSIX systems.\n'
104
# instruct bzrlib/__init__.py to install lazy_regex
105
sys._bzr_lazy_regex = True
108
except ImportError, e:
109
sys.stderr.write("bzr: ERROR: "
110
"Couldn't import bzrlib and dependencies.\n"
111
"Please check the directory containing bzrlib is on your PYTHONPATH.\n"
115
if bzrlib.version_info[:3] != _script_version:
116
sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
117
"This may indicate an installation problem.\n"
118
"bzrlib from %s is version %r\n"
119
% (bzrlib.__path__, bzrlib.version_info))
121
import bzrlib.inspect_for_copy
122
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
124
import bzrlib.breakin
125
bzrlib.breakin.hook_sigquit()
127
import bzrlib.decorators
128
if ('--lsprof' in sys.argv
129
or '--lsprof-file' in sys.argv
130
or '--profile' in sys.argv
131
or '--lsprof-timed' in sys.argv):
132
bzrlib.decorators.use_pretty_decorators()
134
bzrlib.decorators.use_fast_decorators()
136
import bzrlib.commands
45
import bzrlib, bzrlib.commands
140
47
if __name__ == '__main__':
141
bzrlib.trace.enable_default_logging()
142
exit_val = bzrlib.commands.main()
145
profile_imports.log_stack_info(sys.stderr)
147
# run anything registered by atexit, because it won't be run in the normal
151
# By this point we really have completed everything we want to do, and
152
# there's no point doing any additional cleanup. Abruptly exiting here
153
# stops any background threads getting into trouble as code is unloaded,
154
# and it may also be slightly faster, through avoiding gc of objects that
155
# are just about to be discarded anyhow. This does mean that atexit hooks
156
# won't run but we don't use them. Also file buffers won't be flushed,
157
# but our policy is to always close files from a finally block. -- mbp 20070215
163
if e.errno in [errno.EINVAL, errno.EPIPE]:
167
if bzrlib.trace._trace_file:
168
# this is also _bzr_log
169
bzrlib.trace._trace_file.flush()
172
raise ImportError("The bzr script cannot be imported.")
48
sys.exit(bzrlib.commands.main(sys.argv))