PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/util/debugthg.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 50 lines | 43 code | 1 blank | 6 comment | 0 complexity | a4cf7066d1994ad07b0a8ee736a62038 MD5 | raw file
 1# debugthg.py - debugging library for TortoiseHg shell extensions
 2#
 3# Copyright 2008 Steve Borho <steve@borho.org>
 4#
 5# This software may be used and distributed according to the terms of the
 6# GNU General Public License version 2, incorporated herein by reference.
 7
 8debugging = ''
 9try:
10    import _winreg
11    try:
12        hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
13                           r"Software\TortoiseHg", 0,
14                           _winreg.KEY_ALL_ACCESS)
15        val = _winreg.QueryValueEx(hkey, 'OverlayDebug')[0]
16        if val in ('1', 'True'):
17            debugging += 'O'
18        val = _winreg.QueryValueEx(hkey, 'ContextMenuDebug')[0]
19        if val in ('1', 'True'):
20            debugging += 'M'
21        if debugging:
22            import win32traceutil
23    except EnvironmentError:
24        pass
25except ImportError:
26    import os
27    debugging = os.environ.get("DEBUG_THG", "")
28    if debugging.lower() in ("1", "true"):
29        debugging = True
30
31def debugf_No(str, args=None, level=''):
32    pass
33
34if debugging:
35    def debug(level=''):
36        return debugging == True or level in debugging
37    def debugf(str, args=None, level=''):
38        if not debug(level):
39            return
40        if args:
41            print str % args
42        elif debug('e') and isinstance(str, BaseException):
43            import traceback
44            traceback.print_exc()
45        else:
46            print str
47else:
48    def debug(level=''):
49        return False
50    debugf = debugf_No