~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:37:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105103758-wzftnmsip5iv9n2g
Revert addition of get_message_encoding function

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
""")
26
37
 
27
38
 
28
39
class BzrLibraryState(object):
61
72
        """
62
73
        self._ui = ui
63
74
        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()
64
78
        self.started = False
65
79
 
66
80
    def __enter__(self):
69
83
        return self # This is bound to the 'as' clause in a with statement.
70
84
 
71
85
    def _start(self):
72
 
        """Do all initialization.
73
 
        """        
 
86
        """Do all initialization."""
74
87
        # NB: This function tweaks so much global state it's hard to test it in
75
88
        # isolation within the same interpreter.  It's not reached on normal
76
89
        # in-process run_bzr calls.  If it's broken, we expect that
77
90
        # TestRunBzrSubprocess may fail.
78
 
        import bzrlib
 
91
        self.cleanups = cleanup.ObjectWithCleanups()
 
92
 
79
93
        if bzrlib.version_info[3] == 'final':
80
 
            from bzrlib.symbol_versioning import suppress_deprecation_warnings
81
 
            warning_cleanup = suppress_deprecation_warnings(override=True)
82
 
        else:
83
 
            warning_cleanup = None
 
94
            self.cleanups.add_cleanup(
 
95
                symbol_versioning.suppress_deprecation_warnings(override=True))
84
96
 
85
 
        import bzrlib.cleanup
86
 
        self.cleanups = bzrlib.cleanup.ObjectWithCleanups()
87
 
        if warning_cleanup:
88
 
            self.cleanups.add_cleanup(warning_cleanup)
89
97
        self._trace.__enter__()
90
98
 
91
99
        self._orig_ui = bzrlib.ui.ui_factory
98
106
 
99
107
    def __exit__(self, exc_type, exc_val, exc_tb):
100
108
        self.cleanups.cleanup_now()
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()
 
109
        trace._flush_stdout_stderr()
 
110
        trace._flush_trace()
 
111
        osutils.report_extension_load_failures()
106
112
        self._ui.__exit__(None, None, None)
107
113
        self._trace.__exit__(None, None, None)
108
 
        bzrlib.ui.ui_factory = self._orig_ui
109
 
        global global_state
110
 
        global_state = self.saved_state
 
114
        ui.ui_factory = self._orig_ui
 
115
        bzrlib.global_state = self.saved_state
111
116
        return False # propogate exceptions.