/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/__init__.py

  • Committer: Robert Collins
  • Date: 2010-06-21 03:55:08 UTC
  • mto: This revision was merged to the branch mainline in revision 5310.
  • Revision ID: robertc@robertcollins.net-20100621035508-wrcgnqv227ftxhs8
Write up some doc about bzrlib.initialize.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""bzr library"""
 
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
"""
18
33
 
19
34
import time
20
35
 
134
149
    
135
150
    :ivar saved_state: The bzrlib.global_state at the time __enter__ was
136
151
        called.
 
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__.
137
155
    """
138
156
 
139
157
    def __init__(self, setup_ui=True, stdin=None, stdout=None, stderr=None):
147
165
        arguments.
148
166
 
149
167
        BzrLibraryState implements the Python 2.5 Context Manager protocol, and
150
 
        can be used with the with statement. Upon __entry__ the global
 
168
        can be used with the with statement. Upon __enter__ the global
151
169
        variables in use by bzr are set, and they are cleared on __exit__.
152
170
 
153
171
        :param setup_ui: If true (default) use a terminal UI; otherwise 
170
188
            from bzrlib.symbol_versioning import suppress_deprecation_warnings
171
189
            suppress_deprecation_warnings(override=True)
172
190
 
 
191
        import bzrlib.cleanup
173
192
        import bzrlib.trace
 
193
        self.cleanups = bzrlib.cleanup.ObjectWithCleanups()
174
194
        bzrlib.trace.enable_default_logging()
175
195
 
176
196
        if self.setup_ui:
185
205
        global_state = self
186
206
 
187
207
    def __exit__(self, exc_type, exc_val, exc_tb):
 
208
        self.cleanups.cleanup_now()
188
209
        import bzrlib.ui
189
210
        bzrlib.trace._flush_stdout_stderr()
190
211
        bzrlib.trace._flush_trace()
211
232
    :param stdin, stdout, stderr: If provided, use these for terminal IO;
212
233
        otherwise use the files in `sys`.
213
234
    :return: A context manager for the use of bzrlib. The __enter__ method of
214
 
        this context has already been called, the __exit__ should be called
215
 
        by the caller before exiting their process or otherwise stopping use
216
 
        of bzrlib. Advanced callers, or callers wanting to use the 'with'
217
 
        statement in Python 2.5 and above, should use BzrLibraryState directly.
 
235
        this context needs to be alled before it takes effect, and the __exit__
 
236
        should be called by the caller before exiting their process or
 
237
        otherwise stopping use of bzrlib. Advanced callers can use
 
238
        BzrLibraryState directly.
218
239
    """
219
 
    # TODO: mention this in a guide to embedding bzrlib
220
 
    library_state = BzrLibraryState(setup_ui=setup_ui, stdin=stdin,
 
240
    return BzrLibraryState(setup_ui=setup_ui, stdin=stdin,
221
241
        stdout=stdout, stderr=stderr)
222
 
    library_state.__enter__()
223
 
    return library_state
224
242
 
225
243
 
226
244
def test_suite():