~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

  • Committer: Patch Queue Manager
  • Date: 2016-01-31 13:36:59 UTC
  • mfrom: (6613.1.5 1538480-match-hostname)
  • Revision ID: pqm@pqm.ubuntu.com-20160131133659-ouy92ee2wlv9xz8m
(vila) Use ssl.match_hostname instead of our own. (Vincent Ladeuil)

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