~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
3
# Copyright (C) 2005 by Canonical Ltd
4
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.
9
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.
14
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
1185.35.10 by Aaron Bentley
Error when run with -OO
18
"""Bazaar-NG -- a free distributed version-control tool"""
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
19
import os, sys
1185.35.10 by Aaron Bentley
Error when run with -OO
20
if __doc__ is None:
21
    print "bzr does not support python -OO."
22
    sys.exit(2)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
23
try:
24
    version_info = sys.version_info
25
except AttributeError:
26
    version_info = 1, 5 # 1.5 or older
27
1185.16.129 by Martin Pool
Add check that the bzr program and bzrlib version match.
28
REINVOKE = "__BZR_REINVOKE"
974.1.1 by Aaron Bentley
Fixed python invocation
29
NEED_VERS = (2, 4)
30
KNOWN_PYTHONS = ('python2.4',)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
31
32
if version_info < NEED_VERS:
33
    if not os.environ.has_key(REINVOKE):
34
        # mutating os.environ doesn't work in old Pythons
35
        os.putenv(REINVOKE, "1")
974.1.1 by Aaron Bentley
Fixed python invocation
36
        for python in KNOWN_PYTHONS:
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
37
            try:
38
                os.execvp(python, [python] + sys.argv)
39
            except OSError:
40
                pass
41
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
42
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
43
    sys.exit(1)
1185.1.7 by Robert Collins
Nathaniel McCallums patch for urandom friendliness on aix.
44
if hasattr(os, "unsetenv"):
45
    os.unsetenv(REINVOKE)
443 by Martin Pool
- Patch from Fredrik Lundh to check Python version and
46
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
47
try:
48
    import bzrlib
49
    import bzrlib.commands
50
    import bzrlib.trace
51
except ImportError, e:
52
    sys.stderr.write("bzr: ERROR: "
53
                     "Couldn't import bzrlib and dependencies.\n"
54
                     "Please check bzrlib is on your PYTHONPATH.\n"
55
                     "\n")
56
    raise
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
57
1185.16.144 by Martin Pool
Bump version to 0.7pre
58
if bzrlib.version_info[:3] != (0, 7, 0):
1185.16.129 by Martin Pool
Add check that the bzr program and bzrlib version match.
59
    sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
60
            "This may indicate an installation problem.\n"
61
            "bzrlib from %s is version %r\n"
62
            % (bzrlib.__path__, bzrlib.version_info))
63
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
64
if __name__ == '__main__':
1111 by Martin Pool
- add functions to enable and disable default logging, so that we can
65
    bzrlib.trace.enable_default_logging()
32 by mbp at sourcefrog
- Split commands into bzrlib.commands
66
    sys.exit(bzrlib.commands.main(sys.argv))
1393.1.3 by Martin Pool
- better error on failing to import bzrlib
67
else:
68
    pass    # should this give an error? - it can't be used as a lib