/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/library_state.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    ]
24
24
 
25
25
 
26
 
import bzrlib
27
 
from bzrlib.lazy_import import lazy_import
 
26
import breezy
 
27
from .lazy_import import lazy_import
28
28
lazy_import(globals(), """
29
 
from bzrlib import (
 
29
from breezy import (
30
30
    cleanup,
31
31
    config,
32
32
    osutils,
38
38
 
39
39
 
40
40
class BzrLibraryState(object):
41
 
    """The state about how bzrlib has been configured.
 
41
    """The state about how breezy has been configured.
42
42
 
43
43
    This is the core state needed to make use of bzr. The current instance is
44
 
    currently always exposed as bzrlib.global_state, but we desired to move
 
44
    currently always exposed as breezy.global_state, but we desired to move
45
45
    to a point where no global state is needed at all.
46
46
 
47
 
    :ivar saved_state: The bzrlib.global_state at the time __enter__ was
 
47
    :ivar saved_state: The breezy.global_state at the time __enter__ was
48
48
        called.
49
49
    :ivar cleanups: An ObjectWithCleanups which can be used for cleanups that
50
 
        should occur when the use of bzrlib is completed. This is initialised
 
50
        should occur when the use of breezy is completed. This is initialised
51
51
        in __enter__ and executed in __exit__.
52
52
    """
53
53
 
54
54
    def __init__(self, ui, trace):
55
 
        """Create library start for normal use of bzrlib.
 
55
        """Create library start for normal use of breezy.
56
56
 
57
 
        Most applications that embed bzrlib, including bzr itself, should just
58
 
        call bzrlib.initialize(), but it is possible to use the state class
 
57
        Most applications that embed breezy, including bzr itself, should just
 
58
        call breezy.initialize(), but it is possible to use the state class
59
59
        directly. The initialize() function provides sensible defaults for a
60
60
        CLI program, such as a text UI factory.
61
61
 
67
67
        global variables in use by bzr are set, and they are cleared on
68
68
        __exit__.
69
69
 
70
 
        :param ui: A bzrlib.ui.ui_factory to use.
71
 
        :param trace: A bzrlib.trace.Config context manager to use, perhaps
72
 
            bzrlib.trace.DefaultConfig.
 
70
        :param ui: A breezy.ui.ui_factory to use.
 
71
        :param trace: A breezy.trace.Config context manager to use, perhaps
 
72
            breezy.trace.DefaultConfig.
73
73
        """
74
74
        self._ui = ui
75
75
        self._trace = trace
93
93
        # TestRunBzrSubprocess may fail.
94
94
        self.cleanups = cleanup.ObjectWithCleanups()
95
95
 
96
 
        if bzrlib.version_info[3] == 'final':
 
96
        if breezy.version_info[3] == 'final':
97
97
            self.cleanups.add_cleanup(
98
98
                symbol_versioning.suppress_deprecation_warnings(override=True))
99
99
 
100
100
        self._trace.__enter__()
101
101
 
102
 
        self._orig_ui = bzrlib.ui.ui_factory
103
 
        bzrlib.ui.ui_factory = self._ui
 
102
        self._orig_ui = breezy.ui.ui_factory
 
103
        breezy.ui.ui_factory = self._ui
104
104
        self._ui.__enter__()
105
105
 
106
 
        self.saved_state = bzrlib.global_state
107
 
        bzrlib.global_state = self
 
106
        self.saved_state = breezy.global_state
 
107
        breezy.global_state = self
108
108
        self.started = True
109
109
 
110
110
    def __exit__(self, exc_type, exc_val, exc_tb):
111
111
        if exc_type is None:
112
112
            # Save config changes
113
 
            for k, store in self.config_stores.iteritems():
 
113
            for k, store in self.config_stores.items():
114
114
                store.save_changes()
115
115
        self.cleanups.cleanup_now()
116
116
        trace._flush_stdout_stderr()
119
119
        self._ui.__exit__(None, None, None)
120
120
        self._trace.__exit__(None, None, None)
121
121
        ui.ui_factory = self._orig_ui
122
 
        bzrlib.global_state = self.saved_state
 
122
        breezy.global_state = self.saved_state
123
123
        return False # propogate exceptions.