1
1
#! /usr/bin/env python
3
# Copyright (C) 2005 by Canonical Ltd
3
# Copyright (C) 2005-2012 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
from __future__ import absolute_import
21
"""Bazaar -- a free distributed version-control tool"""
27
# update this on each release
28
_script_version = (2, 6, 0)
32
if sys.version_info < NEED_VERS:
33
sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
34
sys.stderr.write(" (need %d.%d or later)\n" % NEED_VERS)
39
if '--profile-imports' in sys.argv:
40
import profile_imports
41
profile_imports.install()
45
if os.name == "posix":
48
locale.setlocale(locale.LC_ALL, '')
49
except locale.Error, e:
50
sys.stderr.write('bzr: warning: %s\n'
51
' bzr could not set the application locale.\n'
52
' Although this should be no problem for bzr itself, it might\n'
53
' cause problems with some plugins. To investigate the issue,\n'
54
' look at the output of the locale(1p) tool.\n' % e)
55
# Use better default than ascii with posix filesystems that deal in bytes
56
# natively even when the C locale or no locale at all is given. Note that
57
# we need an immortal string for the hack, hence the lack of a hyphen.
58
sys._bzr_default_fs_enc = "utf8"
61
# The python2.6 release includes some libraries that have deprecation warnings
62
# against the interpreter - see https://bugs.launchpad.net/bzr/+bug/387139
63
warnings.filterwarnings('ignore',
64
r"(struct integer overflow masking is deprecated|"
65
r"'L' format requires 0 <= number <= 4294967295)",
71
# instruct bzrlib/__init__.py to install lazy_regex
72
sys._bzr_lazy_regex = True
22
version_info = sys.version_info
23
except AttributeError:
24
version_info = 1, 5 # 1.5 or older
27
REINVOKE = "__BZR_REINVOKE"
29
KNOWN_PYTHONS = ('python2.4',)
31
if version_info < NEED_VERS:
32
if not os.environ.has_key(REINVOKE):
33
# mutating os.environ doesn't work in old Pythons
34
os.putenv(REINVOKE, "1")
35
for python in KNOWN_PYTHONS:
37
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
75
except ImportError, e:
76
sys.stderr.write("bzr: ERROR: "
77
"Couldn't import bzrlib and dependencies.\n"
78
"Please check the directory containing bzrlib is on your PYTHONPATH.\n"
82
if bzrlib.version_info[:3] != _script_version:
84
"bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
85
"This may indicate an installation problem.\n"
86
"bzrlib is version %s from %s\n"
87
"bzr is version %s from %s\n" % (
88
bzrlib._format_version_tuple(bzrlib.version_info),
90
bzrlib._format_version_tuple(_script_version),
94
import bzrlib.inspect_for_copy
95
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
98
bzrlib.breakin.hook_debugger_to_signal()
100
import bzrlib.decorators
101
if ('--lsprof' in sys.argv
102
or '--lsprof-file' in sys.argv
103
or '--profile' in sys.argv
104
or '--lsprof-timed' in sys.argv):
105
bzrlib.decorators.use_pretty_decorators()
107
bzrlib.decorators.use_fast_decorators()
46
109
import bzrlib.commands
47
110
import bzrlib.trace
49
113
if __name__ == '__main__':
50
bzrlib.trace.enable_default_logging()
51
sys.exit(bzrlib.commands.main(sys.argv))
114
library_state = bzrlib.initialize()
115
library_state.__enter__()
117
exit_val = bzrlib.commands.main()
119
profile_imports.log_stack_info(sys.stderr)
121
library_state.__exit__(None, None, None)
123
# By this point we really have completed everything we want to do, and
124
# there's no point doing any additional cleanup. Abruptly exiting here
125
# stops any background threads getting into trouble as code is unloaded,
126
# and it may also be slightly faster, through avoiding gc of objects that
127
# are just about to be discarded anyhow. This does mean that atexit hooks
128
# won't run but we don't use them. Also file buffers won't be flushed,
129
# but our policy is to always close files from a finally block. -- mbp 20070215
133
raise ImportError("The bzr script cannot be imported.")