~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr

  • Committer: Vincent Ladeuil
  • Date: 2010-10-26 08:08:23 UTC
  • mfrom: (5514.1.1 665100-content-type)
  • mto: This revision was merged to the branch mainline in revision 5516.
  • Revision ID: v.ladeuil+lp@free.fr-20101026080823-3wggo03b7cpn9908
Correctly set the Content-Type header when POSTing http requests

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 by Canonical Ltd
4
 
 
 
3
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Canonical Ltd
 
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
7
7
# the Free Software Foundation; either version 2 of the License, or
8
8
# (at your option) any later version.
9
 
 
 
9
#
10
10
# This program is distributed in the hope that it will be useful,
11
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
13
# GNU General Public License for more details.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
"""Bazaar-NG -- a free distributed version-control tool"""
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
18
 
 
19
"""Bazaar -- a free distributed version-control tool"""
19
20
 
20
21
import os
21
22
import sys
22
 
 
23
 
 
24
 
if __doc__ is None:
25
 
    print "bzr does not support python -OO."
26
 
    sys.exit(2)
 
23
import warnings
 
24
 
 
25
# update this on each release
 
26
_script_version = (2, 3, 0)
 
27
 
27
28
try:
28
29
    version_info = sys.version_info
29
30
except AttributeError:
31
32
 
32
33
REINVOKE = "__BZR_REINVOKE"
33
34
NEED_VERS = (2, 4)
34
 
KNOWN_PYTHONS = ('python2.4',)
 
35
KNOWN_PYTHONS = ('python2.4', 'python2.5', 'python2.6')
35
36
 
36
37
if version_info < NEED_VERS:
37
38
    if not os.environ.has_key(REINVOKE):
42
43
                os.execvp(python, [python] + sys.argv)
43
44
            except OSError:
44
45
                pass
45
 
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
46
 
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
 
46
    sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
 
47
    sys.stderr.write("  (need %d.%d or later)\n" % NEED_VERS)
47
48
    sys.exit(1)
48
49
if hasattr(os, "unsetenv"):
49
50
    os.unsetenv(REINVOKE)
50
51
 
51
52
 
52
 
 
53
53
profiling = False
54
54
if '--profile-imports' in sys.argv:
55
 
    sys.argv.remove('--profile-imports')
56
55
    import profile_imports
57
56
    profile_imports.install()
58
57
    profiling = True
59
58
 
60
 
 
 
59
if sys.platform == 'darwin':
 
60
    # jameinel says this hack is to force python to honor the LANG setting,
 
61
    # even on Darwin.  Otherwise it is apparently hardcoded to Mac-Roman,
 
62
    # which is incorrect for the normal Terminal.app which wants UTF-8.
 
63
    #
 
64
    # "It might be that I should be setting the "system locale" somewhere else
 
65
    # on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
 
66
    # Switching to 'posix' and setting LANG worked for me."
 
67
    #
 
68
    # So we can remove this if someone works out the right way to tell Mac
 
69
    # Python which encoding to use.  -- mbp 20080703
 
70
    sys.platform = 'posix'
 
71
    try:
 
72
        import locale
 
73
    finally:
 
74
        sys.platform = 'darwin'
 
75
else:
 
76
    import locale
 
77
 
 
78
if os.name == "posix":
 
79
    try:
 
80
        locale.setlocale(locale.LC_ALL, '')
 
81
    except locale.Error, e:
 
82
        sys.stderr.write('bzr: warning: %s\n'
 
83
            '  bzr could not set the application locale.\n'
 
84
            '  Although this should be no problem for bzr itself, it might\n'
 
85
            '  cause problems with some plugins. To investigate the issue,\n'
 
86
            '  look at the output of the locale(1p) tool.\n' % e)
 
87
 
 
88
 
 
89
# The python2.6 release includes some libraries that have deprecation warnings
 
90
# against the interpreter - see https://bugs.launchpad.net/bzr/+bug/387139
 
91
warnings.filterwarnings('ignore',
 
92
    r"(struct integer overflow masking is deprecated|"
 
93
    r"'L' format requires 0 <= number <= 4294967295)",
 
94
    DeprecationWarning,
 
95
    'gzip',
 
96
    )
 
97
 
 
98
 
 
99
# instruct bzrlib/__init__.py to install lazy_regex
 
100
sys._bzr_lazy_regex = True
61
101
try:
62
102
    import bzrlib
63
 
    import bzrlib.commands
64
 
    import bzrlib.trace
65
103
except ImportError, e:
66
104
    sys.stderr.write("bzr: ERROR: "
67
 
                     "Couldn't import bzrlib and dependencies.\n"
68
 
                     "Please check bzrlib is on your PYTHONPATH.\n"
69
 
                     "\n")
 
105
        "Couldn't import bzrlib and dependencies.\n"
 
106
        "Please check the directory containing bzrlib is on your PYTHONPATH.\n"
 
107
        "\n")
70
108
    raise
71
109
 
72
 
if bzrlib.version_info[:3] != (0, 9, 0):
 
110
if bzrlib.version_info[:3] != _script_version:
73
111
    sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
74
112
            "This may indicate an installation problem.\n"
75
113
            "bzrlib from %s is version %r\n"
76
114
            % (bzrlib.__path__, bzrlib.version_info))
77
115
 
 
116
import bzrlib.inspect_for_copy
 
117
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
 
118
 
 
119
import bzrlib.breakin
 
120
bzrlib.breakin.hook_debugger_to_signal()
 
121
 
 
122
import bzrlib.decorators
 
123
if ('--lsprof' in sys.argv
 
124
    or '--lsprof-file' in sys.argv
 
125
    or '--profile' in sys.argv
 
126
    or '--lsprof-timed' in sys.argv):
 
127
    bzrlib.decorators.use_pretty_decorators()
 
128
else:
 
129
    bzrlib.decorators.use_fast_decorators()
 
130
 
 
131
import bzrlib.commands
 
132
import bzrlib.trace
 
133
 
 
134
 
78
135
if __name__ == '__main__':
79
 
    bzrlib.trace.enable_default_logging()
80
 
    exit_val = bzrlib.commands.main(sys.argv)
 
136
    library_state = bzrlib.initialize()
 
137
    library_state.__enter__()
 
138
    try:
 
139
        exit_val = bzrlib.commands.main()
 
140
        if profiling:
 
141
            profile_imports.log_stack_info(sys.stderr)
 
142
    finally:
 
143
        library_state.__exit__(None, None, None)
81
144
 
82
 
    if profiling:
83
 
        profile_imports.log_stack_info(sys.stderr)
84
 
    sys.exit(exit_val)
 
145
    # By this point we really have completed everything we want to do, and
 
146
    # there's no point doing any additional cleanup.  Abruptly exiting here
 
147
    # stops any background threads getting into trouble as code is unloaded,
 
148
    # and it may also be slightly faster, through avoiding gc of objects that
 
149
    # are just about to be discarded anyhow.  This does mean that atexit hooks
 
150
    # won't run but we don't use them.  Also file buffers won't be flushed,
 
151
    # but our policy is to always close files from a finally block. -- mbp 20070215
 
152
    sys.exitfunc()
 
153
    os._exit(exit_val)
85
154
else:
86
 
    pass    # should this give an error? - it can't be used as a lib
 
155
    raise ImportError("The bzr script cannot be imported.")