/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4634.119.10 by John Arbash Meinel
Prepare 2.0.4 final
1
# Copyright (C) 2005-2010 Canonical Ltd
2052.3.5 by John Arbash Meinel
Guide people to how to add files to the list of exceptions
2
#
1 by mbp at sourcefrog
import from baz patch-364
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
7
#
1 by mbp at sourcefrog
import from baz patch-364
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
12
#
1 by mbp at sourcefrog
import from baz patch-364
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1 by mbp at sourcefrog
import from baz patch-364
16
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
17
"""All of bzr.
18
19
Developer documentation is available at
20
http://doc.bazaar.canonical.com/bzr.dev/developers/
21
22
The project website is at http://bazaar.canonical.com/
23
24
Some particularly interesting things in bzrlib are:
25
26
 * bzrlib.initialize -- setup the library for use
27
 * bzrlib.plugin.load_plugins -- load all installed plugins
28
 * bzrlib.branch.Branch.open -- open a branch
29
 * bzrlib.workingtree.WorkingTree.open -- open a working tree
30
31
We hope you enjoy this library.
32
"""
1 by mbp at sourcefrog
import from baz patch-364
33
3195.1.1 by Andrew Bennetts
Always include timestamps in the trace file (i.e. remove -Dtimes in favour of having it switched on permanently)
34
import time
35
36
# Keep track of when bzrlib was first imported, so that we can give rough
37
# timestamps relative to program start in the log file kept by bzrlib.trace.
38
_start_time = time.time()
39
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.
40
import sys
41
if getattr(sys, '_bzr_lazy_regex', False):
3224.5.30 by Andrew Bennetts
Comments.
42
    # The 'bzr' executable sets _bzr_lazy_regex.  We install the lazy regex
43
    # hack as soon as possible so that as much of the standard library can
44
    # benefit, including the 'string' module.
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.
45
    del sys._bzr_lazy_regex
46
    import bzrlib.lazy_regex
47
    bzrlib.lazy_regex.install_lazy_compile()
1 by mbp at sourcefrog
import from baz patch-364
48
3224.5.37 by Andrew Bennetts
Reinstate bzrlib.user_encoding because plugins may still use it, and we don't (yet) have a good way to mark it as deprecated.
49
5 by mbp at sourcefrog
.bzrignore support
50
IGNORE_FILENAME = ".bzrignore"
51
1955.2.2 by John Arbash Meinel
Change the name of the test classes (test_lang => test_locale), move the function into osutils.py
52
4634.145.2 by Martin Pool
Update copyright
53
__copyright__ = "Copyright 2005-2010 Canonical Ltd."
1702.1.2 by Martin Pool
Prepare for 0.8 release
54
1704.2.8 by Martin Pool
Bump version to 0.9.0
55
# same format as sys.version_info: "A tuple containing the five components of
1702.1.2 by Martin Pool
Prepare for 0.8 release
56
# the version number: major, minor, micro, releaselevel, and serial. All
57
# values except releaselevel are integers; the release level is 'alpha',
58
# 'beta', 'candidate', or 'final'. The version_info value corresponding to the
1704.2.8 by Martin Pool
Bump version to 0.9.0
59
# Python version 2.0 is (2, 0, 0, 'final', 0)."  Additionally we use a
60
# releaselevel of 'dev' for unreleased under-development code.
61
5263.1.1 by Robert Collins
Release 2.2b3.
62
version_info = (2, 2, 0, 'beta', 3)
1704.2.8 by Martin Pool
Bump version to 0.9.0
63
5036.1.1 by Martin Pool
merge 2.1 back to trunk
64
# API compatibility version
5106.1.1 by Jelmer Vernooij
Bump API version to 2.2.0.
65
api_minimum_version = (2, 2, 0)
2550.2.2 by Robert Collins
Add helpers to get api versions from objects.
66
4574.3.1 by Martin Pool
Give a warning when failing to load _chunks_to_lines_pyx
67
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
68
def _format_version_tuple(version_info):
4098.2.1 by Robert Collins
Allow self documenting hooks.
69
    """Turn a version number 2, 3 or 5-tuple into a short string.
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
70
71
    This format matches <http://docs.python.org/dist/meta-data.html>
72
    and the typical presentation used in Python output.
73
74
    This also checks that the version is reasonable: the sub-release must be
3847.1.1 by Matt Nordhoff
Let _format_version_tuple accept alphas/betas/rcs with a subrelease of 0.
75
    zero for final releases.
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
76
3185.1.13 by Martin Pool
Fix doctest syntax
77
    >>> print _format_version_tuple((1, 0, 0, 'final', 0))
4634.50.2 by John Arbash Meinel
Fix the tests.
78
    1.0.0
3185.1.13 by Martin Pool
Fix doctest syntax
79
    >>> print _format_version_tuple((1, 2, 0, 'dev', 0))
4634.50.2 by John Arbash Meinel
Fix the tests.
80
    1.2.0dev
81
    >>> print bzrlib._format_version_tuple((1, 2, 0, 'dev', 1))
82
    1.2.0dev1
3185.1.13 by Martin Pool
Fix doctest syntax
83
    >>> print _format_version_tuple((1, 1, 1, 'candidate', 2))
84
    1.1.1rc2
4634.13.1 by Vincent Ladeuil
Feedback on the 2.0rc1 release.
85
    >>> print bzrlib._format_version_tuple((2, 1, 0, 'beta', 1))
5160.1.1 by Martin Pool
Show beta versions as 2.2b1
86
    2.1b1
3388.1.1 by Martin Pool
_format_version_tuple can take a 3-tuple
87
    >>> print _format_version_tuple((1, 4, 0))
4634.50.2 by John Arbash Meinel
Fix the tests.
88
    1.4.0
4098.2.1 by Robert Collins
Allow self documenting hooks.
89
    >>> print _format_version_tuple((1, 4))
90
    1.4
4634.50.2 by John Arbash Meinel
Fix the tests.
91
    >>> print bzrlib._format_version_tuple((2, 1, 0, 'final', 1))
92
    Traceback (most recent call last):
93
    ...
94
    ValueError: version_info (2, 1, 0, 'final', 1) not valid
3726.1.1 by Martin Pool
Correct exception expression in _format_version_tuple (Mark Hammond)
95
    >>> print _format_version_tuple((1, 4, 0, 'wibble', 0))
96
    Traceback (most recent call last):
97
    ...
98
    ValueError: version_info (1, 4, 0, 'wibble', 0) not valid
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
99
    """
