1
1
#! /usr/bin/env python
3
# Copyright (C) 2004, 2005 by Martin Pool
4
# Copyright (C) 2005 by Canonical Ltd
3
# Copyright (C) 2005-2011 Canonical Ltd
6
5
# This program is free software; you can redistribute it and/or modify
7
6
# it under the terms of the GNU General Public License as published by
8
7
# the Free Software Foundation; either version 2 of the License, or
9
8
# (at your option) any later version.
11
10
# This program is distributed in the hope that it will be useful,
12
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
13
# GNU General Public License for more details.
16
15
# You should have received a copy of the GNU General Public License
17
16
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
import sys, bzrlib, bzrlib.commands
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 = (2, 5, 0)
29
version_info = sys.version_info
30
except AttributeError:
31
version_info = 1, 5 # 1.5 or older
33
REINVOKE = "__BZR_REINVOKE"
35
KNOWN_PYTHONS = ('python2.6', 'python2.7')
37
if version_info < NEED_VERS:
38
if not os.environ.has_key(REINVOKE):
39
# mutating os.environ doesn't work in old Pythons
40
os.putenv(REINVOKE, "1")
41
for python in KNOWN_PYTHONS:
43
os.execvp(python, [python] + sys.argv)
46
sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
47
sys.stderr.write(" (need %d.%d or later)\n" % NEED_VERS)
49
if hasattr(os, "unsetenv"):
54
if '--profile-imports' in sys.argv:
55
import profile_imports
56
profile_imports.install()
59
if sys.platform == 'darwin':
60
# jameinel says this hack is to force python to honor the LANG setting,
61
# even on Darwin. Otherwise it is apparently hardcoded to Mac-Roman,
62
# which is incorrect for the normal Terminal.app which wants UTF-8.
64
# "It might be that I should be setting the "system locale" somewhere else
65
# on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
66
# Switching to 'posix' and setting LANG worked for me."
68
# So we can remove this if someone works out the right way to tell Mac
69
# Python which encoding to use. -- mbp 20080703
70
sys.platform = 'posix'
74
sys.platform = 'darwin'
78
if os.name == "posix":
80
locale.setlocale(locale.LC_ALL, '')
81
except locale.Error, e:
82
sys.stderr.write('bzr: warning: %s\n'
83
' bzr could not set the application locale.\n'
84
' Although this should be no problem for bzr itself, it might\n'
85
' cause problems with some plugins. To investigate the issue,\n'
86
' look at the output of the locale(1p) tool.\n' % e)
89
# The python2.6 release includes some libraries that have deprecation warnings
90
# against the interpreter - see https://bugs.launchpad.net/bzr/+bug/387139
91
warnings.filterwarnings('ignore',
92
r"(struct integer overflow masking is deprecated|"
93
r"'L' format requires 0 <= number <= 4294967295)",
99
# instruct bzrlib/__init__.py to install lazy_regex
100
sys._bzr_lazy_regex = True
103
except ImportError, e:
104
sys.stderr.write("bzr: ERROR: "
105
"Couldn't import bzrlib and dependencies.\n"
106
"Please check the directory containing bzrlib is on your PYTHONPATH.\n"
110
if bzrlib.version_info[:3] != _script_version:
112
"bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
113
"This may indicate an installation problem.\n"
114
"bzrlib is version %s from %s\n"
115
"bzr is version %s from %s\n" % (
116
bzrlib._format_version_tuple(bzrlib.version_info),
118
bzrlib._format_version_tuple(_script_version),
122
import bzrlib.inspect_for_copy
123
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
125
import bzrlib.breakin
126
bzrlib.breakin.hook_debugger_to_signal()
128
import bzrlib.decorators
129
if ('--lsprof' in sys.argv
130
or '--lsprof-file' in sys.argv
131
or '--profile' in sys.argv
132
or '--lsprof-timed' in sys.argv):
133
bzrlib.decorators.use_pretty_decorators()
135
bzrlib.decorators.use_fast_decorators()
137
import bzrlib.commands
23
141
if __name__ == '__main__':
24
sys.exit(bzrlib.commands.main(sys.argv))
142
library_state = bzrlib.initialize()
143
library_state.__enter__()
145
exit_val = bzrlib.commands.main()
147
profile_imports.log_stack_info(sys.stderr)
149
library_state.__exit__(None, None, None)
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
161
raise ImportError("The bzr script cannot be imported.")