/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
5320.2.2 by Robert Collins
Move BzrLibraryState to its own module and prepare to start testing it.
134
# to a library_state.BzrLibraryState object rather than getting new global
135
# variables that need to be hunted down. Accessing the current BzrLibraryState
136
# through this variable is not encouraged: it is better to pass it around as
137
# part of the context of an operation than to look it up directly, but when
138
# that is too hard, it is better to use this variable than to make a branch new
139
# global 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
def initialize(setup_ui=True, stdin=None, stdout=None, stderr=None):
5017.1.1 by Martin Pool
Add bzrlib.initialize
148
    """Set up everything needed for normal use of bzrlib.
149
150
    Most applications that embed bzrlib, including bzr itself, should call
151
    this function to initialize various subsystems.  
152
153
    More options may be added in future so callers should use named arguments.
154
155
    :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.
156
        some other ui_factory must be assigned to `bzrlib.ui.ui_factory` by
157
        the caller.
5017.1.1 by Martin Pool
Add bzrlib.initialize
158
    :param stdin, stdout, stderr: If provided, use these for terminal IO;
159
        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.
160
    :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.
161
        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.
162
        should be called by the caller before exiting their process or
163
        otherwise stopping use of bzrlib. Advanced callers can use
164
        BzrLibraryState directly.
5017.1.1 by Martin Pool
Add bzrlib.initialize
165
    """
5320.2.2 by Robert Collins
Move BzrLibraryState to its own module and prepare to start testing it.
166
    import bzrlib.library_state
5320.2.3 by Robert Collins
Restore the original ui_factory when existing BzrLibraryState.
167
    if setup_ui:
168
        import bzrlib.ui
169
        stdin = stdin or sys.stdin
170
        stdout = stdout or sys.stdout
171
        stderr = stderr or sys.stderr
172
        ui_factory = bzrlib.ui.make_ui_for_terminal(stdin, stdout, stderr)
173
    else:
174
        ui_factory = None
5320.2.5 by Robert Collins
Make bzrlib startup use a trace context manager.
175
    tracer = bzrlib.trace.DefaultConfig()
176
    return bzrlib.library_state.BzrLibraryState(ui=ui_factory, trace=tracer)
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.
177
178
179
def test_suite():
180
    import tests
181
    return tests.test_suite()