~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr

  • Committer: Martin Pool
  • Date: 2007-06-21 04:27:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2551.
  • Revision ID: mbp@sourcefrog.net-20070621042747-e3g0tdn8if750mv5
More commit specs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
2
2
 
3
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
3
# Copyright (C) 2005, 2006, 2007 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
21
21
import os
22
22
import sys
23
23
 
24
 
# update this on each release
25
 
_script_version = (1, 7, 0)
26
24
 
27
25
if __doc__ is None:
28
26
    print "bzr does not support python -OO."
45
43
                os.execvp(python, [python] + sys.argv)
46
44
            except OSError:
47
45
                pass
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)
 
46
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
 
47
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
50
48
    sys.exit(1)
51
49
if hasattr(os, "unsetenv"):
52
50
    os.unsetenv(REINVOKE)
59
57
    profile_imports.install()
60
58
    profiling = True
61
59
 
62
 
if sys.platform == 'darwin':
63
 
    # jameinel says this hack is to force python to honor the LANG setting,
64
 
    # even on Darwin.  Otherwise it is apparently hardcoded to Mac-Roman,
65
 
    # which is incorrect for the normal Terminal.app which wants UTF-8.  
66
 
    #
67
 
    # "It might be that I should be setting the "system locale" somewhere else
68
 
    # on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
69
 
    # Switching to 'posix' and setting LANG worked for me." 
70
 
    #
71
 
    # So we can remove this if someone works out the right way to tell Mac
72
 
    # Python which encoding to use.  -- mbp 20080703
73
 
    sys.platform = 'posix'
74
 
    try:
75
 
        import locale
76
 
    finally:
77
 
        sys.platform = 'darwin'
78
 
else:
79
 
    import locale
80
 
 
81
 
try:
82
 
    locale.setlocale(locale.LC_ALL, '')
83
 
except locale.Error, e:
84
 
    sys.stderr.write('bzr: warning: %s\n'
85
 
                     '  bzr could not set the application locale.\n'
86
 
                     '  Although this should be no problem for bzr itself,\n'
87
 
                     '  it might cause problems with some plugins.\n'
88
 
                     '  To investigate the issue, look at the output\n'
89
 
                     '  of the locale(1p) tool available on POSIX systems.\n'
90
 
                     % e)
91
60
 
92
61
try:
93
62
    import bzrlib
94
63
except ImportError, e:
95
64
    sys.stderr.write("bzr: ERROR: "
96
 
        "Couldn't import bzrlib and dependencies.\n"
97
 
        "Please check the directory containing bzrlib is on your PYTHONPATH.\n"
98
 
        "\n")
 
65
                     "Couldn't import bzrlib and dependencies.\n"
 
66
                     "Please check bzrlib is on your PYTHONPATH.\n"
 
67
                     "\n")
99
68
    raise
100
69
 
101
 
if bzrlib.version_info[:3] != _script_version:
102
 
    sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
103
 
            "This may indicate an installation problem.\n"
104
 
            "bzrlib from %s is version %r\n"
105
 
            % (bzrlib.__path__, bzrlib.version_info))
106
 
 
107
70
import bzrlib.inspect_for_copy
108
71
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
109
72
 
125
88
import bzrlib.commands
126
89
import bzrlib.trace
127
90
 
 
91
if bzrlib.version_info[:3] != (0, 17, 0):
 
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))
128
96
 
129
97
if __name__ == '__main__':
130
98
    bzrlib.trace.enable_default_logging()
133
101
    if profiling:
134
102
        profile_imports.log_stack_info(sys.stderr)
135
103
 
136
 
    # run anything registered by atexit, because it won't be run in the normal
137
 
    # way
138
 
    sys.exitfunc()
139
 
 
140
104
    # By this point we really have completed everything we want to do, and
141
105
    # there's no point doing any additional cleanup.  Abruptly exiting here
142
106
    # stops any background threads getting into trouble as code is unloaded,
149
113
        sys.stderr.flush()
150
114
    except IOError, e:
151
115
        import errno
152
 
        if e.errno in [errno.EINVAL, errno.EPIPE]:
153
 
            pass
154
 
        else:
 
116
        if sys.platform != 'win32' or e.errno != errno.EINVAL:
155
117
            raise
156
118
    if bzrlib.trace._trace_file:
157
119
        # this is also _bzr_log
158
120
        bzrlib.trace._trace_file.flush()
159
121
    os._exit(exit_val)
160
122
else:
161
 
    raise ImportError("The bzr script cannot be imported.")
 
123
    pass    # should this give an error? - it can't be used as a lib