~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/breakin.py

  • Committer: Robert Collins
  • Date: 2007-07-15 15:40:37 UTC
  • mto: (2592.3.33 repository)
  • mto: This revision was merged to the branch mainline in revision 2624.
  • Revision ID: robertc@robertcollins.net-20070715154037-3ar8g89decddc9su
Make GraphIndex accept nodes as key, value, references, so that the method
signature is closer to what a simple key->value index delivers. Also
change the behaviour when the reference list count is zero to accept
key, value as nodes, and emit key, value to make it identical in that case
to a simple key->value index. This may not be a good idea, but for now it
seems ok.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
18
import signal
19
19
 
20
 
 
21
 
_breakin_signal_number = None
22
 
_breakin_signal_name = None
23
 
 
24
 
 
25
20
def _debug(signal_number, interrupted_frame):
26
21
    import pdb
27
22
    import sys
28
 
    sys.stderr.write("** %s received, entering debugger\n"
 
23
    sys.stderr.write("** SIGQUIT received, entering debugger\n"
29
24
            "** Type 'c' to continue or 'q' to stop the process\n"
30
 
            "** Or %s again to quit (and possibly dump core)\n"
31
 
            % (_breakin_signal_name, _breakin_signal_name))
32
 
    # It seems that on Windows, when sys.stderr is to a PIPE, then we need to
33
 
    # flush. Not sure why it is buffered, but that seems to be the case.
34
 
    sys.stderr.flush()
 
25
            "** Or SIGQUIT again to quit (and possibly dump core)\n"
 
26
            )
35
27
    # restore default meaning so that you can kill the process by hitting it
36
28
    # twice
37
 
    signal.signal(_breakin_signal_number, signal.SIG_DFL)
 
29
    signal.signal(signal.SIGQUIT, signal.SIG_DFL)
38
30
    try:
39
31
        pdb.set_trace()
40
32
    finally:
41
 
        signal.signal(_breakin_signal_number, _debug)
 
33
        signal.signal(signal.SIGQUIT, _debug)
42
34
 
43
35
 
44
36
def hook_sigquit():
45
 
    # We import this late because breakin.py is loaded as part of the main
46
 
    # 'bzr' script, so we want it to load as little as possible until things
47
 
    # are up and running
48
 
    from bzrlib import symbol_versioning, trace
49
 
    trace.mutter_callsite(2, 'Deprecated function called')
50
 
    symbol_versioning.warn(symbol_versioning.deprecation_string(
51
 
        hook_sigquit, symbol_versioning.deprecated_in((1, 18, 0))),
52
 
        DeprecationWarning, stacklevel=2)
53
 
 
54
 
    return hook_debugger_to_signal()
55
 
 
56
 
 
57
 
def determine_signal():
58
 
    global _breakin_signal_number
59
 
    global _breakin_signal_name
60
 
    if _breakin_signal_number is not None:
61
 
        return _breakin_signal_number
62
 
    # Note: As near as I can tell, Windows is the only one to define SIGBREAK,
63
 
    #       and other platforms defined SIGQUIT. There doesn't seem to be a
64
 
    #       platform that defines both.
65
 
    #       -- jam 2009-07-30
66
 
    sigquit = getattr(signal, 'SIGQUIT', None)
67
 
    sigbreak = getattr(signal, 'SIGBREAK', None)
68
 
    if sigquit is not None:
69
 
        _breakin_signal_number = sigquit
70
 
        _breakin_signal_name = 'SIGQUIT'
71
 
    elif sigbreak is not None:
72
 
        _breakin_signal_number = sigbreak
73
 
        _breakin_signal_name = 'SIGBREAK'
74
 
 
75
 
    return _breakin_signal_number
76
 
 
77
 
 
78
 
def hook_debugger_to_signal():
79
 
    """Add a signal handler so we drop into the debugger.
80
 
 
81
 
    On Linux and Mac, this is hooked into SIGQUIT (C-\\) on Windows, this is
82
 
    hooked into SIGBREAK (C-Pause).
83
 
    """
84
 
 
85
 
    # when sigquit (C-\) or sigbreak (C-Pause) is received go into pdb
86
 
    if os.environ.get('BZR_SIGQUIT_PDB', '1') == '0':
87
 
        # User explicitly requested we don't support this
88
 
        return
89
 
    sig = determine_signal()
90
 
    if sig is None:
91
 
        return
92
 
    # print 'hooking into %s' % (_breakin_signal_name,)
93
 
    signal.signal(sig, _debug)
 
37
    # when sigquit (C-\) is received go into pdb
 
38
    if (os.environ.get('BZR_SIGQUIT_PDB', '1') == '0'
 
39
        or getattr(signal, 'SIGQUIT', None) is None):
 
40
        return
 
41
    signal.signal(signal.SIGQUIT, _debug)