~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

(jelmer) Deprecate Repository.iter_reverse_revision_history(). (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

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