4634.50.1 by John Arbash Meinel
Change 'bzr --version' to always give the major.minor.micro version
100
    if len(version_info) == 2:
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
101
        main_version = '%d.%d' % version_info[:2]
102
    else:
103
        main_version = '%d.%d.%d' % version_info[:3]
3388.1.1 by Martin Pool
_format_version_tuple can take a 3-tuple
104
    if len(version_info) <= 3:
105
        return main_version
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
106
3849.2.1 by John Arbash Meinel
Cleanup variable names inside a function.
107
    release_type = version_info[3]
108
    sub = version_info[4]
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
109
110
    # check they're consistent
3849.2.1 by John Arbash Meinel
Cleanup variable names inside a function.
111
    if release_type == 'final' and sub == 0:
112
        sub_string = ''
113
    elif release_type == 'dev' and sub == 0:
114
        sub_string = 'dev'
4634.50.2 by John Arbash Meinel
Fix the tests.
115
    elif release_type == 'dev':
116
        sub_string = 'dev' + str(sub)
3849.2.1 by John Arbash Meinel
Cleanup variable names inside a function.
117
    elif release_type in ('alpha', 'beta'):
5160.1.1 by Martin Pool
Show beta versions as 2.2b1
118
        if version_info[2] == 0:
119
            main_version = '%d.%d' % version_info[:2]
3849.2.1 by John Arbash Meinel
Cleanup variable names inside a function.
120
        sub_string = release_type[0] + str(sub)
121
    elif release_type == 'candidate':
122
        sub_string = 'rc' + str(sub)
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
123
    else:
3726.1.1 by Martin Pool
Correct exception expression in _format_version_tuple (Mark Hammond)
124
        raise ValueError("version_info %r not valid" % (version_info,))
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
125
3849.2.1 by John Arbash Meinel
Cleanup variable names inside a function.
126
    return main_version + sub_string
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
127
4122.1.1 by Martin Pool
Merge back 1.13 and bump version to 1.14dev
128
3185.1.9 by Martin Pool
Show short version in a more terse form, like "1.2dev"
129
__version__ = _format_version_tuple(version_info)
3185.1.12 by Martin Pool
Restore bzrlib.version_string variable
130
version_string = __version__
3185.1.5 by Martin Pool
Use a shorter version number, and check that it makes sense.
131
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
132
# bzr has various bits of global state that are slowly being eliminated.
133
# This variable is intended to permit any new state-like things to be attached
134
# to a BzrLibraryState object rather than getting new global variables that
135
# need to be hunted down. Accessing the current BzrLibraryState through this
136
# variable is not encouraged: it is better to pass it around as part of the
137
# context of an operation than to look it up directly, but when that is too
138
# hard, it is better to use this variable than to make a branch new global
139
# variable.
5222.2.10 by Robert Collins
More NEWS about the bzrlib.initialize contract change, and typographical error fixes for __init__.py.
140
# If using this variable by looking it up (because it can't be easily obtained)
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
141
# it is important to store the reference you get, rather than looking it up
142
# repeatedly; that way your code will behave properly in the bzrlib test suite
143
# and from programs that do use multiple library contexts.
144
global_state = None
5017.1.1 by Martin Pool
Add bzrlib.initialize
145
146
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
147
class BzrLibraryState(object):
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
148
    """The state about how bzrlib has been configured.
149
    
150
    :ivar saved_state: The bzrlib.global_state at the time __enter__ was
151
        called.
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
152
    :ivar cleanups: An ObjectWithCleanups which can be used for cleanups that
153
        should occur when the use of bzrlib is completed. This is initialised
154
        in __enter__ and executed in __exit__.
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
155
    """
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
156
157
    def __init__(self, setup_ui=True, stdin=None, stdout=None, stderr=None):
