~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/debug.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

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
 
17
18
"""Set of flags that enable different debug behaviour.
18
19
 
19
20
These are set with eg ``-Dlock`` on the bzr command line or in
23
24
for a list of the available options.
24
25
"""
25
26
 
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 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)
 
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)