~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/library_state.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

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
64
65
 
65
66
    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
        """        
66
74
        # NB: This function tweaks so much global state it's hard to test it in
67
75
        # isolation within the same interpreter.  It's not reached on normal
68
76
        # in-process run_bzr calls.  If it's broken, we expect that
86
94
 
87
95
        self.saved_state = bzrlib.global_state
88
96
        bzrlib.global_state = self
89
 
        return self # This is bound to the 'as' clause in a with statement.
 
97
        self.started = True
90
98
 
91
99
    def __exit__(self, exc_type, exc_val, exc_tb):
92
100
        self.cleanups.cleanup_now()