~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    This is the core state needed to make use of bzr. The current instance is
32
32
    currently always exposed as bzrlib.global_state, but we desired to move
33
33
    to a point where no global state is needed at all.
34
 
 
 
34
    
35
35
    :ivar saved_state: The bzrlib.global_state at the time __enter__ was
36
36
        called.
37
37
    :ivar cleanups: An ObjectWithCleanups which can be used for cleanups that
61
61
        """
62
62
        self._ui = ui
63
63
        self._trace = trace
64
 
        self.started = False
65
64
 
66
65
    def __enter__(self):
67
 
        if not self.started:
68
 
            self._start()
69
 
        return self # This is bound to the 'as' clause in a with statement.
70
 
 
71
 
    def _start(self):
72
 
        """Do all initialization.
73
 
        """        
74
66
        # NB: This function tweaks so much global state it's hard to test it in
75
67
        # isolation within the same interpreter.  It's not reached on normal
76
68
        # in-process run_bzr calls.  If it's broken, we expect that
94
86
 
95
87
        self.saved_state = bzrlib.global_state
96
88
        bzrlib.global_state = self
97
 
        self.started = True
 
89
        return self # This is bound to the 'as' clause in a with statement.
98
90
 
99
91
    def __exit__(self, exc_type, exc_val, exc_tb):
100
92
        self.cleanups.cleanup_now()