~bzr/ubuntu/maverick/bzr/bzr-ppa

« back to all changes in this revision

Viewing changes to bzrlib/debug.py

  • Committer: Max Bowsher
  • Date: 2012-03-11 00:18:38 UTC
  • mfrom: (144.1.23 natty)
  • Revision ID: _@maxb.eu-20120311001838-orc0v5vksuqp0431
Tags: 2.5.0-2~bazaar1~maverick1
MergeĀ 2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Set of flags that enable different debug behaviour.
19
18
 
20
19
These are set with eg ``-Dlock`` on the bzr command line or in
24
23
for a list of the available options.
25
24
"""
26
25
 
 
26
from __future__ import absolute_import
27
27
 
28
28
debug_flags = set()
29
29
 
31
31
def set_debug_flags_from_config():
32
32
    """Turn on debug flags based on the global configuration"""
33
33
 
34
 
    from bzrlib.config import GlobalConfig
35
 
 
36
 
    c = GlobalConfig()
37
 
    value = c.get_user_option("debug_flags")
38
 
    if value is not None:
39
 
        # configobject gives us either a string if there's just one or a list
40
 
        # if there's multiple
41
 
        if isinstance(value, basestring):
42
 
            value = [value]
43
 
        for w in value:
44
 
            w = w.strip()
45
 
            debug_flags.add(w)
 
34
    from bzrlib import config
 
35
 
 
36
    c = config.GlobalStack()
 
37
    for f in c.get('debug_flags'):
 
38
        debug_flags.add(f)
 
39
 
 
40
 
 
41
def set_trace():
 
42
    """Pdb using original stdin and stdout.
 
43
 
 
44
    When debugging blackbox tests, sys.stdin and sys.stdout are captured for
 
45
    test purposes and cannot be used for interactive debugging. This class uses
 
46
    the origianl stdin/stdout to allow such use.
 
47
 
 
48
    Instead of doing:
 
49
 
 
50
       import pdb; pdb.set_trace()
 
51
 
 
52
    you can do:
 
53
 
 
54
       from bzrlib import debug; debug.set_trace()
 
55
    """
 
56
    import pdb
 
57
    import sys
 
58
    pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__
 
59
            ).set_trace(sys._getframe().f_back)