~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
2288.1.3 by Martin Pool
update copyright
3
# Copyright (C) 2005, 2006, 2007 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
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
18
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
19
"""Bazaar -- a free distributed version-control tool"""
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
20
21
import os
22
import sys
23
24
1185.35.10 by Aaron Bentley
Error when run with -OO
25
if __doc__ is None:
26
    print "bzr does not support python -OO."
27
    sys.exit(2)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
28
try:
29
    version_info = sys.version_info
30
except AttributeError:
31
    version_info = 1, 5 # 1.5 or older
32
1185.16.129 by Martin Pool
Add check that the bzr program and bzrlib version match.
33
REINVOKE = "__BZR_REINVOKE"
974.1.1 by Aaron Bentley
Fixed python invocation
34
NEED_VERS = (2, 4)
2055.1.1 by John Arbash Meinel
Find python2.5 if 2.4 cannot be found
35
KNOWN_PYTHONS = ('python2.4', 'python2.5')
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
36
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")
974.1.1 by Aaron Bentley
Fixed python invocation
41
        for python in KNOWN_PYTHONS:
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
42
            try:
43
                os.execvp(python, [python] + sys.argv)
44
            except OSError:
45
                pass
46
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
47
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
48
    sys.exit(1)
1185.1.7 by Robert Collins
Nathaniel McCallums patch for urandom friendliness on aix.
49
if hasattr(os, "unsetenv"):
50
    os.unsetenv(REINVOKE)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
51
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
52
1724.2.8 by John Arbash Meinel
New --profile-imports output which puts parents before children.
53
profiling = False
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
54
if '--profile-imports' in sys.argv:
55
    sys.argv.remove('--profile-imports')
1724.2.4 by John Arbash Meinel
Move the custom importers into a separate module
56
    import profile_imports
1724.2.14 by John Arbash Meinel
Refactor import stuff into separate functions. Update news
57
    profile_imports.install()
1724.2.8 by John Arbash Meinel
New --profile-imports output which puts parents before children.
58
    profiling = True
1724.2.1 by John Arbash Meinel
adding --profile-imports to a stock bzr.dev tree
59
60
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
61
try:
62
    import bzrlib
63
except ImportError, e:
64
    sys.stderr.write("bzr: ERROR: "
65
                     "Couldn't import bzrlib and dependencies.\n"
66
                     "Please check bzrlib is on your PYTHONPATH.\n"
67
                     "\n")
68
    raise
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
69
1996.3.11 by John Arbash Meinel
Hack around loading 'copy' to make startup much faster
70
import bzrlib.inspect_for_copy
71
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
72
2063.4.4 by John Arbash Meinel
Install lazy compile during startup
73
import bzrlib.lazy_regex
74
bzrlib.lazy_regex.install_lazy_compile()
75
2423.3.1 by Martin Pool
C-\ drops bzr into the debugger
76
import bzrlib.breakin
77
bzrlib.breakin.hook_sigquit()
78
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.
79
import bzrlib.decorators
80
if ('--lsprof' in sys.argv
81
    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
82
    or '--profile' in sys.argv
83
    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.
84
    bzrlib.decorators.use_pretty_decorators()
85
else:
86
    bzrlib.decorators.use_fast_decorators()
87
1996.3.11 by John Arbash Meinel
Hack around loading 'copy' to make startup much faster
88
import bzrlib.commands
89
import bzrlib.trace
90
2524.1.1 by Aaron Bentley
Revert broken changes
91
if bzrlib.version_info[:3] != (0, 18, 0):
1185.16.129 by Martin Pool
Add check that the bzr program and bzrlib version match.
92
    sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
93
            "This may indicate an installation problem.\n"
94
            "bzrlib from %s is version %r\n"
95
            % (bzrlib.__path__, bzrlib.version_info))
96
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
97
if __name__ == '__main__':
1111 by Martin Pool
- add functions to enable and disable default logging, so that we can
98
    bzrlib.trace.enable_default_logging()
1724.2.8 by John Arbash Meinel
New --profile-imports output which puts parents before children.
99
    exit_val = bzrlib.commands.main(sys.argv)
100
101
    if profiling:
102
        profile_imports.log_stack_info(sys.stderr)
2288.1.1 by Martin Pool
os._exit rather than sys.exit at top level
103
2485.6.7 by Martin Pool
Run exitfuncs explicitly before exiting
104
    # run anything registered by atexit, because it won't be run in the normal
105
    # way
106
    sys.exitfunc()
107
2288.1.1 by Martin Pool
os._exit rather than sys.exit at top level
108
    # By this point we really have completed everything we want to do, and
109
    # there's no point doing any additional cleanup.  Abruptly exiting here
110
    # stops any background threads getting into trouble as code is unloaded,
111
    # and it may also be slightly faster, through avoiding gc of objects that
112
    # are just about to be discarded anyhow.  This does mean that atexit hooks
113
    # won't run but we don't use them.  Also file buffers won't be flushed,
114
    # but our policy is to always close files from a finally block. -- mbp 20070215
2304.2.1 by Alexander Belchenko
Suppress IOError with errno=22 (Invalid argument) on win32 when pipe is broken
115
    try:
116
        sys.stdout.flush()
2309.2.1 by Alexander Belchenko
flush sys.stderr before os._exit
117
        sys.stderr.flush()
2304.2.1 by Alexander Belchenko
Suppress IOError with errno=22 (Invalid argument) on win32 when pipe is broken
118
    except IOError, e:
119
        import errno
120
        if sys.platform != 'win32' or e.errno != errno.EINVAL:
121
            raise
2295.1.1 by Martin Pool
Flush trace file before doing os._exit.
122
    if bzrlib.trace._trace_file:
123
        # this is also _bzr_log
124
        bzrlib.trace._trace_file.flush()
2288.1.1 by Martin Pool
os._exit rather than sys.exit at top level
125
    os._exit(exit_val)
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
126
else:
127
    pass    # should this give an error? - it can't be used as a lib