~bzr-pqm/bzr/bzr.dev

50 by mbp at sourcefrog
use "/usr/bin/env python" for shebang"
1
#! /usr/bin/env python
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
2
6615.1.1 by Vincent Ladeuil
Open trunk again as 2.8b1
3
# Copyright (C) 2005-2013, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
4
#
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
9
#
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
14
#
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
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
4183.7.1 by Sabin Iacob
update FSF mailing address
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
18
6379.6.3 by Jelmer Vernooij
Use absolute_import.
19
from __future__ import absolute_import
20
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
21
"""Bazaar -- a free distributed version-control tool"""
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
22
23
import os
24
import sys
4445.1.1 by Martin Pool
Ignore deprecation warnings from inside gzip.py
25
import warnings
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
26
3053.4.9 by Martin Pool
Prepare 1.0final!
27
# update this on each release
6615.1.1 by Vincent Ladeuil
Open trunk again as 2.8b1
28
_script_version = (2, 8, 0)
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
29
5848.2.1 by John Arbash Meinel
Break compatibility with python <2.6.
30
NEED_VERS = (2, 6)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
31
6385.2.1 by Martin Packman
Remove bzr script support for reinvoking with different python version
32
if sys.version_info < NEED_VERS:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
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)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
35
    sys.exit(1)
36
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
37
1724.2.8 by John Arbash Meinel
New --profile-imports output which puts parents before children.
38
profiling = False
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
39
if '--profile-imports' in sys.argv:
1724.2.4 by John Arbash Meinel
Move the custom importers into a separate module
40
    import profile_imports
1724.2.14 by John Arbash Meinel
Refactor import stuff into separate functions. Update news
41
    profile_imports.install()
1724.2.8 by John Arbash Meinel
New --profile-imports output which puts parents before children.
42
    profiling = True
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
43
6383.1.2 by Martin Packman
Remove locale hacks for OSX from bzr script
44
45
if os.name == "posix":
3512.3.1 by Martin von Gagern
Hand-selected minimalistic set of changes from my setlocale branch.
46
    import locale
5050.29.1 by Martin
Only call setlocale on posix platforms to avoid console printing breakage with Python 2.6 and later on windows
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)
6352.3.3 by Martin Packman
Use UTF-8 as the filesystem default encoding when running bzr if it would otherwise be ascii
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"
5050.29.1 by Martin
Only call setlocale on posix platforms to avoid console printing breakage with Python 2.6 and later on windows
59
4445.1.1 by Martin Pool
Ignore deprecation warnings from inside gzip.py
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
3224.5.29 by Andrew Bennetts
Install lazy_regex code sooner, so that it is there before the stdlib gets a chance to 'import string', which compiles regexes.
71
# instruct bzrlib/__init__.py to install lazy_regex
72
sys._bzr_lazy_regex = True
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
73
try:
74
    import bzrlib
75
except ImportError, e:
76
    sys.stderr.write("bzr: ERROR: "
3497.3.3 by Martin Pool
Clearer message about how to set PYTHONPATH
77
        "Couldn't import bzrlib and dependencies.\n"
78
        "Please check the directory containing bzrlib is on your PYTHONPATH.\n"
79
        "\n")
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
80
    raise
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
81
3053.4.9 by Martin Pool
Prepare 1.0final!
82
if bzrlib.version_info[:3] != _script_version:
5997.1.2 by Martin Pool
Better message on mismatched bzr/bzrlib
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
2867.2.1 by Alexander Belchenko
check bzrlib version early
93
1996.3.11 by John Arbash Meinel
Hack around loading 'copy' to make startup much faster
94
import bzrlib.inspect_for_copy
95
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
96
2423.3.1 by Martin Pool
C-\ drops bzr into the debugger
97
import bzrlib.breakin
4578.1.1 by John Arbash Meinel
Update the breakin support to support CTRL-BREAK on Windows.
98
bzrlib.breakin.hook_debugger_to_signal()
2423.3.1 by Martin Pool
C-\ drops bzr into the debugger
99
2230.2.3 by John Arbash Meinel
Add the ability to have fast decorators as well as pretty ones, and have 'bzr' select the right one at startup.
100
import bzrlib.decorators
101
if ('--lsprof' in sys.argv
102
    or '--lsprof-file' in sys.argv
2476.2.1 by John Arbash Meinel
Vastly improve bundle install performance by only validating the bundle one time
103
    or '--profile' in sys.argv
104
    or '--lsprof-timed' in sys.argv):
2230.2.3 by John Arbash Meinel
Add the ability to have fast decorators as well as pretty ones, and have 'bzr' select the right one at startup.
105
    bzrlib.decorators.use_pretty_decorators()
106
else:
107
    bzrlib.decorators.use_fast_decorators()
108
1996.3.11 by John Arbash Meinel
Hack around loading 'copy' to make startup much faster
109
import bzrlib.commands
110
import bzrlib.trace
111
2592.3.163 by Robert Collins
Merge bzr.dev (untested)
112
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
113
if __name__ == '__main__':
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
114
    library_state = bzrlib.initialize()
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
115
    library_state.__enter__()
5222.2.1 by Aaron Bentley
Clean up progress output on exit.
116
    try:
117
        exit_val = bzrlib.commands.main()
118
        if profiling:
119
            profile_imports.log_stack_info(sys.stderr)
120
    finally:
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
121
        library_state.__exit__(None, None, None)
2485.6.7 by Martin Pool
Run exitfuncs explicitly before exiting
122
2288.1.1 by Martin Pool
os._exit rather than sys.exit at top level
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
5017.1.1 by Martin Pool
Add bzrlib.initialize
130
    sys.exitfunc()
2288.1.1 by Martin Pool
os._exit rather than sys.exit at top level
131
    os._exit(exit_val)
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
132
else:
3275.2.1 by Benjamin Peterson
Made importing the bzr script raise an ImportError
133
    raise ImportError("The bzr script cannot be imported.")