~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-29 15:50:58 UTC
  • mfrom: (6177 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6178.
  • Revision ID: v.ladeuil+lp@free.fr-20110929155058-zgbecmx1huzktegm
Merge trunk and resolve conflicts

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
26
from bzrlib.lazy_import import lazy_import
28
27
lazy_import(globals(), """
29
 
from bzrlib import (
30
 
    cleanup,
31
 
    config,
32
 
    osutils,
33
 
    symbol_versioning,
34
 
    trace,
35
 
    ui,
36
 
    )
 
28
from bzrlib import config
37
29
""")
38
30
 
39
31
 
75
67
        self._trace = trace
76
68
        # There is no overrides by default, they are set later when the command
77
69
        # arguments are parsed.
78
 
        self.cmdline_overrides = config.CommandLineStore()
 
70
        self.cmdline_overrides = config.CommandLineSection()
79
71
        self.started = False
80
72
 
81
73
    def __enter__(self):
89
81
        # isolation within the same interpreter.  It's not reached on normal
90
82
        # in-process run_bzr calls.  If it's broken, we expect that
91
83
        # TestRunBzrSubprocess may fail.
92
 
        self.cleanups = cleanup.ObjectWithCleanups()
93
 
 
 
84
        import bzrlib
94
85
        if bzrlib.version_info[3] == 'final':
95
 
            self.cleanups.add_cleanup(
96
 
                symbol_versioning.suppress_deprecation_warnings(override=True))
 
86
            from bzrlib.symbol_versioning import suppress_deprecation_warnings
 
87
            warning_cleanup = suppress_deprecation_warnings(override=True)
 
88
        else:
 
89
            warning_cleanup = None
97
90
 
 
91
        import bzrlib.cleanup
 
92
        self.cleanups = bzrlib.cleanup.ObjectWithCleanups()
 
93
        if warning_cleanup:
 
94
            self.cleanups.add_cleanup(warning_cleanup)
98
95
        self._trace.__enter__()
99
96
 
100
97
        self._orig_ui = bzrlib.ui.ui_factory
107
104
 
108
105
    def __exit__(self, exc_type, exc_val, exc_tb):
109
106
        self.cleanups.cleanup_now()
110
 
        trace._flush_stdout_stderr()
111
 
        trace._flush_trace()
112
 
        osutils.report_extension_load_failures()
 
107
        import bzrlib.ui
 
108
        bzrlib.trace._flush_stdout_stderr()
 
109
        bzrlib.trace._flush_trace()
 
110
        import bzrlib.osutils
 
111
        bzrlib.osutils.report_extension_load_failures()
113
112
        self._ui.__exit__(None, None, None)
114
113
        self._trace.__exit__(None, None, None)
115
 
        ui.ui_factory = self._orig_ui
116
 
        bzrlib.global_state = self.saved_state
 
114
        bzrlib.ui.ui_factory = self._orig_ui
 
115
        global global_state
 
116
        global_state = self.saved_state
117
117
        return False # propogate exceptions.