158
        """Create library start for normal use of bzrlib.
159
5222.2.7 by Robert Collins
Document bzrlib.initialize a little better, and explicitly propogate exceptions in the new __exit__ methods.
160
        Most applications that embed bzrlib, including bzr itself, should just
161
        call bzrlib.initialize(), but it is possible to use the state class
162
        directly.
163
164
        More options may be added in future so callers should use named
165
        arguments.
166
5311.1.1 by Robert Collins
Return self from the new context managers so that new objects used with with statements are usable.
167
        BzrLibraryState implements the Python 2.5 Context Manager protocol
168
        PEP343, and can be used with the with statement. Upon __enter__ the
169
        global variables in use by bzr are set, and they are cleared on
170
        __exit__.
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
171
172
        :param setup_ui: If true (default) use a terminal UI; otherwise 
173
            some other ui_factory must be assigned to `bzrlib.ui.ui_factory` by
174
            the caller.
175
        :param stdin, stdout, stderr: If provided, use these for terminal IO;
176
            otherwise use the files in `sys`.
177
        """
178
        self.setup_ui = setup_ui
179
        self.stdin = stdin
180
        self.stdout = stdout
181
        self.stderr = stderr
182
183
    def __enter__(self):
184
        # NB: This function tweaks so much global state it's hard to test it in
185
        # isolation within the same interpreter.  It's not reached on normal
186
        # in-process run_bzr calls.  If it's broken, we expect that
187
        # TestRunBzrSubprocess may fail.
188
        if version_info[3] == 'final':
189
            from bzrlib.symbol_versioning import suppress_deprecation_warnings
190
            suppress_deprecation_warnings(override=True)
191
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
192
        import bzrlib.cleanup
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
193
        import bzrlib.trace
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
194
        self.cleanups = bzrlib.cleanup.ObjectWithCleanups()
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
195
        bzrlib.trace.enable_default_logging()
196
197
        if self.setup_ui:
198
            import bzrlib.ui
199
            stdin = self.stdin or sys.stdin
200
            stdout = self.stdout or sys.stdout
201
            stderr = self.stderr or sys.stderr
202
            bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
203
                stdin, stdout, stderr)
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
204
        global global_state
205
        self.saved_state = global_state
206
        global_state = self
5311.1.1 by Robert Collins
Return self from the new context managers so that new objects used with with statements are usable.
207
        return self # This is bound to the 'as' clause in a with statement.
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
208
209
    def __exit__(self, exc_type, exc_val, exc_tb):
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
210
        self.cleanups.cleanup_now()
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
211
        import bzrlib.ui
212
        bzrlib.trace._flush_stdout_stderr()
213
        bzrlib.trace._flush_trace()
214
        import bzrlib.osutils
215
        bzrlib.osutils.report_extension_load_failures()
216
        bzrlib.ui.ui_factory.__exit__(None, None, None)
217
        bzrlib.ui.ui_factory = None
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
218
        global global_state
219
        global_state = self.saved_state
5222.2.7 by Robert Collins
Document bzrlib.initialize a little better, and explicitly propogate exceptions in the new __exit__ methods.
220
        return False # propogate exceptions.
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
221
222
223
def initialize(setup_ui=True, stdin=None, stdout=None, stderr=None):
5017.1.1 by Martin Pool
Add bzrlib.initialize
224
    """Set up everything needed for normal use of bzrlib.
225
226
    Most applications that embed bzrlib, including bzr itself, should call
227
    this function to initialize various subsystems.  
228
229
    More options may be added in future so callers should use named arguments.
230
231
    :param setup_ui: If true (default) use a terminal UI; otherwise 
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
232
        some other ui_factory must be assigned to `bzrlib.ui.ui_factory` by
233
        the caller.
5017.1.1 by Martin Pool
Add bzrlib.initialize
234
    :param stdin, stdout, stderr: If provided, use these for terminal IO;
235
        otherwise use the files in `sys`.
5222.2.7 by Robert Collins
Document bzrlib.initialize a little better, and explicitly propogate exceptions in the new __exit__ methods.
236
    :return: A context manager for the use of bzrlib. The __enter__ method of
5222.2.10 by Robert Collins
More NEWS about the bzrlib.initialize contract change, and typographical error fixes for __init__.py.
237
        this context needs to be called before it takes effect, and the __exit__
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
238
        should be called by the caller before exiting their process or
239
        otherwise stopping use of bzrlib. Advanced callers can use
240
        BzrLibraryState directly.
5017.1.1 by Martin Pool
Add bzrlib.initialize
241
    """
5222.2.9 by Robert Collins
Write up some doc about bzrlib.initialize.
242
    return BzrLibraryState(setup_ui=setup_ui, stdin=stdin,
5222.2.4 by Robert Collins
Rather than adding another global thing, use a context manager to represent all the global state.
243
        stdout=stdout, stderr=stderr)
5222.2.8 by Robert Collins
Store the library state as a global variable so that code with no other way of finding the BzrLibraryState can access it.
244
245
246
def test_suite():
247
    import tests
248
    return tests.test_suite()