~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

(jelmer) Fix bug #1010339,
 use encoding_type='exact' for bzr testament (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""The core state needed to make use of bzr is managed here."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
__all__ = [
22
20
    'BzrLibraryState',
23
21
    ]
24
22
 
 
23
import sys
25
24
 
26
25
import bzrlib
27
 
from bzrlib.lazy_import import lazy_import
28
 
lazy_import(globals(), """
29
 
from bzrlib import (
30
 
    cleanup,
31
 
    config,
32
 
    osutils,
33
 
    symbol_versioning,
34
 
    trace,
35
 
    ui,
36
 
    )
37
 
""")
38
26
 
39
27
 
40
28
class BzrLibraryState(object):
73
61
        """
74
62
        self._ui = ui
75
63
        self._trace = trace
76
 
        # There is no overrides by default, they are set later when the command
77
 
        # arguments are parsed.
78
 
        self.cmdline_overrides = config.CommandLineStore()
79
64
        self.started = False
80
65
 
81
66
    def __enter__(self):
84
69
        return self # This is bound to the 'as' clause in a with statement.
85
70
 
86
71
    def _start(self):
87
 
        """Do all initialization."""
 
72
        """Do all initialization.
 
73
        """        
88
74
        # NB: This function tweaks so much global state it's hard to test it in
89
75
        # isolation within the same interpreter.  It's not reached on normal
90
76
        # in-process run_bzr calls.  If it's broken, we expect that
91
77
        # TestRunBzrSubprocess may fail.
92
 
        self.cleanups = cleanup.ObjectWithCleanups()
93
 
 
 
78
        import bzrlib
94
79
        if bzrlib.version_info[3] == 'final':
95
 
            self.cleanups.add_cleanup(
96
 
                symbol_versioning.suppress_deprecation_warnings(override=True))
 
80
            from bzrlib.symbol_versioning import suppress_deprecation_warnings
 
81
            warning_cleanup = suppress_deprecation_warnings(override=True)
 
82
        else:
 
83
            warning_cleanup = None
97
84
 
 
85
        import bzrlib.cleanup
 
86
        self.cleanups = bzrlib.cleanup.ObjectWithCleanups()
 
87
        if warning_cleanup:
 
88
            self.cleanups.add_cleanup(warning_cleanup)
98
89
        self._trace.__enter__()
99
90
 
100
91
        self._orig_ui = bzrlib.ui.ui_factory
107
98
 
108
99
    def __exit__(self, exc_type, exc_val, exc_tb):
109
100
        self.cleanups.cleanup_now()
110
 
        trace._flush_stdout_stderr()
111
 
        trace._flush_trace()
112
 
        osutils.report_extension_load_failures()
 
101
        import bzrlib.ui
 
102
        bzrlib.trace._flush_stdout_stderr()
 
103
        bzrlib.trace._flush_trace()
 
104
        import bzrlib.osutils
 
105
        bzrlib.osutils.report_extension_load_failures()
113
106
        self._ui.__exit__(None, None, None)
114
107
        self._trace.__exit__(None, None, None)
115
 
        ui.ui_factory = self._orig_ui
116
 
        bzrlib.global_state = self.saved_state
 
108
        bzrlib.ui.ui_factory = self._orig_ui
 
109
        global global_state
 
110
        global_state = self.saved_state
117
111
        return False # propogate exceptions.