3
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
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
19
"""Bazaar -- a free distributed version-control tool"""
24
# update this on each release
25
_script_version = (1, 6, 0)
28
print "bzr does not support python -OO."
31
version_info = sys.version_info
32
except AttributeError:
33
version_info = 1, 5 # 1.5 or older
35
REINVOKE = "__BZR_REINVOKE"
37
KNOWN_PYTHONS = ('python2.4', 'python2.5')
39
if version_info < NEED_VERS:
40
if not os.environ.has_key(REINVOKE):
41
# mutating os.environ doesn't work in old Pythons
42
os.putenv(REINVOKE, "1")
43
for python in KNOWN_PYTHONS:
45
os.execvp(python, [python] + sys.argv)
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)
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()
65
except ImportError, e:
66
sys.stderr.write("bzr: ERROR: "
67
"Couldn't import bzrlib and dependencies.\n"
68
"Please check bzrlib is on your PYTHONPATH.\n"
72
if bzrlib.version_info[:3] != _script_version:
73
sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
74
"This may indicate an installation problem.\n"
75
"bzrlib from %s is version %r\n"
76
% (bzrlib.__path__, bzrlib.version_info))
78
import bzrlib.inspect_for_copy
79
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
81
import bzrlib.lazy_regex
82
bzrlib.lazy_regex.install_lazy_compile()
85
bzrlib.breakin.hook_sigquit()
87
import bzrlib.decorators
88
if ('--lsprof' in sys.argv
89
or '--lsprof-file' in sys.argv
90
or '--profile' in sys.argv
91
or '--lsprof-timed' in sys.argv):
92
bzrlib.decorators.use_pretty_decorators()
94
bzrlib.decorators.use_fast_decorators()
96
import bzrlib.commands
100
if __name__ == '__main__':
101
bzrlib.trace.enable_default_logging()
102
exit_val = bzrlib.commands.main(sys.argv)
105
profile_imports.log_stack_info(sys.stderr)
107
# run anything registered by atexit, because it won't be run in the normal
111
# By this point we really have completed everything we want to do, and
112
# there's no point doing any additional cleanup. Abruptly exiting here
113
# stops any background threads getting into trouble as code is unloaded,
114
# and it may also be slightly faster, through avoiding gc of objects that
115
# are just about to be discarded anyhow. This does mean that atexit hooks
116
# won't run but we don't use them. Also file buffers won't be flushed,
117
# but our policy is to always close files from a finally block. -- mbp 20070215
123
if e.errno in [errno.EINVAL, errno.EPIPE]:
127
if bzrlib.trace._trace_file:
128
# this is also _bzr_log
129
bzrlib.trace._trace_file.flush()
132
raise ImportError("The bzr script cannot be imported.")