~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
2
2
 
3
 
# Copyright (C) 2005-2013, 2016 Canonical Ltd
 
3
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
4
4
#
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
14
14
#
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
18
 
 
19
 
from __future__ import absolute_import
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
18
 
21
19
"""Bazaar -- a free distributed version-control tool"""
22
20
 
23
21
import os
24
22
import sys
25
 
import warnings
26
23
 
27
24
# update this on each release
28
 
_script_version = (2, 8, 0)
29
 
 
30
 
NEED_VERS = (2, 6)
31
 
 
32
 
if sys.version_info < NEED_VERS:
 
25
_script_version = (1, 6, 0)
 
26
 
 
27
if __doc__ is None:
 
28
    print "bzr does not support python -OO."
 
29
    sys.exit(2)
 
30
try:
 
31
    version_info = sys.version_info
 
32
except AttributeError:
 
33
    version_info = 1, 5 # 1.5 or older
 
34
 
 
35
REINVOKE = "__BZR_REINVOKE"
 
36
NEED_VERS = (2, 4)
 
37
KNOWN_PYTHONS = ('python2.4', 'python2.5')
 
38
 
 
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:
 
44
            try:
 
45
                os.execvp(python, [python] + sys.argv)
 
46
            except OSError:
 
47
                pass
33
48
    sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
34
49
    sys.stderr.write("  (need %d.%d or later)\n" % NEED_VERS)
35
50
    sys.exit(1)
 
51
if hasattr(os, "unsetenv"):
 
52
    os.unsetenv(REINVOKE)
36
53
 
37
54
 
38
55
profiling = False
39
56
if '--profile-imports' in sys.argv:
 
57
    sys.argv.remove('--profile-imports')
40
58
    import profile_imports
41
59
    profile_imports.install()
42
60
    profiling = True
43
61
 
44
62
 
45
 
if os.name == "posix":
46
 
    import locale
47
 
    try:
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"
59
 
 
60
 
 
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)",
66
 
    DeprecationWarning,
67
 
    'gzip',
68
 
    )
69
 
 
70
 
 
71
 
# instruct bzrlib/__init__.py to install lazy_regex
72
 
sys._bzr_lazy_regex = True
73
63
try:
74
64
    import bzrlib
75
65
except ImportError, e:
76
66
    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"
79
 
        "\n")
 
67
                     "Couldn't import bzrlib and dependencies.\n"
 
68
                     "Please check bzrlib is on your PYTHONPATH.\n"
 
69
                     "\n")
80
70
    raise
81
71
 
82
72
if bzrlib.version_info[:3] != _script_version:
83
 
    sys.stderr.write(
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),
89
 
        bzrlib.__path__[0],
90
 
        bzrlib._format_version_tuple(_script_version),
91
 
        __file__))
92
 
 
 
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))
93
77
 
94
78
import bzrlib.inspect_for_copy
95
79
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
96
80
 
 
81
import bzrlib.lazy_regex
 
82
bzrlib.lazy_regex.install_lazy_compile()
 
83
 
97
84
import bzrlib.breakin
98
 
bzrlib.breakin.hook_debugger_to_signal()
 
85
bzrlib.breakin.hook_sigquit()
99
86
 
100
87
import bzrlib.decorators
101
88
if ('--lsprof' in sys.argv
111
98
 
112
99
 
113
100
if __name__ == '__main__':
114
 
    library_state = bzrlib.initialize()
115
 
    library_state.__enter__()
116
 
    try:
117
 
        exit_val = bzrlib.commands.main()
118
 
        if profiling:
119
 
            profile_imports.log_stack_info(sys.stderr)
120
 
    finally:
121
 
        library_state.__exit__(None, None, None)
 
101
    bzrlib.trace.enable_default_logging()
 
102
    exit_val = bzrlib.commands.main(sys.argv)
 
103
 
 
104
    if profiling:
 
105
        profile_imports.log_stack_info(sys.stderr)
 
106
 
 
107
    # run anything registered by atexit, because it won't be run in the normal
 
108
    # way
 
109
    sys.exitfunc()
122
110
 
123
111
    # By this point we really have completed everything we want to do, and
124
112
    # there's no point doing any additional cleanup.  Abruptly exiting here
127
115
    # are just about to be discarded anyhow.  This does mean that atexit hooks
128
116
    # won't run but we don't use them.  Also file buffers won't be flushed,
129
117
    # but our policy is to always close files from a finally block. -- mbp 20070215
130
 
    sys.exitfunc()
 
118
    try:
 
119
        sys.stdout.flush()
 
120
        sys.stderr.flush()
 
121
    except IOError, e:
 
122
        import errno
 
123
        if e.errno in [errno.EINVAL, errno.EPIPE]:
 
124
            pass
 
125
        else:
 
126
            raise
 
127
    if bzrlib.trace._trace_file:
 
128
        # this is also _bzr_log
 
129
        bzrlib.trace._trace_file.flush()
131
130
    os._exit(exit_val)
132
131
else:
133
132
    raise ImportError("The bzr script cannot be imported.")